2018-05-19 14:53:38 +02:00
|
|
|
local Event = require 'utils.event'
|
2018-04-06 21:58:50 +02:00
|
|
|
|
2018-12-19 15:43:30 +02:00
|
|
|
local function pick_name(event)
|
|
|
|
-- Create a weight table comprised of the backer name, a player's name, and a regular's name
|
|
|
|
local random_player = table.get_random(game.players, true)
|
|
|
|
if not random_player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name_table = {
|
|
|
|
{event.created_entity.backer_name, 8},
|
|
|
|
{random_player.name, 1},
|
|
|
|
{table.get_random(global.regulars, false, true), 1},
|
|
|
|
}
|
|
|
|
return table.get_random_weighted(name_table)
|
|
|
|
end
|
|
|
|
|
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
|
2018-12-19 15:43:30 +02:00
|
|
|
event.created_entity.backer_name = pick_name(event) or event.created_entity.backer_name
|
2018-05-19 14:53:38 +02:00
|
|
|
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)
|