Add nil check after call to 3d_armor's get_valid_player

If a game is started instantly after a new player joins, the armor may still be uninitialized.
master
upsilon 2019-08-13 22:36:46 +02:00
parent 4bfa535de6
commit 3df67950ec
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
1 changed files with 8 additions and 6 deletions

View File

@ -86,14 +86,16 @@ hg_match.register_on_new_game(function(map, players)
inv:set_list("craft", {})
-- Armor is a bit more complex
local _, armor_inv = armor:get_valid_player(player, "[hg_match.on_new_game]")
for i = 1, armor_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then
armor:set_inventory_stack(player, i, nil)
armor:run_callbacks("on_unequip", player, i, stack)
if armor_inv then
for i = 1, armor_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then
armor:set_inventory_stack(player, i, nil)
armor:run_callbacks("on_unequip", player, i, stack)
end
end
armor:set_player_armor(player)
end
armor:set_player_armor(player)
-- Teleport the player to a spawn point
local sp_i = math.random(#spawnpoints)