2018-05-19 14:53:38 +02:00
|
|
|
local Event = require 'utils.event'
|
2018-09-23 00:25:13 +02:00
|
|
|
local Game = require 'utils.game'
|
2018-04-06 21:58:50 +02:00
|
|
|
|
2017-06-13 13:16:07 +02:00
|
|
|
local function player_built_entity(event)
|
2018-05-19 14:53:38 +02:00
|
|
|
local entity = event.created_entity
|
2018-11-20 12:46:19 +02:00
|
|
|
if not entity or not entity.valid then
|
|
|
|
return
|
|
|
|
end
|
2017-06-13 13:16:07 +02:00
|
|
|
|
2018-05-19 14:53:38 +02:00
|
|
|
if entity.name == 'train-stop' then
|
|
|
|
local y = math.random(1, 3)
|
|
|
|
if y ~= 1 then
|
2018-09-22 22:07:05 +02:00
|
|
|
local x = math.random(1, #Game.players)
|
2018-09-23 12:46:58 +02:00
|
|
|
local player = Game.get_player_by_index(x)
|
2018-05-19 14:53:38 +02:00
|
|
|
event.created_entity.backer_name = player.name
|
|
|
|
end
|
|
|
|
end
|
2017-06-13 13:16:07 +02:00
|
|
|
end
|
|
|
|
|
2018-04-06 21:58:50 +02:00
|
|
|
Event.add(defines.events.on_built_entity, player_built_entity)
|
|
|
|
Event.add(defines.events.on_robot_built_entity, player_built_entity)
|