Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Auto Save

Skilled Illusionist
Loyal Member
Joined
Aug 4, 2008
Messages
376
Reaction score
37
ChannelServer
PHP:
public void saveAll() {
        for (MapleCharacter chr : players.getAllCharacters()) {
            chr.saveToDB(true, true);
        }
    }

Save this as AutoSave.js, and add to world.prop events list AutoSave
PHP:
var setupTask;

function init() {
    scheduleNew();
}

function scheduleNew() {
    var cal = java.util.Calendar.getInstance();
    cal.set(java.util.Calendar.HOUR, 0);
    cal.set(java.util.Calendar.MINUTE, 10);
    cal.set(java.util.Calendar.SECOND, 0);
    var nextTime = cal.getTimeInMillis();
    while (nextTime <= java.lang.System.currentTimeMillis()) {
        nextTime += 1000 * SECONDS;
    }
    setupTask = em.scheduleAtTimestamp("start", nextTime);
}

function cancelSchedule() {
    setupTask.cancel(true);
}

function start() {
    scheduleNew();
    em.getChannelServer().saveAll();
    var iter = em.getInstances().iterator();
    while (iter.hasNext()) {
        var eim = iter.next();
    }
}


To justify the auto save time...
change the
PHP:
    cal.set(java.util.Calendar.HOUR, 0);
     cal.set(java.util.Calendar.MINUTE, 10);
     cal.set(java.util.Calendar.SECOND, 0);
to the intervals you want.

Change
PHP:
nextTime += 1000 * SECONDS;
to the autosave interval

Now find the number of seconds for your interval and replace 'SECONDS' with it.
So if your doing 1 minute, it'll be 60. If your doing 10 minutes, then its 60 x 10, which is 600. 1 hour is 60 x 60, which is 3600, and so on
 
Last edited:
Newbie Spellweaver
Joined
Jan 4, 2009
Messages
13
Reaction score
0
Sorry Noob Question But Where Is The Top Part Saved And Where Do I Save AutoSave.js?
 
Newbie Spellweaver
Joined
Dec 8, 2008
Messages
63
Reaction score
3
1000 * SECOND * MINUTE * HOUR;

You should have just said 1000 * number of seconds
 
Skilled Illusionist
Loyal Member
Joined
Aug 4, 2008
Messages
376
Reaction score
37
1000 * SECOND * MINUTE * HOUR;

You should have just said 1000 * number of seconds
Eh, I'll just do that since it's less complicated.

---------- Post added at 11:31 PM ---------- Previous post was at 11:28 PM ----------

Sorry Noob Question But Where Is The Top Part Saved And Where Do I Save AutoSave.js?
You put it under a function.

AutoSave.js into the event folder
 
return null;
Loyal Member
Joined
Dec 21, 2008
Messages
805
Reaction score
130
lol are u jking are u fcking gm on ijji? :O
 
Newbie Spellweaver
Joined
Nov 22, 2009
Messages
83
Reaction score
4
ChannelServer
PHP:
public void saveAll() {
        for (MapleCharacter chr : players.getAllCharacters()) {
            chr.saveToDB(true, true);
        }
    }

Save this as AutoSave.js, and add to world.prop events list AutoSave
PHP:
var setupTask;

function init() {
    scheduleNew();
}

function scheduleNew() {
    var cal = java.util.Calendar.getInstance();
    cal.set(java.util.Calendar.HOUR, 0);
    cal.set(java.util.Calendar.MINUTE, 10);
    cal.set(java.util.Calendar.SECOND, 0);
    var nextTime = cal.getTimeInMillis();
    while (nextTime <= java.lang.System.currentTimeMillis()) {
        nextTime += 1000 * SECONDS;
    }
    setupTask = em.scheduleAtTimestamp("start", nextTime);
}

function cancelSchedule() {
    setupTask.cancel(true);
}

function start() {
    scheduleNew();
    em.getChannelServer().saveAll();
    var iter = em.getInstances().iterator();
    while (iter.hasNext()) {
        var eim = iter.next();
    }
}


To justify the auto save time...
change the
PHP:
    cal.set(java.util.Calendar.HOUR, 0);
     cal.set(java.util.Calendar.MINUTE, 10);
     cal.set(java.util.Calendar.SECOND, 0);
to the intervals you want.

Change
PHP:
nextTime += 1000 * SECONDS;
to the autosave interval

Now find the number of seconds for your interval and replace 'SECONDS' with it.
So if your doing 1 minute, it'll be 60. If your doing 10 minutes, then its 60 x 10, which is 600. 1 hour is 60 x 60, which is 3600, and so on

Works and its good for servers that crash alot.
 
Newbie Spellweaver
Joined
Sep 29, 2009
Messages
43
Reaction score
3
auto save is poop.

why is it poop doesit lah like poop when auto saving otherwise it would be usefull for all them servers that get alot of crashes to stop rollbacks??? anyways

*Kinda off-topic*
if this thread is old sorry for the bump.
 
Joined
Oct 14, 2008
Messages
960
Reaction score
197
you need to work on the crashes... autosave won't make it more stable.
using autosave is the worst idea I've seen, but
good job for people who need it.
 
Newbie Spellweaver
Joined
Sep 29, 2009
Messages
43
Reaction score
3
then dont bother posting here -_- if think it is then why post.

*off topic*
Because People flame because they are mad some peoples releases are either incomplete for a reason, already been released or just because they have nothing better to do

i never complain because their releases is what makes ALL SERVERS BETTER oh and stuff people release like re-packs saying all credits to me WHAT ABOUT ODINMS original Developers they deserve Majority of the credit

i believe majority of flamers come from people that don't release stuff their selfs so why they complain for? who would ever know

*on topic*
how do i get to to auto save every 5mins.?
i am currently making a re-pack to soon release once its done
 
Newbie Spellweaver
Joined
Feb 8, 2009
Messages
17
Reaction score
1
PHP:
  cal.set(java.util.Calendar.HOUR, 0);
     cal.set(java.util.Calendar.MINUTE, 10);
     cal.set(java.util.Calendar.SECOND, 0);

What does that do? :O
why do you have "10" on MINUTE ?

I just want to know what does it do, and what happens if i change the numbers.

Thanks :p
 
Skilled Illusionist
Loyal Member
Joined
Aug 4, 2008
Messages
376
Reaction score
37
PHP:
  cal.set(java.util.Calendar.HOUR, 0);
     cal.set(java.util.Calendar.MINUTE, 10);
     cal.set(java.util.Calendar.SECOND, 0);
What does that do? :O
why do you have "10" on MINUTE ?

I just want to know what does it do, and what happens if i change the numbers.

Thanks :p
You have to change that to the time you want it to save each time. So if you want it to auto save every 1 minute, change the 10 minute to 1, etc.
You also have to change the nextTime+= 1000 * SECONDS;
 
Back
Top