saving data using a timer
#1

Removed
Reply
#2

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.
Reply
#3

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);
Reply
#4

If I'm not wrong loop is the statemets (for, while, do-while) that just a repeat timer.
Reply
#5

Removed
Reply
#6

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.
Reply
#7

Removed
Reply
#8

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;
}
Reply
#9

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
Reply
#10

Removed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)