assert( _file.Exists( "lua/ULib/init.lua" ), "This script needs ULib to run!" )
_OpenScript( "ULib/init.lua" )
assert( ULib.ULIB_VERSION >= 1.2, "This script requires ULib version 1.2 or higher to run!" )
local textKey = 452
local rectKey = 451
local timer
local finish
local function update()
if _CurTime() > finish then
_ServerCommand( "quit\n" )
return
end
local s = math.floor( finish - _CurTime() )
local m = math.floor( s / 60 )
s = math.mod( s, 60 )
m = math.mod( m, 60 )
s = string.format( "%02i", s )
m = string.format( "%02i", m )
local str = "Time until server shutdown:\n " .. m .. ":" .. s
ULib.sendRect( userid, rectKey, 0.4, 0.2, 0.2, 0.07, 2, 255, 80, 80, 220, "ULib/menu", 0, 0, 0 )
ULib.sendText( userid, textKey, 0.41, 0.215, str, 2, 255, 255, 255, 255, "Default", 0, 0, 0 )
end
local function cc_shutdown( userid, args, argv, argc )
if string.lower( argv[ 1 ] ) == "cancel" then
if timer then
HaltTimer( timer )
timer = nil
ULib.tsay( 0, "Timed shutdown has been halted!" )
end
return
end
if not argv[ 1 ] or not tonumber( argv[ 1 ] ) then
ULib.tsay( userid, "Please specify number of seconds until shutdown." )
end
finish = _CurTime() + tonumber( argv[ 1 ] )
timer = AddTimer( 1, 0, update )
ULib.tsay( userid, "Shutdown has been started. Use \"shutdown cancel\" to stop it." )
ULib.tsay( 0, "ATTENTION: A TIMED SERVER SHUTDOWN HAS BEEN ACTIVATED! Please take screenshots or save your work while you have time." )
end
ULib.CONCOMMAND( "shutdown", cc_shutdown, _, ACCESS_RCON )