Commands: /restart and /stopRestart
Useful manual restart server command that countdown with timer and broadcast notification (reason of restart + timer) to online players (at bottom of screen).
PREVIEW
U S A G E
First of all, please add this inside your global variables like somewhere in global.lua or something:Useful manual restart server command that countdown with timer and broadcast notification (reason of restart + timer) to online players (at bottom of screen).
PREVIEW
U S A G E
/restart time_in_miliseconds , reason
example: /restart 15 , Maintenance restart please hold your chairs bitches!
/stopRestart
If "restart command" was executed by someone before, you can stop it by saying above command.
Lua:
STORAGE_REBOOT = insert_your_free_global_storage
/restart (talkactions/scripts/restart.lua)
Lua:
<talkaction words="/restart" separator=" " script="restart.lua" />
Lua:
function onSay(player, words, param)
local restartGlobalStorage = Game.getStorageValue(STORAGE_REBOOT)
local split = param:split(",")
local server = "Server"
local time = tonumber(split[1])
local reason = split[2]
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return false
end
if time == nil or time <= 0 then
player:sendCancelMessage("ERROR: Argument - time, not found! You need to use it properly ex. /restart time, reason")
return false
end
if time >= 1800 then
player:sendCancelMessage("Time to restart cannot be longer than 30 minutes (1800).")
return false
end
if reason == nil then
player:sendCancelMessage("ERROR: Argument - reason, not found! You need to use it properly ex. /restart time, reason")
return false
end
if not Game.getStorageValue(STORAGE_REBOOT) then
for _, tmpPlayer in ipairs(Game.getPlayers()) do
broadcastMessage("Game World is going to perform maintenance reboot in ".. time .." seconds, because of following reason: ".. reason ..".", MESSAGE_STATUS_WARNING)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Executed Game World Rebooting! To stop this action, write: /stopRestart")
Game.setStorageValue(STORAGE_REBOOT, time)
addEvent(minusTime,1000,tmpPlayer)
return true
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Rebooting Progress is already running, to Stop this action, write: /stopRestart")
return true
end
end
function minusTime()
local restartGlobalStorage = Game.getStorageValue(STORAGE_REBOOT)
if restartGlobalStorage == nil then
return true
end
if restartGlobalStorage > 0 then
for _, tmpPlayer in ipairs(Game.getPlayers()) do
tmpPlayer:sendTextMessage(MESSAGE_STATUS_SMALL,"Game World is going to reboot in: "..restartGlobalStorage.." seconds.")
end
Game.setStorageValue(STORAGE_REBOOT,restartGlobalStorage - 1)
addEvent(minusTime,1000)
elseif restartGlobalStorage == 0 then
for _, tmpPlayer in ipairs(Game.getPlayers()) do
tmpPlayer:sendTextMessage(MESSAGE_STATUS_SMALL,"Rebooting Game World!")
end
saveServer()
addEvent(rebootServer(), 1000)
end
end
/stopRestart (talkactions/scripts/stopRestart.lua)
Lua:
<talkaction words="/stopRestart" separator=" " script="stopRestart.lua" />
Lua:
function onSay(cid, words, param, channel)
local restartGlobalStorage = Game.getStorageValue(STORAGE_REBOOT)
if restartGlobalStorage ~= nil then
broadcastMessage("Game World reboot has been canceled by Game Creator.")
Game.setStorageValue(STORAGE_REBOOT)
cid:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You canceled Game World reboot progress.")
else
cid:sendTextMessage(MESSAGE_STATUS_SMALL,"First you must call Game World reboot by using: /restart time, reason!")
return true
end
end
Last edited: