2019-04-06 21:23:14 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-11-20 23:58:42 -05:00
|
|
|
local minetest, nodecore, pairs
|
|
|
|
= minetest, nodecore, pairs
|
2019-04-06 21:23:14 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
minetest.register_on_player_hpchange(function(player, hp)
|
2019-04-08 08:26:44 -04:00
|
|
|
local orig = player:get_hp()
|
2019-09-12 19:30:05 -04:00
|
|
|
if player:get_armor_groups().immortal then
|
|
|
|
return orig
|
|
|
|
end
|
2019-04-06 21:23:14 -04:00
|
|
|
if hp < 0 then
|
2019-11-29 21:40:47 -05:00
|
|
|
player:get_meta():set_float("hurttime", nodecore.gametime)
|
2019-12-11 06:52:09 -05:00
|
|
|
if nodecore.player_visible(player) then
|
|
|
|
minetest.after(0, function()
|
|
|
|
local now = player:get_hp()
|
|
|
|
if now >= orig then return end
|
|
|
|
nodecore.sound_play_except("player_damage", {
|
|
|
|
pos = player:get_pos(),
|
|
|
|
gain = 0.5
|
|
|
|
}, player)
|
|
|
|
end)
|
|
|
|
end
|
2019-04-06 21:23:14 -04:00
|
|
|
end
|
2019-04-08 08:26:44 -04:00
|
|
|
if hp + orig <= 0 then
|
|
|
|
hp = 1 - orig
|
2019-04-06 21:23:14 -04:00
|
|
|
player:get_meta():set_float("dhp", -1)
|
|
|
|
end
|
|
|
|
return hp
|
2019-08-27 19:14:51 -04:00
|
|
|
end,
|
|
|
|
true
|
|
|
|
)
|
2019-11-20 23:58:42 -05:00
|
|
|
|
|
|
|
minetest.register_on_dieplayer(function(player)
|
|
|
|
player:set_hp(1)
|
|
|
|
player:get_meta():set_float("dhp", -1)
|
|
|
|
end)
|
|
|
|
|
2019-11-29 21:40:47 -05:00
|
|
|
local function heal(player, dtime)
|
|
|
|
if player:get_hp() <= 0 then return end
|
|
|
|
if player:get_breath() <= 0 then return end
|
|
|
|
local hurt = player:get_meta():get_float("hurttime")
|
|
|
|
if hurt >= nodecore.gametime - 4 then return end
|
|
|
|
nodecore.addphealth(player, dtime * 2)
|
|
|
|
end
|
2019-11-20 23:58:42 -05:00
|
|
|
minetest.register_globalstep(function(dtime)
|
2019-11-29 21:40:47 -05:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
heal(player, dtime)
|
2019-11-20 23:58:42 -05:00
|
|
|
end
|
|
|
|
end)
|