• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TalkAction /restart

4220niller

XHTML / CSS Coder
Joined
Jul 4, 2007
Messages
127
Reaction score
1
Location
Denmark, Korsør
well i saw that thread Helveg made, and i decided to make a restarter of my own, so here it is:

Update, i added a timer event so you can now make it broadcast a message before restart, default is 5 minutes, you can also just say /restart "now to restart it instantly

Update, i added a log too, so now you can see who restarted at wich time in data/logs/restarts.txt, also added a stopper so if you started a timed restart you can now say /restart "stop to stop it

This script is only for The Forgotten Server atm
data/talkactions/scripts/restarter.lua
Code:
function onSay(cid, words, param)
	[COLOR="Red"]local minid = 3[/COLOR]
	[COLOR="Green"]local restartTime = 1000*60*5[/COLOR]
	[COLOR="Blue"]local message = "Server will restart in 5 minutes, data will be saved"[/COLOR]
	[COLOR="Magenta"]local messageStop = "Restart process has been stopped"[/COLOR]
	if getPlayerGroupId(cid) >= minid then
		if param == "now" then
			saveAndRestart(cid)
		elseif param == "stop" then
			broadcastMessage(messageStop)
			stopEvent(saverestart)
		else
			broadcastMessage(message)
			saverestart = addEvent(saveAndRestart, restartTime, cid)
		end
	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("data/logs/restarts.txt", "r")
	if file == nil then
		file = io.open("data/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("data/logs/restarts.txt", "w")
	file:write(newtext)
	file:close()
	savePlayers()
	io.popen("LuaRestarter.exe")
end

The minimum group id to use this command
The time that will pass before the server restarts
The message that will be broadcasted before the server restarts
The message that will be broadcasted if the restart process is stopped
if you use /restart "now then it will restart instantly, otherwise the restartTime has to pass before restart

data/talkactions/talkactions.xml
Code:
	<talkaction words="/restart" script="restarter.lua" />

You cannot use an auto restarter if you want this to work

download the file in my attachments and put it in your otserver directory
 

Attachments

Last edited:
Thanks.
I hope it works.
But do you maybe gonna make a script for evolutions too?
Then it would be very nice! :D
 
I'm not sure at all, but I think it can be enough to change savePlayers() to doCreatureSay(cid,"/save",1)

Just a thought.
 
You have some nmice scripts made gone add it to the list =)
 
does this save houses?????
pretty useless if it didnt :p sorry but i dont see it in the script.. unless save players also saves houses
 
If you open the log file in append mode, you don't have to get the previous text to save it.
Code:
[B]"a+":[/B] append update mode, previous data is preserved,   writing is only allowed at the end of file
@Jgarder: Yes, savePlayers() saves EVERYTHING.
 
I have forgotten server 0.2.6 and i was wondering why if i say the talk action it does it instant no matter what and also i dont have a log folder in my data file should i make one?
 
I got luaRestarter in the folder with .exe of server.

When I'm saying that /restart I'm getting error about Microsoft Visual C++ runtime library.
Runtime error!
Program: path to forgottenserver.exe

This application has requested the Runtime to terminate it in unusual way. Please contact the applications support team for more information.

What the heck?
 
I got luaRestarter in the folder with .exe of server.

When I'm saying that /restart I'm getting error about Microsoft Visual C++ runtime library.


What the heck?

Same as me! What's wrong?
---------------------
Edit

I make it working by deleting line
broadcastMessage(messageStop)
and line with msgrestart, also i set timer to 5 secs, so it's instant restarter.. Is function broadcastMessage supported by TFG lua ?
 
Last edited:
I just got it working ^^

Code:
broadcastMessage("Restart process has been stopped!"[b], 18[/b])

Add this to your script, and should work. , 18
 
How I can make it to restart my OWN named server?

Else, in what program I can edit it?
 
Back
Top