Do you mean something like this? Please, create the mod.
Code: Select all
--control.lua
INTERFERENCE_RANGE = 50
function IsEntityRoboport(entity)
if entity.name == "entity-ghost" then if entity.ghost_name == "roboport" then return true end
else if entity.name == "roboport" then return true end end
return false
end
script.on_event(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local player = game.players[event.player_index]
local pos = { x = entity.position.x, y = entity.position.y }
if IsEntityRoboport(entity) then
local offset = INTERFERENCE_RANGE - 2
local interference_area = {{pos.x - offset, pos.y-offset}, {pos.x + offset, pos.y + offset}}
local entities = game.surfaces[1].find_entities_filtered{name = {"roboport"}, area = interference_area}
--local entities = game.surfaces[1].find_entities_filtered{name = {"roboport"}, position = pos, radius = interference-area}
for _, e in pairs(entities) do
if e ~= entity then
if entity.name ~= "entity-ghost" then -- If the item is not a ghost insert it back to the player.
player.insert({name = entity.name, count = 1})
end
entity.destroy()
game.print("Roboports logistic range can not overlap.")
return
end
end
end
end
)