mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
implemented set time command #9
This commit is contained in:
parent
7574025466
commit
26e4b599a2
49
chatlog.lua
49
chatlog.lua
@ -1,16 +1,40 @@
|
||||
local time_set_moment = 0
|
||||
local current_month = 1
|
||||
local current_day = 1
|
||||
local current_h = 0
|
||||
local current_m = 0
|
||||
local days_passed = 0
|
||||
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)
|
||||
|
||||
|
||||
ticks = ticks - time_set_moment - 5184000 * days_passed + 3600 * (current_m + current_h * 60)
|
||||
|
||||
if ticks > 5184000 then
|
||||
current_day = current_day + 1
|
||||
days_passed = days_passed + 1
|
||||
ticks = ticks - 5184000
|
||||
--fuck february
|
||||
if current_day > 30 then
|
||||
if (current_day > 31 and (current_day % 2) == 1) or ((current_day % 2) == 0) then
|
||||
current_month = current_month + 1
|
||||
current_day = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local s = tostring(math.floor(ticks / 60) % 60)
|
||||
local m = tostring(math.floor(ticks / 3600) % 60)
|
||||
local h = tostring(math.floor(ticks / 216000))
|
||||
local current_month_str = ternary(current_month < 10, "0" .. tostring(current_month), tostring(current_month))
|
||||
local current_day_str = ternary(current_day < 10, "0" .. tostring(current_day), tostring(current_day))
|
||||
h = ternary(h:len() == 1, "0" .. h, h)
|
||||
m = ternary(m:len() == 1, "0" .. m, m)
|
||||
s = ternary(s:len() == 1, "0" .. s, s)
|
||||
return current_day_str .. "-" .. current_month_str .. "-" .. h .. ":" .. m .. ":" ..s
|
||||
end
|
||||
|
||||
function log_chat_message(event, message)
|
||||
@ -40,6 +64,15 @@ function player_left(event)
|
||||
local player = game.players[event.player_index]
|
||||
log_chat_message(event, "### " .. player.name .. " left the game. ###")
|
||||
end
|
||||
|
||||
function set_time(d, month, h, m)
|
||||
time_set_moment = game.tick
|
||||
current_month = month
|
||||
current_day = d
|
||||
current_h = h
|
||||
current_m = m
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_console_command, player_send_command)
|
||||
Event.register(defines.events.on_console_chat, player_send)
|
||||
Event.register(defines.events.on_player_joined_game, player_joined)
|
||||
|
@ -67,7 +67,7 @@ function walkabout(cmd)
|
||||
cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
params = {}
|
||||
local params = {}
|
||||
if cmd.parameter == nil then
|
||||
game.print("Walkabout failed.")
|
||||
return
|
||||
@ -138,10 +138,45 @@ function walkabout(cmd)
|
||||
game.print(player_name .. " could not go on a walkabout.")
|
||||
end
|
||||
|
||||
function on_set_time(cmd)
|
||||
if not game.player.admin then
|
||||
cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
|
||||
local params = {}
|
||||
local params_numeric = {}
|
||||
|
||||
|
||||
if cmd.parameter == nil then
|
||||
game.player.print("Setting clock failed. Usage: /settime <day> <month> <hour> <minute>")
|
||||
return
|
||||
end
|
||||
|
||||
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
|
||||
|
||||
if params[4] == nil then
|
||||
game.player.print("Setting clock failed. Usage: /settime <day> <month> <hour> <minute>")
|
||||
return
|
||||
end
|
||||
|
||||
for _, param in pairs(params) do
|
||||
if tonumber(param) == nil then
|
||||
game.player.print("Don't be stupid.")
|
||||
return
|
||||
end
|
||||
table.insert(params_numeric, tonumber(param))
|
||||
end
|
||||
if (params_numeric[2] > 12) or (params_numeric[2] < 1) or (params_numeric[1] > 31) or (params_numeric[1] < 1) or (params_numeric[2] % 2 == 0 and params_numeric[1] > 30) or (params_numeric[3] > 24) or (params_numeric[3] < 0) or (params_numeric[4] > 60) or (params_numeric[4] < 0) then
|
||||
game.player.print("Don't be stupid.")
|
||||
return
|
||||
end
|
||||
set_time(params_numeric[1], params_numeric[2], params_numeric[3], params_numeric[4])
|
||||
end
|
||||
commands.add_command("kill", "Will kill you.", kill)
|
||||
commands.add_command("detrain", "<player> - Kicks the player off a train.", detrain)
|
||||
commands.add_command("tpplayer", "<player> - Teleports you to the player.", teleport_player)
|
||||
commands.add_command("invoke", "<player> - Teleports the player to you.", invoke)
|
||||
commands.add_command("tppos", "Teleports you to a selected entity.", teleport_location)
|
||||
commands.add_command("walkabout", '<player> - <"close", "far", "very far", number>', walkabout)
|
||||
commands.add_command("walkabout", '<player> <"close", "far", "very far", number> - Send someone on a walk.', walkabout)
|
||||
commands.add_command("settime", '<day> <month> <hour> <minute> - Sets the clock', on_set_time)
|
||||
|
Loading…
Reference in New Issue
Block a user