Tweak and optimize medkits
This commit is contained in:
parent
82c2477d70
commit
92c5600d7e
3 changed files with 19 additions and 15 deletions
|
@ -23,5 +23,5 @@ function ctf_treasure.register_default_treasures()
|
|||
treasurer.register_treasure("shooter:arrow_white",0.5,2,{2,18})
|
||||
|
||||
treasurer.register_treasure("ctf_bandages:bandage",0.3,5,{1,6})
|
||||
treasurer.register_treasure("medkits:medkit",0.8,5,{2,4})
|
||||
treasurer.register_treasure("medkits:medkit",0.8,5,2)
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ minetest.register_globalstep(function(dtime)
|
|||
-- ##1## replace info.sprintRequested with info.sprinting
|
||||
if sprintRequested ~= info.sprintRequested then
|
||||
if sprintRequested and info.stamina > MIN_SPRINT
|
||||
and not is_healing(player:get_player_name()) then
|
||||
and not medkits.is_healing(player:get_player_name()) then
|
||||
setSprinting(player, info, true)
|
||||
elseif not sprintRequested then
|
||||
setSprinting(player, info, false)
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
-- Table of tables indexed by player names, each having three fields:
|
||||
-- * HP at time of left-click + regen_max,
|
||||
-- * Max HP of player (generally 20)
|
||||
-- * ID of "healing effect" HUD element
|
||||
-- {
|
||||
-- hp: HP at time of left-click + regen_max,
|
||||
-- pos: Position of player while initiating the healing process
|
||||
-- hud: ID of "healing effect" HUD element
|
||||
-- }
|
||||
local players = {}
|
||||
|
||||
local regen_max = 20 -- Max HP provided by one medkit
|
||||
local regen_interval = 0.3 -- Time in seconds between each iteration
|
||||
local regen_interval = 0.5 -- Time in seconds between each iteration
|
||||
local regen_timer = 0 -- Timer to keep track of regen_interval
|
||||
local regen_step = 1 -- Number of HP added every iteration
|
||||
|
||||
-- Boolean function for use by other mods to check if a player is healing
|
||||
function is_healing(name)
|
||||
medkits = {}
|
||||
function medkits.is_healing(name)
|
||||
return players[name] and true or false
|
||||
end
|
||||
|
||||
|
@ -22,13 +25,13 @@ local function start_healing(stack, player)
|
|||
end
|
||||
local name = player:get_player_name()
|
||||
|
||||
if players[name] or player:get_hp() >= 20 then
|
||||
if players[name] or player:get_hp() >= regen_max then
|
||||
return stack
|
||||
end
|
||||
|
||||
players[name] = {
|
||||
hp = player:get_hp(),
|
||||
pos = player:get_pos(),
|
||||
target = player:get_hp() + regen_max,
|
||||
hud = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0.5, y = 0.5},
|
||||
|
@ -51,7 +54,7 @@ local function stop_healing(player, interrupted)
|
|||
if interrupted then
|
||||
minetest.chat_send_player(name, minetest.colorize("#FF4444",
|
||||
"Your healing was interrupted!"))
|
||||
player:set_hp(info.target - regen_max)
|
||||
player:set_hp(info.hp)
|
||||
player:get_inventory():add_item("main", ItemStack("medkits:medkit 1"))
|
||||
end
|
||||
|
||||
|
@ -80,9 +83,10 @@ minetest.register_globalstep(function(dtime)
|
|||
|
||||
-- Stop healing if target reached
|
||||
local hp = player:get_hp()
|
||||
if hp < info.target and hp < 20 then
|
||||
if hp < regen_max then
|
||||
player:set_hp(hp + regen_step)
|
||||
else
|
||||
player:set_hp(regen_max)
|
||||
stop_healing(player)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue