• 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!

Auto Server Save!!

Ispiro

New Member
Joined
Oct 1, 2007
Messages
129
Reaction score
2
Server saves will be initiated after first player's login. After that, it'll save every 10 minutes. To cancel server saves using talkaction, or apply another, make sure to cancel addEvent ID that is saved in alrdyInitServSave. I'll make an edit later on so player can changes server save intervals ingame, or cancel server saves altogether.

Add on global.lua:
Code:
alryInitServSave = 0

onLogin script:
Code:
local minute = 10 -- interval in minutes
local minutes = minute * 60 * 1000 -- dont edit

function onLogin(cid)
	if(alryInitServSave == 0) then
		local eventServ = addEvent(autoSavePlayers, minutes, {})
		alryInitServSave = eventServ
	end
	return 1
end

function autoSavePlayers(parameters)
	savePlayers()
	print("Server save...")
	local eventServ = addEvent(autoSavePlayers, minutes, parameters)
	alryInitServSave = eventServ
end

Tell me if there is any errors or mistake in my script. I'd be glad to fix it.
 
Last edited:
I haven't tested it but it's a 10 line script(maybe less?), pretty simple and most likely bug free.
When server starts, variable "alryInitServSave" is = to 0. After first player logs in, it changes this variable to make sure that it wont addEvent for another server save stacking many of them on eachother ending up with many server saves that weren't planned for. Also, it enables the OT maker to cancel the server save using a talkaction that I'll make later.
Point is: I believe it's a perfectly fine script, with no bugs.
 
I have same question. With !save command and with funtion savePlayer() it saves only players? Or all? Becouse i want know about its possible to save server in console, and then close Serv? Or somethings will be not saved?

So only players? Or all, houses, depot items etc.?
 
Doesn't work for me :S (neither players nor houses)
Did you get any errors? savePlayers() function was not done by me, and I'm not 100% sure if it's working or not. However, this script should schedule savePlayers() for execution every few minutes starting from first player login.
 
I didn't receive any error at all. It's just that it doesn't save anything.

I added the alryInitServSave = 0 in global.lua

I added the onlogin code in login.lua (data\creaturescripts\scripts).

I run the server, login with my char, I see my position on my SQL database, then I move my character a few squares away, and wait. After 30 minutes I go to my SQL database and refresh. Nothing has changed, so it hasn't saved the new position.

Now I use the !save command. Go to my SQL database and refresh. It shows now the correct current position, so !save has saved the new position.

Why doesn't it save?

I did the same again, but this time shutting down the server. When it was restarted, I was again in the first position, nothing had been saved.
 
I didn't receive any error at all. It's just that it doesn't save anything.

I added the alryInitServSave = 0 in global.lua

I added the onlogin code in login.lua (data\creaturescripts\scripts).

I run the server, login with my char, I see my position on my SQL database, then I move my character a few squares away, and wait. After 30 minutes I go to my SQL database and refresh. Nothing has changed, so it hasn't saved the new position.

Now I use the !save command. Go to my SQL database and refresh. It shows now the correct current position, so !save has saved the new position.

Why doesn't it save?

I did the same again, but this time shutting down the server. When it was restarted, I was again in the first position, nothing had been saved.
under:
savePlayers()
add:
print("saved players...")

Tell me if you get any console messages. If you don't get any messages, try this:
Code:
local minutes = 10 -- how many minutes between server saves. Default 10 minutes.

function onLogin(cid)
	if(alryInitServSave == 0) then
		local eventServ = addEvent(autoSavePlayers, 10*60*1000, 10*60*1000)
		alryInitServSave = eventServ
	end
	return 1
end

function autoSavePlayers(timeDiff)
	savePlayers()
	print("players saved...")
	local eventServ = addEvent(autoSavePlayers, timeDiff, timeDiff)
	alryInitServSave = eventServ
end
 
I get this error:

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/login.lua:eek:nLogin

luaAddEvent(). callback parameter should be a function.

And no more.
 
Try this one:
Code:
local minutes = 10 * 60 * 1000 -- change the '10' to the interval of serversaves in minutes

function onLogin(cid)
	if(alryInitServSave == 0) then
		local eventServ = addEvent(autoSavePlayers, minutes, {})
		alryInitServSave = eventSer
	end
	return 1
end

function autoSavePlayers(parameters)
	savePlayers()
	local eventServ = addEvent(autoSavePlayers, minutes, parameters)
	alryInitServSave = eventServ
end
 
you cant make this script, with onThink function every 10 minutes?
 
you cant make this script, with onThink function every 10 minutes?
Well, I thought since I want the first execution to be on a player login, i would use onLogin function instead. First player to login will start the server saves, after that, logins from other players won't affect the server save.
 
Try this one:
Code:
local minutes = 10 * 60 * 1000 -- change the '10' to the interval of serversaves in minutes

function onLogin(cid)
	if(alryInitServSave == 0) then
		local eventServ = addEvent(autoSavePlayers, minutes, {})
		alryInitServSave = eventSer[SIZE="10"][B][COLOR="Red"]v[/COLOR][/B][/SIZE]
	end
	return 1
end

function autoSavePlayers(parameters)
	savePlayers()
	local eventServ = addEvent(autoSavePlayers, minutes, parameters)
	alryInitServSave = eventServ
end

Wow Wow Working now! :p

(small grammar error, marked above)

And for future visits: it saves both players and houses :)

Thx
 
Last edited:
Hey!

Could somebody explain to me how to exactly use it.

add this in Creature Map in Login.lua
Code:
local minutes = 10 * 60 * 1000 -- change the '10' to the interval of serversaves in minutes

function onLogin(cid)
	if(alryInitServSave == 0) then
		local eventServ = addEvent(autoSavePlayers, minutes, {})
		alryInitServSave = eventServ
	end
	return 1
end

function autoSavePlayers(parameters)
	savePlayers()

And if you will change minutes change "10" to "5" if you whana save every 5 minutes.
 
Back
Top