From 327bb66eb8ab5fc808891365960ec1b47032e4e7 Mon Sep 17 00:00:00 2001 From: Truman Kilen Date: Wed, 9 May 2018 20:25:14 -0500 Subject: [PATCH 1/2] Fix reviving ghosts placed by players and healing entities of other forces --- Addons/Commands/repair.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Addons/Commands/repair.lua b/Addons/Commands/repair.lua index f862f4ce..9d2a1a6a 100644 --- a/Addons/Commands/repair.lua +++ b/Addons/Commands/repair.lua @@ -28,18 +28,20 @@ commands.add_command('repair', 'Repairs all destoryed and damaged entites in an local max_range = rank.power-highest_admin_power > 0 and const/(rank.power-highest_admin_power) or nil local center = player and player.position or {x=0,y=0} if not range or max_range and range > max_range then player_return({'commands.invalid-range',0,math.floor(max_range)}) return commands.error end - for x = -range-2, range+2 do - for y = -range-2, range+2 do - if x^2+y^2 < range^2 then - for key, entity in pairs(player.surface.find_entities_filtered({area={{x+center.x,y+center.y},{x+center.x+1,y+center.y+1}},type='entity-ghost'})) do - if disallow[entity.ghost_prototype.name] then - player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.text_color.crit,player) - Admin.temp_ban(player,'','Attempt To Repair A Banned Item') - entity.destroy() - else entity.revive() end - end - for key, entity in pairs(player.surface.find_entities({{x+center.x,y+center.y},{x+center.x+1,y+center.y+1}})) do if entity.health then entity.health = 10000 end end - end + local area = {{center.x-range,center.y-range},{center.x+range,center.y+range}} + local max_health = 2^32 - 1 + local sq_range = range^2 + for key, entity in pairs(player.surface.find_entities_filtered({area=area,type='entity-ghost'})) do + if entity.force == player.force and (entity.position.x-center.x)^2+(entity.position.y-center.y)^2 < sq_range then + if disallow[entity.ghost_prototype.name] then + player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.text_color.crit,player) + Admin.temp_ban(player,'','Attempt To Repair A Banned Item') + entity.destroy() + elseif entity.time_to_live ~= max_health then + entity.revive() end end end + for key, entity in pairs(player.surface.find_entities(area)) do + if entity.force == player.force and (entity.position.x-center.x)^2+(entity.position.y-center.y)^2 < sq_range and entity.health then entity.health = 10000 end + end end) From a577a6088375e4d66335e566683f3a93434c7bd6 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 10 May 2018 17:32:35 +0100 Subject: [PATCH 2/2] Change name of max_health to max_time_to_live --- Addons/Commands/repair.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Addons/Commands/repair.lua b/Addons/Commands/repair.lua index 9d2a1a6a..654af5f9 100644 --- a/Addons/Commands/repair.lua +++ b/Addons/Commands/repair.lua @@ -29,7 +29,7 @@ commands.add_command('repair', 'Repairs all destoryed and damaged entites in an local center = player and player.position or {x=0,y=0} if not range or max_range and range > max_range then player_return({'commands.invalid-range',0,math.floor(max_range)}) return commands.error end local area = {{center.x-range,center.y-range},{center.x+range,center.y+range}} - local max_health = 2^32 - 1 + local max_time_to_live = 2^32 - 1 local sq_range = range^2 for key, entity in pairs(player.surface.find_entities_filtered({area=area,type='entity-ghost'})) do if entity.force == player.force and (entity.position.x-center.x)^2+(entity.position.y-center.y)^2 < sq_range then @@ -37,7 +37,7 @@ commands.add_command('repair', 'Repairs all destoryed and damaged entites in an player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.text_color.crit,player) Admin.temp_ban(player,'','Attempt To Repair A Banned Item') entity.destroy() - elseif entity.time_to_live ~= max_health then + elseif entity.time_to_live ~= max_time_to_live then entity.revive() end end end