PDA

View Full Version : [ASK] Autosave player stats ?


VenomMancer
09/07/2015, 06:18 AM
What is best one/work perfectly ?

I put

// Under player loged in
pInfo[playerid][SaveTimer] = SetTimerEx("SavePlayerX",5000*60,true,"d",playerid);

function SavePlayerX(playerid)
{
if(GPVI(playerid,"Spawned") == 1)
{
new query[550];
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Money`='%d', `TotalScore`='%d', `PT`='%d' WHERE `ID`='%d'",GetPlayerMoneyX(playerid),GetPlayerScore(playerid ), pInfo[playerid][PTScore], pInfo[playerid][ID]);
mysql_pquery(mysql, query, "", "");
//printf("%s",query);
}
return 1;
}

Or with globaltimer ?
Like this:

public OnGameModeInit()
{
SetTimer("ServerBackup",5000*60,true);
return 1;
}

public ServerBackup()
{
printf("**DEBUG : Server backup!");
foreach(Player,i)
{
if(pInfo[i][Login] == 1)
{
SavePlayer(i);
}
}

/*for(new s = 1; s < groupscount; s++)
{
SaveG(s);
}*/

//SCMTA(ColInfo,"**INFO : Semua data base di server telah di save (ServerBackup) !");
return 1;
}

#Sorryformybadenglish

rockhopper
09/07/2015, 07:26 AM
I think the timer will work , I do not know much about MYSQL but what I did on my previous scripts which had Y_INI was I made a Function called AutoSave(playerid) in which I placed all my saving vars and placed it in OnPlayerUpdate . I do not know if you can do that with MYSQL as it puts data into a table etc , but with INI it works and is very useful as it saves every time .

VenomMancer
10/07/2015, 12:59 PM
This my save function

function SavePlayerX(playerid)
{
if(GPVI(playerid,"Spawned") == 1)
{
new query[2010];
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET \
`Money`=%d,\
`Cash`=%d,\
`TotalScore`=%d,\
`DuelScore`=%d,\
`MostScore`=%d,\
`Kills`=%d,\
`Rob`=%d,\
`Race`=%d,\
`Mb`=%d,\
`Lms`=%d,\
`PT`=%d,\
`Deaths`=%d,\
`Fish`=%d,\
`Groupid`=%d,\
`GroupLevel`=%d WHERE `ID`=%d",
GetPlayerMoneyX(playerid),
pInfo[playerid][VgCash],
GetPlayerScore(playerid),
pInfo[playerid][DuelScore],
pInfo[playerid][MostScore],
pInfo[playerid][Kills],
pInfo[playerid][RobScore],
pInfo[playerid][RaceScore],
pInfo[playerid][MbScore],
pInfo[playerid][LmsScore],
pInfo[playerid][PTScore],
pInfo[playerid][Deaths],
pInfo[playerid][pFish],
pInfo[playerid][gID],
pInfo[playerid][gLevel],
pInfo[playerid][ID]);
mysql_pquery(mysql, query, "", "");
}
return 1;
}

I make every 5 minutes player's stats will save