Advertisement
HR_Shaft

Replace Plasma Grenades with Frags for SAPP

Jul 15th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. -- Replace Plasma Grenades with Frags by H® Shaft for SAPP
  2.  
  3. -- This script will:
  4. -- Set Frag and Plasma Grenade counts to what you specify
  5. -- Replace both the plasma grenade equipment and projectile with the frag grenade equipment and projectiles
  6. -- will only work with UNPROTECTED maps with stock frags and plasma grenades
  7.  
  8. -- requested by @Captain@
  9.  
  10. -- If you would like to do the opposite; replace Frag Grenades with Plasma, see other script. http://pastebin.com/8amXdW02
  11.  
  12. -- set grenade counts to what you want them. I suggest leaving 'plasma'_count to 0 (zero)
  13. -- Note: plasma count will show, but only frags will be thrown/picked up.  If you pickup frags, only frag count will increase:
  14.  
  15. frag_count = 2
  16. plasma_count = 0
  17.  
  18. -- sapp api version
  19. api_version = "1.8.0.0"
  20. -- do not edit below unless you know what you are doing --
  21. game_started = false
  22.  
  23. function OnScriptLoad()
  24.     register_callback(cb['EVENT_GAME_START'],"OnNewGame")
  25.     register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
  26.     register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  27.     register_callback(cb['EVENT_OBJECT_SPAWN'],"OnObjectSpawn")
  28. end
  29.  
  30. function OnScriptUnload() end
  31.  
  32. function OnPlayerSpawn(PlayerIndex)
  33.     if (game_started == true) then
  34.                
  35.         -- set grenade counts as they are set above
  36.         if (player_alive(PlayerIndex) == true) then
  37.             local player_object = get_dynamic_player(PlayerIndex)
  38.             safe_write(true)
  39.             write_word(player_object + 0x31E, frag_count)
  40.             write_word(player_object + 0x31F, plasma_count)
  41.             safe_write(false)
  42.         end
  43.        
  44.     end
  45. end
  46.  
  47. function OnObjectSpawn(PlayerIndex, MapID, ParentID, ObjectID)
  48.     if (game_started == true) then
  49.         -- Note: you cannot replace one object type for another, they must be the same type.
  50.         -- obj_types: vehi, weap, bipd, eqip, proj
  51.         -- obj_names: there are many, example: "weapons\\plasma grenade\\plasma grenade"
  52.        
  53.         -- replace plasma grenade eqip/equipment with frag grenades:
  54.         if MapID == get_tag_info("eqip", "weapons\\plasma grenade\\plasma grenade") then
  55.             return true, get_tag_info("eqip", "weapons\\frag grenade\\frag grenade")
  56.         end
  57.  
  58.         -- replace plasma grenade proj/projectiles with frag projectiles (doesn't happen until you throw):
  59.         if MapID == get_tag_info("proj", "weapons\\plasma grenade\\plasma grenade") then
  60.             return true, get_tag_info("proj", "weapons\\frag grenade\\frag grenade")
  61.         end
  62.        
  63.         -- end --
  64.         return true
  65.     else
  66.         return false
  67.     end
  68. end
  69.  
  70. -- note: calls to this function must provide both arguments of obj_type & obj_name separated by comma as shown above.
  71. function get_tag_info(obj_type, obj_name)
  72.     local tag_id = lookup_tag(obj_type, obj_name)
  73.     return tag_id ~= 0 and read_dword(tag_id + 0xC) or nil
  74. end
  75.    
  76. function OnNewGame()
  77.     game_started = true
  78. end
  79.    
  80. function OnGameEnd()
  81.     game_started = false
  82. end
  83.  
  84. -- Created by H® Shaft
  85. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement