More protection from un-initialized player crashes

This commit is contained in:
stujones11
2017-04-13 19:47:43 +01:00
parent b4283f6e60
commit de2c47f334
4 changed files with 51 additions and 35 deletions

View File

@ -27,24 +27,24 @@ unified_inventory.register_page("armor", {
get_formspec = function(player, perplayer_formspec)
local fy = perplayer_formspec.formspec_y
local name = player:get_player_name()
if armor.def[name].init_time == 0 then
return {formspec="label[0,0;Armor not initialized!]"}
end
local formspec = "background[0.06,"..fy..";7.92,7.52;3d_armor_ui_form.png]"..
"label[0,0;Armor]"
if armor.def[name] then
formspec = formspec..
"label[0,0;Armor]"..
"list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]"..
"image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]"..
"label[5.0,"..(fy + 0.0)..";"..S("Level")..": "..armor.def[name].level.."]"..
"label[5.0,"..(fy + 0.5)..";"..S("Heal")..": "..armor.def[name].heal.."]"..
"listring[current_player;main]"..
"listring[detached:"..name.."_armor;armor]"
if armor.config.fire_protect then
formspec = formspec.."label[5.0,"..(fy + 1.0)..";"..
S("Fire")..": "..armor.def[name].fire.."]"
end
if minetest.global_exists("technic") then
formspec = formspec.."label[5.0,"..(fy + 1.5)..";"..
S("Radiation")..": "..armor.def[name].groups["radiation"].."]"
end
if armor.config.fire_protect then
formspec = formspec.."label[5.0,"..(fy + 1.0)..";"..
S("Fire")..": "..armor.def[name].fire.."]"
end
if minetest.global_exists("technic") then
formspec = formspec.."label[5.0,"..(fy + 1.5)..";"..
S("Radiation")..": "..armor.def[name].groups["radiation"].."]"
end
return {formspec=formspec}
end,