mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-12-27 03:00:40 +01:00
Update fire and water protection (#42)
Update fire protection to use register_on_player_hpchange instead of overriding node damage, move water protection into different globalstep.
This commit is contained in:
parent
e7abacc94e
commit
42f7dac4d0
@ -436,80 +436,68 @@ end, true)
|
|||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer > armor.config.init_delay then
|
if timer <= armor.config.init_delay then
|
||||||
for player, count in pairs(pending_players) do
|
return
|
||||||
local remove = init_player_armor(player) == true
|
end
|
||||||
pending_players[player] = count + 1
|
timer = 0
|
||||||
if remove == false and count > armor.config.init_times then
|
|
||||||
minetest.log("warning", S("3d_armor: Failed to initialize player"))
|
for player, count in pairs(pending_players) do
|
||||||
remove = true
|
local remove = init_player_armor(player) == true
|
||||||
end
|
pending_players[player] = count + 1
|
||||||
if remove == true then
|
if remove == false and count > armor.config.init_times then
|
||||||
pending_players[player] = nil
|
minetest.log("warning", S("3d_armor: Failed to initialize player"))
|
||||||
|
remove = true
|
||||||
|
end
|
||||||
|
if remove == true then
|
||||||
|
pending_players[player] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- water breathing protection, added by TenPlus1
|
||||||
|
if armor.config.water_protect == true then
|
||||||
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if armor.def[name].water > 0 and
|
||||||
|
player:get_breath() < 10 then
|
||||||
|
player:set_breath(10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
timer = 0
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Fire Protection and water breathing, added by TenPlus1.
|
-- Fire Protection, added by TenPlus1.
|
||||||
|
|
||||||
if armor.config.fire_protect == true then
|
if armor.config.fire_protect == true then
|
||||||
-- override hot nodes so they do not hurt player anywhere but mod
|
-- override any hot nodes that do not already deal damage
|
||||||
for _, row in pairs(armor.fire_nodes) do
|
for _, row in pairs(armor.fire_nodes) do
|
||||||
if minetest.registered_nodes[row[1]] then
|
if minetest.registered_nodes[row[1]] then
|
||||||
minetest.override_item(row[1], {damage_per_second = 0})
|
local damage = minetest.registered_nodes[row[1]].damage_per_second
|
||||||
|
if not damage or damage == 0 then
|
||||||
|
minetest.override_item(row[1], {damage_per_second = row[3]})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print (S("[3d_armor] Fire Nodes disabled"))
|
print ("[3d_armor] Fire Nodes disabled")
|
||||||
end
|
end
|
||||||
|
|
||||||
if armor.config.water_protect == true or armor.config.fire_protect == true then
|
if armor.config.fire_protect == true then
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||||
armor.timer = armor.timer + dtime
|
|
||||||
if armor.timer < armor.config.update_time then
|
if reason.type == "node_damage" and reason.node then
|
||||||
return
|
|
||||||
end
|
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local pos = player:get_pos()
|
|
||||||
local hp = player:get_hp()
|
|
||||||
if not name or not pos or not hp then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
-- water breathing
|
|
||||||
if armor.config.water_protect == true then
|
|
||||||
if armor.def[name].water > 0 and
|
|
||||||
player:get_breath() < 10 then
|
|
||||||
player:set_breath(10)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- fire protection
|
-- fire protection
|
||||||
if armor.config.fire_protect == true then
|
if armor.config.fire_protect == true and hp_change < 0 then
|
||||||
local fire_damage = true
|
local name = player:get_player_name()
|
||||||
pos.y = pos.y + 1.4 -- head level
|
for _,igniter in pairs(armor.fire_nodes) do
|
||||||
local node_head = minetest.get_node(pos).name
|
if reason.node == igniter[1] then
|
||||||
pos.y = pos.y - 1.2 -- feet level
|
if armor.def[name].fire < igniter[2] then
|
||||||
local node_feet = minetest.get_node(pos).name
|
|
||||||
-- is player inside a hot node?
|
|
||||||
for _, row in pairs(armor.fire_nodes) do
|
|
||||||
-- check fire protection, if not enough then get hurt
|
|
||||||
if row[1] == node_head or row[1] == node_feet then
|
|
||||||
if fire_damage == true then
|
|
||||||
armor:punch(player, "fire")
|
armor:punch(player, "fire")
|
||||||
last_punch_time[name] = minetest.get_gametime()
|
else
|
||||||
fire_damage = false
|
hp_change = 0
|
||||||
end
|
|
||||||
if hp > 0 and armor.def[name].fire < row[2] then
|
|
||||||
hp = hp - row[3] * armor.config.update_time
|
|
||||||
player:set_hp(hp)
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
armor.timer = 0
|
return hp_change
|
||||||
end)
|
end, true)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user