Add ability to breath underwater

Added functionality for armor to have armor_water=1 in groups so that player can breathe underwater.
This commit is contained in:
tenplus1 2016-01-25 14:47:05 +00:00
parent 0ec2dbfb36
commit 921e1ace24

View File

@ -142,6 +142,7 @@ armor.set_player_armor = function(self, player)
local armor_level = 0 local armor_level = 0
local armor_heal = 0 local armor_heal = 0
local armor_fire = 0 local armor_fire = 0
local armor_water = 0
local state = 0 local state = 0
local items = 0 local items = 0
local elements = {} local elements = {}
@ -167,10 +168,9 @@ armor.set_player_armor = function(self, player)
armor_level = armor_level + level armor_level = armor_level + level
state = state + stack:get_wear() state = state + stack:get_wear()
items = items + 1 items = items + 1
local heal = def.groups["armor_heal"] or 0 armor_heal = armor_heal + (def.groups["armor_heal"] or 0)
armor_heal = armor_heal + heal armor_fire = armor_fire + (def.groups["armor_fire"] or 0)
local fire = def.groups["armor_fire"] or 0 armor_water = armor_water + (def.groups["armor_water"] or 0)
armor_fire = armor_fire + fire
for kk,vv in ipairs(self.physics) do for kk,vv in ipairs(self.physics) do
local o_value = def.groups["physics_"..vv] local o_value = def.groups["physics_"..vv]
if o_value then if o_value then
@ -219,6 +219,7 @@ armor.set_player_armor = function(self, player)
self.def[name].speed = physics_o.speed self.def[name].speed = physics_o.speed
self.def[name].gravity = physics_o.gravity self.def[name].gravity = physics_o.gravity
self.def[name].fire = armor_fire self.def[name].fire = armor_fire
self.def[name].water = armor_water
self:update_player_visuals(player) self:update_player_visuals(player)
end end
@ -406,6 +407,7 @@ minetest.register_on_joinplayer(function(player)
speed = 1, speed = 1,
gravity = 1, gravity = 1,
fire = 0, fire = 0,
water = 0,
} }
armor.textures[name] = { armor.textures[name] = {
skin = armor.default_skin..".png", skin = armor.default_skin..".png",
@ -547,42 +549,53 @@ minetest.register_on_player_hpchange(function(player, hp_change)
return hp_change return hp_change
end, true) end, true)
-- Fire Protection, added by TenPlus1 -- Fire Protection and water breating, added by TenPlus1
if ARMOR_FIRE_PROTECT == true then if ARMOR_FIRE_PROTECT == true then
-- override hot nodes so they do not hurt player anywhere but mod -- override hot nodes so they do not hurt player anywhere but mod
for _, row in ipairs(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}) minetest.override_item(row[1], {damage_per_second = 0})
end end
end end
minetest.register_globalstep(function(dtime) else
armor.timer = armor.timer + dtime print ("[3d_armor] Fire Nodes disabled")
if armor.timer > ARMOR_UPDATE_TIME then end
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name() minetest.register_globalstep(function(dtime)
local pos = player:getpos() armor.timer = armor.timer + dtime
local hp = player:get_hp() if armor.timer < ARMOR_UPDATE_TIME then
if name and pos and hp then return
pos.y = pos.y + 1.4 -- head level end
local node_head = minetest.get_node(pos).name for _,player in pairs(minetest.get_connected_players()) do
pos.y = pos.y - 1.2 -- feet level local name = player:get_player_name()
local node_feet = minetest.get_node(pos).name local pos = player:getpos()
-- is player inside a hot node? local hp = player:get_hp()
for _, row in ipairs(ARMOR_FIRE_NODES) do -- water breathing
-- check fire protection, if not enough then get hurt if name and armor.def[name].water > 0 then
if row[1] == node_head or row[1] == node_feet then if player:get_breath() < 10 then
if hp > 0 and armor.def[name].fire < row[2] then player:set_breath(10)
hp = hp - row[3] * ARMOR_UPDATE_TIME end
player:set_hp(hp) end
break -- fire protection
end if ARMOR_FIRE_PROTECT == true
end and name and pos and hp then
pos.y = pos.y + 1.4 -- head level
local node_head = minetest.get_node(pos).name
pos.y = pos.y - 1.2 -- feet level
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 hp > 0 and armor.def[name].fire < row[2] then
hp = hp - row[3] * ARMOR_UPDATE_TIME
player:set_hp(hp)
break
end end
end end
end end
armor.timer = 0
end end
end) end
end armor.timer = 0
end)