Prevent crash by missing armor values

This commit is contained in:
BlockMen 2014-08-15 18:25:42 +02:00
parent 6a06106316
commit 078c621ace

View File

@ -10,22 +10,25 @@ function hud.get_armor(player)
return return
end end
local name = player:get_player_name() local name = player:get_player_name()
hud.set_armor(player, armor.def[name].state, armor.def[name].count) local def = armor.def[name] or nil
if def and def.state and def.count then
hud.set_armor(name, def.state, def.count)
end
end end
function hud.set_armor(player, ges_state, items) function hud.set_armor(player_name, ges_state, items)
if not player then return end
local max_items = 4 local max_items = 4
if items == 5 then max_items = items end if items == 5 then
local max = max_items*65535 max_items = items
end
local max = max_items * 65535
local lvl = max - ges_state local lvl = max - ges_state
lvl = lvl/max lvl = lvl/max
if ges_state == 0 and items == 0 then if ges_state == 0 and items == 0 then
lvl = 0 lvl = 0
end end
hud.armor[player:get_player_name()] = lvl*(items*(20/max_items)) hud.armor[player_name] = lvl* (items * (20 / max_items))
end end