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 > ---------------------------------------------------------
|
|
|
|
|
2020-02-19 21:05:20 -05:00
|
|
|
local hurtcache = {}
|
|
|
|
|
2020-02-19 21:30:45 -05:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp)
|
2019-04-08 08:26:44 -04:00
|
|
|
local orig = player:get_hp()
|
2020-03-22 08:19:39 -04:00
|
|
|
if not nodecore.player_can_take_damage(player) then
|
2019-09-12 19:30:05 -04:00
|
|
|
return orig
|
|
|
|
end
|
2020-02-19 21:05:20 -05:00
|
|
|
local pname
|
2019-04-06 21:23:14 -04:00
|
|
|
if hp < 0 then
|
2020-02-19 21:05:20 -05:00
|
|
|
pname = player:get_player_name()
|
|
|
|
hurtcache[pname] = nodecore.gametime
|
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
|
2020-02-19 22:32:19 -05:00
|
|
|
hp = 1 - orig
|
|
|
|
player:get_meta():set_float("dhp", -1)
|
2019-04-06 21:23:14 -04:00
|
|
|
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)
|
2020-02-20 07:16:19 -05:00
|
|
|
nodecore.setphealth(player, 0, "on_dieplayer")
|
2019-11-20 23:58:42 -05:00
|
|
|
end)
|
|
|
|
|
2020-01-18 10:12:11 -05:00
|
|
|
local full = {}
|
2019-11-29 21:40:47 -05:00
|
|
|
local function heal(player, dtime)
|
2020-02-19 22:32:19 -05:00
|
|
|
local hp = player:get_hp()
|
|
|
|
if hp <= 0 then return end
|
|
|
|
if hp == 1 then
|
|
|
|
local meta = player:get_meta()
|
|
|
|
if meta:get_float("dhp") == -1 then
|
|
|
|
local hurt = hurtcache[player:get_player_name()] or meta:get_float("hurttime")
|
|
|
|
if hurt + 0.5 < nodecore.gametime then
|
2020-02-20 07:16:19 -05:00
|
|
|
nodecore.setphealth(player, 0, "heal_rehurtfx", 2)
|
2020-02-19 22:32:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-18 10:12:11 -05:00
|
|
|
local pname = player:get_player_name()
|
2020-02-19 22:32:19 -05:00
|
|
|
local hpmax = player:get_properties().hp_max
|
2020-02-19 19:48:51 -05:00
|
|
|
if full[pname] and player:get_hp() >= hpmax then return end
|
2020-01-18 10:12:11 -05:00
|
|
|
full[pname] = nil
|
2020-02-19 21:05:20 -05:00
|
|
|
local hurt = hurtcache[pname] or player:get_meta():get_float("hurttime")
|
2019-11-29 21:40:47 -05:00
|
|
|
if hurt >= nodecore.gametime - 4 then return end
|
2020-02-20 07:16:19 -05:00
|
|
|
nodecore.addphealth(player, dtime * 2, "heal")
|
2020-02-19 19:48:51 -05:00
|
|
|
if nodecore.getphealth(player) >= hpmax then full[pname] = true end
|
2019-11-29 21:40:47 -05:00
|
|
|
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)
|
2020-02-19 19:48:51 -05:00
|
|
|
|
2020-02-20 07:35:39 -05:00
|
|
|
local function setmax(player)
|
2020-05-25 11:43:51 -04:00
|
|
|
player:set_properties({hp_max = 8})
|
2020-02-20 07:35:39 -05:00
|
|
|
end
|
|
|
|
minetest.register_on_joinplayer(setmax)
|
|
|
|
minetest.register_on_newplayer(setmax)
|