From a1ff13f365c1a844447aa98f43d53132783aa74e Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Wed, 13 Jul 2022 22:32:21 +0200 Subject: [PATCH] mtn v3 - small fix to higher diff --- maps/mountain_fortress_v3/locomotive.lua | 41 +++++++++++++++++++----- utils/core.lua | 8 +++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 19e23cff..a44304f9 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -182,16 +182,41 @@ local function hurt_players_outside_of_aura() if entity.name == 'character' then game.print(player.name .. messages[random(1, #messages)], {r = 200, g = 0, b = 0}) end - entity.die() - else - entity.damage(1, 'enemy') - entity.health = entity.health - (max_health / 25) - if entity.health <= 0 then - if entity.name == 'character' then - game.print(player.name .. messages[random(1, #messages)], {r = 200, g = 0, b = 0}) - end + if entity.valid then entity.die() end + else + local armor_inventory = player.get_inventory(defines.inventory.character_armor) + if not armor_inventory.valid then + return + end + local armor = armor_inventory[1] + if not armor.valid_for_read then + return + end + local grid = armor.grid + if not grid or not grid.valid then + return + end + local equip = grid.equipment + for _, piece in pairs(equip) do + if piece.valid then + piece.energy = 0 + if piece.shield and piece.shield.valid then + piece.shield = 0 + end + end + end + entity.damage(1, 'enemy') + if entity.valid then + entity.health = entity.health - (max_health / 25) + if entity.health <= 0 then + if entity.name == 'character' then + game.print(player.name .. messages[random(1, #messages)], {r = 200, g = 0, b = 0}) + end + entity.die() + end + end end end end diff --git a/utils/core.lua b/utils/core.lua index f9ceb690..63e41ad2 100644 --- a/utils/core.lua +++ b/utils/core.lua @@ -109,7 +109,9 @@ function Public.iter_connected_players(callback) local players = game.connected_players for i = 1, #players do local player = players[i] - callback(player) + if player and player.valid then + callback(player) + end end end @@ -119,7 +121,9 @@ function Public.iter_players(callback) local players = game.players for i = 1, #players do local player = players[i] - callback(player) + if player and player.valid then + callback(player) + end end end