Advertisement
HR_Shaft

Grenade Refill for SAPP

Jul 20th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. -- Grenade Refill by H® Shaft for SAPP
  2.  
  3. -- Allows you to setup a call for a grenade refill and a limit per game that each player can call for a refill
  4. -- Players type "Refill" in chat, and are given a grenade refill if they are alive and within the refill limit.
  5. -- Each time players call for a refill, they are told how many refill calls they have remaining, and if they have reached the limit (refill_limit below)
  6. -- all players are notified: "H® Shaft called for a grenades REFILL" - which helps other players to know they can type REFILL too.
  7.  
  8. -- set grenade counts to what you want them each time a player requests a grenade REFILL:  
  9. frag_count = 2
  10. plasma_count = 1
  11.  
  12. refill_limit = 3  -- Number of times a player can call a grenade REFILL during the current game.
  13.  
  14. -- sapp api version
  15. api_version = "1.8.0.0"
  16.  
  17. -- don't edit --
  18. refill_player = {}
  19. game_started = false
  20.  
  21. function OnScriptLoad()
  22.     register_callback(cb['EVENT_GAME_START'],"OnNewGame")
  23.     register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
  24.     register_callback(cb['EVENT_JOIN'],"OnPlayerJoin")
  25.     register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
  26. end
  27.  
  28. function OnScriptUnload() end
  29.  
  30. function OnPlayerJoin(PlayerIndex)
  31.     if player_present(PlayerIndex) then
  32.         refill_player[PlayerIndex] = 0 
  33.     end
  34. end
  35.  
  36. function OnNewGame()
  37.     game_started = true
  38.     for i = 1,16 do
  39.         if player_present(i) then
  40.             refill_player[i] = 0
  41.         end
  42.     end
  43. end
  44.  
  45. function OnGameEnd()
  46.     game_started = false
  47.     refill_player = {}
  48. end
  49.  
  50. function OnPlayerChat(PlayerIndex, Message)
  51.     local response = nil
  52.     local name = get_var(PlayerIndex,"$name")
  53.     local Message = string.lower(Message)
  54.    
  55.         if (Message == "refill") or (Message == "refill?") then
  56.             response = false
  57.             if refill_player[PlayerIndex] < refill_limit then
  58.                 if game_started then
  59.                     if player_alive(PlayerIndex) then          
  60.                         say_all(string.format("%s called for grenades REFILL.", tostring(name)))
  61.                         refill_player[PlayerIndex] = refill_player[PlayerIndex] + 1
  62.                         timer(500, "GiveNades", PlayerIndex)
  63.                         say(PlayerIndex, "Grenades Refill: " ..plasma_count.. " Plamsa, and " ..frag_count.. " Frags. You have " .. refill_limit - refill_player[PlayerIndex] .. " grenade refills remaining.")
  64.                         say_all(string.format("%s requested a grenade REFILL. ", tostring(name)))
  65.                     else
  66.                         say(PlayerIndex, "Oops! You are dead, grenades wont help you.  Refill cancelled.")
  67.                     end
  68.                 end
  69.             else
  70.                 say(PlayerIndex, "You have reached the grenade refill limit of " .. refill_limit .. " per game. Refill cancelled.")
  71.             end
  72.         end
  73.    
  74.     return response
  75. end
  76.  
  77. function GiveNades(PlayerIndex)
  78.     if player_present(PlayerIndex) then
  79.         if game_started then
  80.             if player_alive(PlayerIndex) then
  81.                 local player_object = get_dynamic_player(PlayerIndex)
  82.                 safe_write(true)
  83.                 write_word(player_object + 0x31E, frag_count)
  84.                 write_word(player_object + 0x31F, plasma_count)
  85.                 safe_write(false)
  86.             end
  87.         end
  88.     end    
  89.     return false
  90. end
  91.  
  92. -- Created by H® Shaft
  93. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement