mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
34 lines
1.2 KiB
Lua
34 lines
1.2 KiB
Lua
|
function ternary (cond, T, F)
|
||
|
if cond then return T else return F end
|
||
|
end
|
||
|
|
||
|
function format_time(ticks)
|
||
|
local s = tostring(math.floor(ticks / 60) % 60)
|
||
|
local m = tostring(math.floor(ticks / 3600) % 60)
|
||
|
local h = tostring(math.floor(ticks / 216000))
|
||
|
h = ternary(h:len() == 1, "0" .. h, h)
|
||
|
m = ternary(m:len() == 1, "0" .. m, m)
|
||
|
s = ternary(s:len() == 1, "0" .. s, s)
|
||
|
print(tostring(h:len()))
|
||
|
return (h .. ":" .. m .. ":" ..s)
|
||
|
end
|
||
|
|
||
|
function log_chat_message(event, message)
|
||
|
game.write_file("chatlog.txt", "[" .. format_time(event.tick) .. "] " .. message .. "\n", true)
|
||
|
end
|
||
|
|
||
|
function player_send_command(event)
|
||
|
local silent = event.command == "silent-command"
|
||
|
if not silent then
|
||
|
local player = game.players[event.player_index]
|
||
|
log_chat_message(event, player.name .. " used command: " .. event.command .. " " .. event.parameters)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function player_send(event)
|
||
|
local player = game.players[event.player_index]
|
||
|
log_chat_message(event, player.name .. ": " .. event.message)
|
||
|
end
|
||
|
|
||
|
Event.register(defines.events.on_console_command, player_send_command)
|
||
|
Event.register(defines.events.on_console_chat, player_send)
|