1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/features/donator_messages.lua
Matthew c2234505f3 Implement server-side color saving (#566)
* Implement server-side color saving

* Add set_and_return to core utils
2019-01-02 14:42:18 +01:00

34 lines
926 B
Lua

local Game = require 'utils.game'
local Event = require 'utils.event'
local UserGroups = require 'features.user_groups'
local Task = require 'utils.schedule'
local Token = require 'utils.token'
local print_after_timeout =
Token.register(
function(data)
local player = data.player
if not player.valid then
return
end
game.print(data.message, player.chat_color)
end
)
local function player_joined(event)
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
local message = UserGroups.get_donator_welcome_message(player.name)
if not message then
return
end
message = table.concat({'*** ', message, ' ***'})
Task.set_timeout_in_ticks(60, print_after_timeout, {player = player, message = message})
end
Event.add(defines.events.on_player_joined_game, player_joined)