Advertisement
HR_Shaft

Replace Frag Grenades with Plasma for SAPP

Jul 15th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. -- Replace Frag Grenades with Plasma 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 frag grenade equipment and projectile with the plasma 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 Plasma Grenades with Frags, see other script. http://pastebin.com/tkWh9bCZ
  11.  
  12. -- set grenade counts to what you want them. I suggest leaving 'frag'_count to 0 (zero)
  13. -- Note: frag count will show, but only plasma will be thrown/picked up.
  14.  
  15. frag_count = 0
  16. plasma_count = 2
  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 frag grenade eqip/equipment with plasma grenades:
  54.         if MapID == get_tag_info("eqip", "weapons\\frag grenade\\frag grenade") then
  55.             return true, get_tag_info("eqip", "weapons\\plasma grenade\\plasma grenade")
  56.         end
  57.  
  58.         -- replace frag grenade proj/projectiles with plasma projectiles (doesn't happen until you throw):
  59.         if MapID == get_tag_info("proj", "weapons\\frag grenade\\frag grenade") then
  60.             return true, get_tag_info("proj", "weapons\\plasma grenade\\plasma 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