From 652fb42ec9782eb4c40e9ca9966d3df83f5caead Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 18 Apr 2019 23:05:25 +0100 Subject: [PATCH] Added repair --- config/repair.lua | 13 +++++++++++++ modules/commands/repair.lua | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 config/repair.lua create mode 100644 modules/commands/repair.lua diff --git a/config/repair.lua b/config/repair.lua new file mode 100644 index 00000000..dd58d8be --- /dev/null +++ b/config/repair.lua @@ -0,0 +1,13 @@ +return { + disallow = { + ['loader']=true, + ['fast-loader']=true, + ['express-loader']=true, + ['electric-energy-interface']=true, + ['infinity-chest']=true + }, + max_range=50, + allow_blueprint_repair=false, + allow_ghost_revive=true, + allow_heal_entities=true +} \ No newline at end of file diff --git a/modules/commands/repair.lua b/modules/commands/repair.lua new file mode 100644 index 00000000..786abdde --- /dev/null +++ b/modules/commands/repair.lua @@ -0,0 +1,37 @@ +local Commands = require 'expcore.commands' +local config = require 'config.repair' +require 'config.command_parse_general' + +local max_time_to_live = 4294967295 -- unit32 max +Commands.new_command('repair','Repairs entities on your force around you') +:add_param('range',false,'integer-range',1,config.max_range) +:register(function(player,range,raw) + local range2 = range^2 + local surface = player.surface + local center = player.position + local area = {{x=center.x-range,y=center.y-range},{x=center.x+range,y=center.y+range}} + if config.allow_ghost_revive then + local ghosts = surface.find_entities_filtered({area=area,type='entity-ghost',force=player.force}) + for _,ghost in pairs(ghosts) do + if ghost.valid and entity.force == player.force then + local x = ghost.position.x-center.x + local y = ghost.position.y-center.y + if x^2+y^2 <= range2 then + if config.allow_blueprint_repair or ghost.time_to_live ~= max_time_to_live then + ghost.revive() + end + end + end + end + end + if config.allow_heal_entities then + local entities = surface.find_entities_filtered({area=area,force=player.force}) + for _,entity in pairs(entities) do + local x = entity.position.x-center.x + local y = entity.position.y-center.y + if entity.health and x^2+y^2 <= range2 then + entity.health = max_time_to_live + end + end + end +end) \ No newline at end of file