Advertisement
HR_Shaft

Continuous Health Regeneration v1 for Sapp

Feb 28th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.17 KB | None | 0 0
  1. -- Continuous Health Regeneration v1 for Sapp
  2. -- by H® Shaft and AelitePrime
  3.  
  4. -- This script will continuously regenerate health of injured players based on options you set.
  5.  
  6.        
  7. -- time (in seconds) in between each incremental increase in health
  8. TIME = 10
  9.  
  10. -- Max health of a player. 1 = normal 100% health
  11. MAX_HEALTH = 1
  12.  
  13. -- Max amount of health the script will regenerate to (must be a number).
  14. MAX_HEALTH_REGEN = MAX_HEALTH
  15.  
  16. -- Number of regens, back to MAX_HEALTH_REGEN, a player gets PER LIFE. If you want to disable (thus it always regenerates) set to nil
  17. MAX_REGENS = nil
  18.  
  19. -- increments in which the health is regenerated.  0.1 = 10%
  20. INCREMENT = 0.1
  21.  
  22. -- Number of times the re-generator will give you health for each regen.
  23. -- If you want to disable it then just make it nil (thus it regenerates repeatedly)
  24. REGEN_COUNT = nil
  25.  
  26. -- Example: 1
  27.     -- player_health = 0.1
  28.     -- INCREMENT = 0.1
  29.     -- MAX_HEALTH_REGEN = 1
  30.     -- REGEN_COUNT = 5
  31.     -- re-generator will stop when you have 0.6 health.
  32. -- Example: 2
  33.     -- player_health = 0.1
  34.     -- INCREMENT = 0.1
  35.     -- MAX_HEALTH_REGEN = 0.5
  36.     -- REGEN_COUNT = 5
  37.     -- re-generator will stop when you have 0.5 health.
  38. -- So it works like this: player_health = (INCREMENT*REGEN_COUNT)+player_health unless its greather than MAX_HEALTH_REGEN, then player_health = MAX_HEALTH_REGEN
  39.  
  40.  
  41. -- don't edit below --
  42. api_version = "1.10.0.0"
  43.  
  44. function OnScriptLoad()
  45.     register_callback(cb['EVENT_GAME_START'], "OnGameStart")
  46.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  47.     register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  48.     register_callback(cb['EVENT_DAMAGE_APPLICATION'], "OnDamageApplication")
  49.    
  50.     regens = {}
  51.     regening = {}
  52.     count = {}
  53.     set_regen = nil
  54.    
  55.     if get_var(0, "$gt") ~= "n/a" then
  56.         game_started = true
  57.         if set_regen == nil then
  58.             set_regen = timer(TIME * 1000, "regenerator")
  59.         end
  60.     else
  61.         game_started = false
  62.     end
  63.    
  64. end
  65.  
  66. function OnGameStart()
  67.     game_started = true
  68.     if set_regen == nil then
  69.         set_regen = timer(TIME * 1000, "regenerator")
  70.     end    
  71. end
  72.  
  73. function OnGameEnd()
  74.     game_started = false
  75.     set_regen = nil
  76. end
  77.  
  78. function OnPlayerSpawn(PlayerIndex)
  79.     if (game_started == true) then
  80.         regens[PlayerIndex] = 0
  81.         regening[PlayerIndex] = false
  82.         count[PlayerIndex] = 0
  83.         local player_object = get_dynamic_player(PlayerIndex)
  84.         if (player_object ~= 0) then       
  85.             write_float(player_object + 0xE0, MAX_HEALTH)
  86.         end
  87.     end
  88. end
  89.  
  90. function OnDamageApplication(PlayerIndex, CauserIndex, MetaID, Damage, HitString, Backtap)
  91.     if (game_started == true) then
  92.         if player_alive(PlayerIndex) then
  93.             count[PlayerIndex] = 0
  94.         end
  95.     end
  96. end
  97.  
  98. function regenerator()
  99.     for PlayerIndex = 1,16 do
  100.         if player_alive(PlayerIndex) then
  101.             local player_object = get_dynamic_player(PlayerIndex)
  102.             if (player_object ~= 0) then
  103.            
  104.                 local player_health = tonumber(math.round(read_float(player_object + 0xE0),1))         
  105.                 local bool = true
  106.                
  107.                 if (player_health < 1) then
  108.                     if tonumber(MAX_REGENS) then
  109.                         if regening[PlayerIndex] and player_health == MAX_HEALTH_REGEN then
  110.                             regening[PlayerIndex] = false
  111.                             regens[PlayerIndex] = (regens[PlayerIndex] or 0) + 1
  112.                         end
  113.                         if (regens[PlayerIndex] or 0) >= MAX_REGENS then
  114.                             bool = false
  115.                         end
  116.                     end
  117.                 end
  118.                
  119.                 if (tonumber(REGEN_COUNT) and ((count[PlayerIndex] or 0) >= REGEN_COUNT)) then
  120.                     bool = false
  121.                 end
  122.                
  123.                 if (bool and player_health < MAX_HEALTH_REGEN) then
  124.                     regening[PlayerIndex] = true
  125.                     count[PlayerIndex] = (count[PlayerIndex] or 0) + 1
  126.                     write_float(player_object + 0xE0, player_health + INCREMENT)
  127.                     if player_health > MAX_HEALTH then
  128.                         write_float(player_object + 0xE0, MAX_HEALTH)
  129.                     end
  130.                 end
  131.                
  132.             end
  133.         end
  134.     end
  135.     return game_started
  136. end
  137.  
  138. function math.round(num, idp)
  139.   return tonumber(string.format("%." .. (idp or 0) .. "f", num))
  140. end
  141.  
  142. function OnError(Message)
  143.     print(debug.traceback())
  144. end
  145.  
  146. -- Created by H® Shaft
  147. -- Visit http://halorace.org/forum/index.php
  148.  
  149. -- The player -db-GoNe/Juhleek - a well spoken liar, cheat.
  150. -- -db- is: "diverging from the believable" - How ironic. A race clan where admins use rcon to favor themselves to win.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement