From 683d588e83db1f3df8cc2aa41105cb0053331908 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 25 Nov 2024 09:35:50 +0900 Subject: [PATCH] Fix scorched earth on_robot_built_entity (#7) --- .../module/modules/addons/scorched-earth.lua | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/exp_legacy/module/modules/addons/scorched-earth.lua b/exp_legacy/module/modules/addons/scorched-earth.lua index 5ef34e22..f71881f6 100644 --- a/exp_legacy/module/modules/addons/scorched-earth.lua +++ b/exp_legacy/module/modules/addons/scorched-earth.lua @@ -88,25 +88,14 @@ Event.add(defines.events.on_player_changed_position, function(event) end) -- When an entity is build there is a much higher chance that the tiles will degrade -Event.add(defines.events.on_built_entity, function(event) - local entity = event.created_entity - local surface = entity.surface - local position = entity.position - local strength = get_tile_strength(surface, position) +local function on_built_entity(event) + local entity = event.entity + local strength = get_tile_strength(entity.surface, entity.position) if not strength then return end if get_probability(strength) * config.weakness_value > math.random() then degrade_entity(entity) end -end) +end --- Same as above but with robots -Event.add(defines.events.on_robot_built_entity, function(event) - local entity = event.created_entity - local surface = entity.surface - local position = entity.position - local strength = get_tile_strength(surface, position) - if not strength then return end - if get_probability(strength) * config.weakness_value > math.random() then - degrade_entity(entity) - end -end) +Event.add(defines.events.on_built_entity, on_built_entity) +Event.add(defines.events.on_robot_built_entity, on_built_entity)