Advertisement
HR_Shaft

Medic for SAPP

Jul 20th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. -- Medic by H® Shaft for SAPP
  2.  
  3. -- Allows you to setup a call for a medic (player request to be healed), and a limit per game that each player can call for medic
  4. -- Players type "Medic" in chat, 6 seconds later they are healed if they are alive and injured.
  5. -- Each time players call for a medic, they are told how many medic calls they have remaining, and if they have reached the limit (hp_limit below)
  6. -- all players are notified: "H® Shaft called for a MEDIC" - which helps other players to know they can type medic too.
  7.  
  8. -- Note: the delay of 6 seconds is intentional to prevent the shield recharge beep from continuing/getting stuck, and to prevent players using it in the middle of a battle
  9.  
  10. hp_limit = 4  -- Number of times a player can call MEDIC during the current game.
  11.  
  12. -- sapp api version
  13. api_version = "1.8.0.0"
  14.  
  15. -- don't edit --
  16. hp_player = {}
  17. game_started = false
  18.  
  19. function OnScriptLoad()
  20.     register_callback(cb['EVENT_GAME_START'],"OnNewGame")
  21.     register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
  22.     register_callback(cb['EVENT_JOIN'],"OnPlayerJoin")
  23.     register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
  24. end
  25.  
  26. function OnScriptUnload() end
  27.  
  28. function OnPlayerJoin(PlayerIndex)
  29.     if player_present(PlayerIndex) then
  30.         hp_player[PlayerIndex] = 0 
  31.     end
  32. end
  33.  
  34. function OnNewGame()
  35.     game_started = true
  36.     for i = 1,16 do
  37.         if player_present(i) then
  38.             hp_player[i] = 0
  39.         end
  40.     end
  41. end
  42.  
  43. function OnGameEnd()
  44.     game_started = false
  45.     hp_player = {}
  46. end
  47.  
  48. function OnPlayerChat(PlayerIndex, Message)
  49.     local response = nil
  50.     local name = get_var(PlayerIndex,"$name")
  51.     local Message = string.lower(Message)
  52.    
  53.         if (Message == "medic") or (Message == "medic?")then
  54.             response = false
  55.             if hp_player[PlayerIndex] < hp_limit then
  56.                 if game_started then
  57.                     if player_alive(PlayerIndex) then
  58.                         local obj_health = tonumber(get_var(PlayerIndex, "$hp"))
  59.                         if obj_health < 1 then
  60.                             hp_player[PlayerIndex] = hp_player[PlayerIndex] + 1
  61.                             timer(6000, "ApplyHP", PlayerIndex)
  62.                             say(PlayerIndex, "**MEDIC** " ..name.. ": You will be healed in 6 seconds. You have " .. hp_limit - hp_player[PlayerIndex] .. " MEDIC calls remaining.")
  63.                             say_all(string.format("%s called for a MEDIC. ", tostring(name)))                          
  64.                         elseif obj_health == 1 then
  65.                             say(PlayerIndex, "**MEDIC** Oops! You are already at full health! MEDIC cancelled.")
  66.                         end
  67.    
  68.                     end
  69.                 end
  70.             else
  71.                 say(PlayerIndex, "You have reached the limit of " .. hp_limit .. " MEDIC calls per game.") 
  72.             end
  73.         end
  74.    
  75.     return response
  76. end
  77.  
  78. function ApplyHP(PlayerIndex)
  79.     if player_present(PlayerIndex) then
  80.         if game_started then
  81.             if player_alive(PlayerIndex) then
  82.                 local name = get_var(PlayerIndex,"$name")
  83.                 local player_object = get_dynamic_player(PlayerIndex)
  84.                 local obj_health = tonumber(get_var(PlayerIndex, "$hp"))
  85.                 if obj_health < 1 then
  86.                     write_float(player_object + 0xE0, 1)
  87.                     say(PlayerIndex, "**MEDIC** " ..name.. " You were healed!")                                        
  88.                 else
  89.                     say(PlayerIndex, "**MEDIC** Oops! You are already at full health! MEDIC cancelled.")
  90.                 end
  91.             else
  92.                 say(PlayerIndex, "**MEDIC** Oops! You are dead, a healthpack won't help you. MEDIC cancelled.")
  93.             end
  94.         end
  95.     end
  96.     return false
  97. end
  98.  
  99. -- Created by H® Shaft
  100. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement