function onSay(cid, words, param)
local minid = 3
local restartTime = 5*60*1000
local message = "Server will restart in 5 minutes, data will be saved"
local messageStop = "Restart process has been stopped"
if getPlayerGroupId(cid) >= minid then
if param == "now" or param == "0" then
saveAndRestart(cid)
elseif param == "stop" then
broadcastMessage(messageStop)
stopEvent(saverestart)
elseif getNumber(param) ~= 0 then
broadcastMessage("Server will restart in " .. getNumber(param) .. " minutes, data will be saved")
saverestart = addEvent(saveAndRestart, getNumber(param)*60*1000, cid)
else
broadcastMessage(message)
saverestart = addEvent(saveAndRestart, restartTime, cid)
end
end
end
function getNumber(str)
x = string.gsub(str,"%a","")
x = tonumber(x)
if x ~= nill and x > 0 then
return x
else
return 0
end
end
function returnDate()
curdate = os.date("*t")
if curdate.day < 10 then
curdate.day = "0"..curdate.day
end
if curdate.month < 10 then
curdate.month = "0"..curdate.month
end
if curdate.hour < 10 then
curdate.hour = "0"..curdate.hour
end
if curdate.min < 10 then
curdate.min = "0"..curdate.min
end
return curdate
end
function saveAndRestart(cid)
file = io.open("./logs/restarts.txt", "r")
if file == nil then
file = io.open("./logs/restarts.txt", "w")
end
text = file:read()
if text == nil then
text = ""
end
file:close()
curdate = returnDate()
newdate = "["..curdate.day.."/"..curdate.month.."/"..curdate.year.." "..curdate.hour..":"..curdate.min.."]"
newtext = text..newdate.."Server restarted by "..getPlayerName(cid).."\n"
file = io.open("./logs/restarts.txt", "w")
file:write(newtext)
file:close()
saveData()
io.popen("LuaRestarter.exe")
end