saving data using a timer -
Fernado Samuel - 27.03.2013
Removed
Re: saving data using a timer -
Private200 - 27.03.2013
Basically, it's going to be something like this:
pawn Код:
public OnPlayerSpawn(playerid)
{
SetTimerEx("Savedata", 180000, true, "i", playerid);
return 1;
}
forward Savedata(playerid);
public Savedata(playerid)
{
SavePlayerData(playerid);
return 1;
}
I think this shall work fine.
EDIT: If you're having any problem please post below.
Re: saving data using a timer -
Joshman543 - 28.03.2013
Make sure you set the timer to loop.
pawn Код:
public Savedata()
{
SavePlayerData(playerid);
SetTimerEx("Savedata", 120000, false, "i", playerid);
return 1;
}
or
SetTimerEx("Savedata", 120000, true, "i", playerid);
Re: saving data using a timer -
TheArcher - 28.03.2013
If I'm not wrong loop is the statemets (for, while, do-while) that just a repeat timer.
Re: saving data using a timer -
Fernado Samuel - 28.03.2013
Removed
Re: saving data using a timer -
TheArcher - 28.03.2013
Add
pawn Код:
SetTimerEx("Savedata", 120000, true, "i", playerid);
I suggest you to create a global variable which hold that timer, you have to kill it when a player disconnects.
Re: saving data using a timer -
Fernado Samuel - 28.03.2013
Removed
Re: saving data using a timer - Patrick - 28.03.2013
Here you go i suggest the same as what TheArcher said. and i start to code it. im sure this is what he means
pawn Код:
new datasaving[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
datasaving[playerid] = SetTimerEx("Savedata", 120000, true, "i", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(datasaving[playerid]);
return 1;
}
forward Savedata(playerid);
public Savedata(playerid)
{
SavePlayerData(playerid);
return 1;
}
Re: saving data using a timer -
TheArcher - 28.03.2013
Top of your gamemode
pawn Код:
new savedatatimer[MAX_PLAYERS];
go to your login function and insert
pawn Код:
savedatatimer = SetTimerEx("Savedata", 120000, true, "i", playerid);
Now go to your save function which should be called "Savedata" (The function must be forward & public)
E.g
pawn Код:
forward Savedata(playerid);
public Savedata(playerid)
{
//your code
}
then when a player disconnects
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(savedatatimer[playerid]);
//Since the player has to save after sometime, make sure you re-call it after the kill timer.
Savedata(playerid);
return 1;
}
Edit: Damn I was too slow :P
@pds2012 Ok, why saving the data if the player hasn't logged for 10 minutes? It's going to save anyways by taking your method, plus your code tell that every 10 minutes have to save, and the player must stay 10 minutes to save their stats, what about they want to disconnect and save their data? Look a bit on my example :S
Re: saving data using a timer -
Fernado Samuel - 28.03.2013
Removed