TalkAction /restart

4220niller

XHTML / CSS Coder
Joined
Jul 4, 2007
Messages
127
Best answers
0
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:

BrasseN

New Member
Joined
Jul 18, 2007
Messages
415
Best answers
0
Reaction score
2
Thanks.
I hope it works.
But do you maybe gonna make a script for evolutions too?
Then it would be very nice! :D
 

Jonern

Retired
Joined
May 31, 2007
Messages
1,054
Best answers
0
Reaction score
8
Location
Norway
I'm not sure at all, but I think it can be enough to change savePlayers() to doCreatureSay(cid,"/save",1)

Just a thought.
 

Herox

the hero of girls :O
Joined
Aug 21, 2007
Messages
62
Best answers
0
Reaction score
0
Location
Brazil
hmm, usefull, i will add in my server :DD
 

Mokerhamer

Retired Global Mod
Joined
Aug 6, 2007
Messages
1,766
Best answers
0
Reaction score
35
You have some nmice scripts made gone add it to the list =)
 

Jgarder

Tprogramming Ex-Adm|n
Joined
Jun 7, 2007
Messages
353
Best answers
0
Reaction score
1
Location
Michigan
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
 

Jonern

Retired
Joined
May 31, 2007
Messages
1,054
Best answers
0
Reaction score
8
Location
Norway
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.
 

Adoniz

New Member
Joined
Oct 12, 2007
Messages
5
Best answers
0
Reaction score
0
Thanks.
I hope it works.
But do you maybe gonna make a script for evolutions too?
Then it would be very nice! :D
Yes, I want that too.
Do a script to evolutions too, please. : )
 

Sean Larson

New Member
Joined
Oct 22, 2007
Messages
99
Best answers
0
Reaction score
1
Location
Colorado
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?
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
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?
 

[email protected]

New Member
Joined
Nov 27, 2007
Messages
17
Best answers
0
Reaction score
0
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:

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
I just got it working ^^

Code:
broadcastMessage("Restart process has been stopped!"[b], 18[/b])
Add this to your script, and should work. , 18
 

EvulMastah

๏̯͡๏﴿
Premium User
Joined
Aug 19, 2007
Messages
4,833
Best answers
0
Reaction score
184
How I can make it to restart my OWN named server?

Else, in what program I can edit it?
 
Top