Added chat messages and fix empty armor slot bug.

This commit is contained in:
stujones11 2013-03-17 19:34:12 +00:00
parent a430ddc587
commit b4cdb676e3

View File

@ -1,6 +1,6 @@
armor_api = { armor_api = {
default_character_skin = "3d_armor_character.png", default_character_skin = "character.png",
player_hp = {}, player_hp = {},
wielded_items = {}, wielded_items = {},
} }
@ -10,7 +10,7 @@ armor_api.get_player_skin = function(self, name)
if mod_path then if mod_path then
local skin = skins.skins[name] local skin = skins.skins[name]
if skin then if skin then
if skin ~= skins.default() and skins.get_type(skin) == skins.type.MODEL then if skins.get_type(skin) == skins.type.MODEL then
return skin..".png" return skin..".png"
end end
end end
@ -110,7 +110,7 @@ armor_api.update_armor = function(self, player)
end end
local name = player:get_player_name() local name = player:get_player_name()
local hp = player:get_hp() local hp = player:get_hp()
if hp == nil or hp == self.player_hp[name] then if hp == nil or hp == 0 or hp == self.player_hp[name] then
return return
end end
if self.player_hp[name] > hp then if self.player_hp[name] > hp then
@ -122,15 +122,22 @@ armor_api.update_armor = function(self, player)
local heal_max = 0 local heal_max = 0
for _,v in ipairs({"head", "torso", "legs", "shield"}) do for _,v in ipairs({"head", "torso", "legs", "shield"}) do
local stack = armor_inv:get_stack("armor_"..v, 1) local stack = armor_inv:get_stack("armor_"..v, 1)
local use = stack:get_definition().groups["armor_use"] or 0 if stack:get_count() > 0 then
local heal = stack:get_definition().groups["armor_heal"] or 0 local use = stack:get_definition().groups["armor_use"] or 0
stack:add_wear(use) local heal = stack:get_definition().groups["armor_heal"] or 0
armor_inv:set_stack("armor_"..v, 1, stack) local item = stack:get_name()
player_inv:set_stack("armor_"..v, 1, stack) stack:add_wear(use)
if stack:get_count() == 0 then armor_inv:set_stack("armor_"..v, 1, stack)
self:set_player_armor(player) player_inv:set_stack("armor_"..v, 1, stack)
if stack:get_count() == 0 then
local desc = minetest.registered_items[item].description
if desc then
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
end
self:set_player_armor(player)
end
heal_max = heal_max + heal
end end
heal_max = heal_max + heal
end end
if heal_max > math.random(100) then if heal_max > math.random(100) then
player:set_hp(self.player_hp[name]) player:set_hp(self.player_hp[name])