1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-06 00:23:49 +02:00
ComfyFactorio/modules/dynamic_player_spawn.lua
2020-03-27 14:07:56 +01:00

17 lines
782 B
Lua

-- this automatically sets player's force spawn point to where a lot of buildings are
local event = require 'utils.event'
local valid_types = {"boiler", "furnace", "generator", "offshore-pump", "lab", "assembling-machine"}
local function on_built_entity(event)
if not event.created_entity.valid then return end
local player = game.players[event.player_index]
local area = {{event.created_entity.position.x - 12, event.created_entity.position.y - 12}, {event.created_entity.position.x + 12, event.created_entity.position.y + 12}}
if player.surface.count_entities_filtered({area = area, force = player.force, type = valid_types}) > 12 then
player.force.set_spawn_position(player.position, player.surface)
end
end
event.add(defines.events.on_built_entity, on_built_entity)