1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/maps/biter_battles_v2/no_turret_creep.lua
2020-01-02 16:09:24 +01:00

46 lines
1.3 KiB
Lua

local Public = {}
local type_blacklist = {
["ammo-turret"] = true,
["artillery-turret"] = true,
["electric-turret"] = true,
["fluid-turret"] = true
}
function Public.deny_building(event)
local entity = event.created_entity
if not entity.valid then return end
if not type_blacklist[event.created_entity.type] then return end
local surface = event.created_entity.surface
local spawners = surface.find_entities_filtered({type = "unit-spawner", area = {{entity.position.x - 70, entity.position.y - 70}, {entity.position.x + 70, entity.position.y + 70}}})
if #spawners == 0 then return end
local allowed_to_build = true
for _, e in pairs(spawners) do
if (e.position.x - entity.position.x)^2 + (e.position.y - entity.position.y)^2 < 4096 then
allowed_to_build = false
break
end
end
if allowed_to_build then return end
if event.player_index then
game.players[event.player_index].insert({name = entity.name, count = 1})
else
local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
inventory.insert({name = entity.name, count = 1})
end
surface.create_entity({
name = "flying-text",
position = entity.position,
text = "Turret too close to spawner!",
color = {r=0.98, g=0.66, b=0.22}
})
entity.destroy()
end
return Public