Advertisement
HR_Shaft

Setup Player Grenades 1.2 for SAPP

Nov 1st, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.64 KB | None | 0 0
  1. -- Setup Player Grenades 1.2 for SAPP
  2. -- by H® Shaft
  3.  
  4. -- Allows server admins to set number of frag and plasma grenades per map, assigned when player spawns.
  5. -- Allows server admins to set maximum number of grenades a player may hold per map.
  6. -- See line 78 and below - 'load tables' to modify the grenade counts/maximums you prefer per map, and to add maps.
  7. -- WILL work with stock PC/CE maps, and CE maps with stock grenade sets (names)
  8.  
  9. -- sapp api version
  10. api_version = "1.8.0.0"
  11.  
  12. function OnScriptLoad()
  13.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  14.     register_callback(cb["EVENT_WEAPON_PICKUP"],"OnWeaponPickup")
  15.     register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  16.     map_name = get_var(0,"$map")
  17.     Load_Tables()
  18. end
  19.  
  20. function OnScriptUnload()
  21.     frag_count = {}
  22.     plasma_count = {}
  23. end
  24.  
  25. function OnNewGame()
  26.     map_name = get_var(0,"$map")
  27.     Load_Tables()
  28. end
  29.  
  30. function GameEnd()
  31.     game_started = false
  32. end
  33.  
  34. function OnPlayerSpawn(PlayerIndex)
  35.     if player_alive(PlayerIndex) then
  36.         local player_object = get_dynamic_player(PlayerIndex)
  37.         if (player_object ~= 0) then
  38.             write_word(player_object + 0x31E, frag_count[map_name])
  39.             write_word(player_object + 0x31F, plasma_count[map_name])
  40.         end
  41.     end
  42. end
  43.  
  44. function OnWeaponPickup(PlayerIndex, WeaponSlot, WeaponType)
  45.     local player_object = get_dynamic_player(PlayerIndex)
  46.     if (player_object ~= 0) then
  47.         local x,y,z = read_vector3d(player_object + 0x5C)
  48.         local fragcount = tonumber(read_word(player_object + 0x31E))
  49.         local plasmacount = tonumber(read_word(player_object + 0x31F))
  50.         if (WeaponType == "2") then
  51.             if (WeaponSlot == "1") then
  52.                 if (fragcount > tonumber(max_frags[map_name])) then
  53.                     timer(1000, "DropFrag", PlayerIndex,x,y,z+0.15)
  54.                 end
  55.             elseif (WeaponSlot == "2") then    
  56.                 if (plasmacount > tonumber(max_plasmas[map_name])) then
  57.                     timer(1000, "DropPlasma", PlayerIndex,x,y,z+0.15)
  58.                 end
  59.             end
  60.         end    
  61.     end
  62. end
  63.  
  64. function DropFrag(PlayerIndex,x,y,z)
  65.     local repl_frag = spawn_object("eqip", "weapons\\frag grenade\\frag grenade", x, y, z+0.15)
  66.     if player_alive(PlayerIndex) then
  67.         execute_command('nades me ' .. max_frags[map_name] .. ' 1', PlayerIndex)
  68.     end
  69. end
  70.  
  71. function DropPlasma(PlayerIndex,x,y,z)
  72.     local repl_plasma = spawn_object("eqip", "weapons\\plasma grenade\\plasma grenade", x, y, z+0.15)
  73.     if player_alive(PlayerIndex) then
  74.         execute_command('nades me ' .. max_plasmas[map_name] .. ' 2', PlayerIndex)
  75.     end
  76. end    
  77.  
  78. function Load_Tables()
  79.     -- specify the number of frag grenades when player spawns
  80.     -- each map in this table, must be separated with a comma
  81.    
  82.     -- specify the number of frag grenades a player will spawn with
  83.     -- map name         # count
  84.     frag_count = {
  85.         beavercreek     =   1,
  86.         bloodgulch      =   1,
  87.         boardingaction  =   1,
  88.         carousel        =   1,
  89.         chillout        =   1,
  90.         damnation       =   1,
  91.         dangercanyon    =   1,
  92.         deathisland     =   1,
  93.         gephyrophobia   =   1,
  94.         hangemhigh      =   1,
  95.         icefields       =   1,
  96.         infinity        =   1,
  97.         longest         =   1,
  98.         prisoner        =   1,
  99.         putput          =   1,
  100.         ratrace         =   1,
  101.         sidewinder      =   1,
  102.         timberland      =   1,
  103.         wizard          =   1,
  104.     }
  105.    
  106.     -- specify the maximum number of frag grenades a player can hold
  107.     -- map name         # count    
  108.     max_frags = {
  109.         beavercreek     =   1,
  110.         bloodgulch      =   1,
  111.         boardingaction  =   1,
  112.         carousel        =   1,
  113.         chillout        =   1,
  114.         damnation       =   1,
  115.         dangercanyon    =   1,
  116.         deathisland     =   1,
  117.         gephyrophobia   =   1,
  118.         hangemhigh      =   1,
  119.         icefields       =   1,
  120.         infinity        =   1,
  121.         longest         =   1,
  122.         prisoner        =   1,
  123.         putput          =   1,
  124.         ratrace         =   1,
  125.         sidewinder      =   1,
  126.         timberland      =   1,
  127.         wizard          =   1,
  128.     }  
  129.    
  130.     -- specify the number of plasma grenades a player will spawn with
  131.     -- map name         # count
  132.    
  133.     plasma_count = {
  134.         beavercreek     =   1,
  135.         bloodgulch      =   1,
  136.         boardingaction  =   1,
  137.         carousel        =   1,
  138.         chillout        =   1,
  139.         damnation       =   1,
  140.         dangercanyon    =   1,
  141.         deathisland     =   1,
  142.         gephyrophobia   =   1,
  143.         hangemhigh      =   1,
  144.         icefields       =   1,
  145.         infinity        =   1,
  146.         longest         =   1,
  147.         prisoner        =   1,
  148.         putput          =   1,
  149.         ratrace         =   1,
  150.         sidewinder      =   1,
  151.         timberland      =   1,
  152.         wizard          =   1, 
  153.     }
  154.    
  155.     -- specify the maximum number of plasma grenades a player can hold
  156.     -- map name         # count
  157.     max_plasmas = {
  158.         beavercreek     =   1,
  159.         bloodgulch      =   1,
  160.         boardingaction  =   1,
  161.         carousel        =   1,
  162.         chillout        =   1,
  163.         damnation       =   1,
  164.         dangercanyon    =   1,
  165.         deathisland     =   1,
  166.         gephyrophobia   =   1,
  167.         hangemhigh      =   1,
  168.         icefields       =   1,
  169.         infinity        =   1,
  170.         longest         =   1,
  171.         prisoner        =   1,
  172.         putput          =   1,
  173.         ratrace         =   1,
  174.         sidewinder      =   1,
  175.         timberland      =   1,
  176.         wizard          =   1, 
  177.     }  
  178.  
  179. end
  180.  
  181. -- Created by H® Shaft
  182. -- Visit Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement