summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlockMen <nmuelll@web.de>2014-08-15 18:25:42 +0200
committerBlockMen <nmuelll@web.de>2014-08-16 13:19:33 +0200
commit078c621ace2aaea1da7f5c02695110ada6553b4d (patch)
tree3514c4443fd50030153e8e35e8832967532d91cb
parent6a0610631624767e5a97f395bfb571d6fc6fcd05 (diff)
Prevent crash by missing armor values
-rw-r--r--armor.lua17
1 files changed, 10 insertions, 7 deletions
diff --git a/armor.lua b/armor.lua
index 2030c42..7f0d0cf 100644
--- a/armor.lua
+++ b/armor.lua
@@ -10,22 +10,25 @@ function hud.get_armor(player)
return
end
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
-function hud.set_armor(player, ges_state, items)
- if not player then return end
-
+function hud.set_armor(player_name, ges_state, items)
local max_items = 4
- if items == 5 then max_items = items end
- local max = max_items*65535
+ if items == 5 then
+ max_items = items
+ end
+ local max = max_items * 65535
local lvl = max - ges_state
lvl = lvl/max
if ges_state == 0 and items == 0 then
lvl = 0
end
- hud.armor[player:get_player_name()] = lvl*(items*(20/max_items))
+ hud.armor[player_name] = lvl* (items * (20 / max_items))
end \ No newline at end of file