medkits: Remove hardcoded regen_max; use hp_max instead (#584)
This commit is contained in:
parent
afc8447c62
commit
fffe0ea3d6
1 changed files with 13 additions and 12 deletions
|
@ -6,10 +6,9 @@
|
||||||
-- }
|
-- }
|
||||||
local players = {}
|
local players = {}
|
||||||
|
|
||||||
local regen_max = 20 -- Max HP provided by one medkit
|
local regen_interval = 0.5 -- Time in seconds between each step
|
||||||
local regen_interval = 0.5 -- Time in seconds between each iteration
|
local regen_timer = 0 -- Timer to keep track of regen_interval
|
||||||
local regen_timer = 0 -- Timer to keep track of hpregen.interval
|
local regen_step = 1 -- Number of HP added every step
|
||||||
local regen_step = 1 -- Number of HP added every iteration
|
|
||||||
|
|
||||||
-- Boolean function for use by other mods to check if a player is healing
|
-- Boolean function for use by other mods to check if a player is healing
|
||||||
medkits = {}
|
medkits = {}
|
||||||
|
@ -26,11 +25,13 @@ local function start_healing(stack, player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
|
|
||||||
if players[name] or hp >= regen_max then
|
local hp_max = player:get_properties().hp_max
|
||||||
|
if players[name] or hp == hp_max then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
players[name] = {
|
players[name] = {
|
||||||
|
regen_max = hp_max,
|
||||||
hp = hp,
|
hp = hp,
|
||||||
pos = player:get_pos(),
|
pos = player:get_pos(),
|
||||||
hud = player:hud_add({
|
hud = player:hud_add({
|
||||||
|
@ -74,8 +75,8 @@ ctf_flag.register_on_precapture(function()
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Called after left-click every n seconds (determined by regen_interval)
|
-- Called after left-click every n seconds (determined by
|
||||||
-- heals player for a total of regen_max, limited by player's max hp
|
-- regen_interval); heals player until player's hp_max
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
regen_timer = regen_timer + dtime
|
regen_timer = regen_timer + dtime
|
||||||
if regen_timer < regen_interval then
|
if regen_timer < regen_interval then
|
||||||
|
@ -95,12 +96,12 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Stop healing if target reached
|
-- Stop healing if target reached
|
||||||
if players[name] then
|
local pstat = players[name]
|
||||||
|
if pstat then
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
if hp < regen_max then
|
if hp < pstat.regen_max then
|
||||||
player:set_hp(math.min(hp + regen_step, regen_max))
|
player:set_hp(math.min(hp + regen_step, pstat.regen_max))
|
||||||
else
|
else
|
||||||
player:set_hp(regen_max)
|
|
||||||
stop_healing(player)
|
stop_healing(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue