12.11.2018, 22:56
Now, instead of saving player data only when player disconnects, why not save it whenever the player DIES.
I mean, in most servers, player\'s data is significantly changed when they die (maybe not for RP servers). So when the player dies, save their data.
Moreover, for security reasons its better to have a interval check between two deaths, so if a Cheater spams your OnPlayerDeath for fake kills/deaths, your server won\'t crash from MySQL query overload!
gettime() would do it for you. Before saving data, check if last save was not very recently and then forward.
But the above case is only for data which is significantly changed, other data like "AdminLevel" doesn\'t require to be updated in OnPlayerDeath. You should update AdminLevel whenever its changed in script, i.e. Update query for AdminLevel in your /setadmin command.
The whole idea about using Timer to save stats is nonsense.
I mean, in most servers, player\'s data is significantly changed when they die (maybe not for RP servers). So when the player dies, save their data.
pawn Code:
public OnPlayerDeath(playerid, killerid, reason) {
// add kills and change variables\' data
// save data in the end
mysql_tquery(...);
return 1;
}
Moreover, for security reasons its better to have a interval check between two deaths, so if a Cheater spams your OnPlayerDeath for fake kills/deaths, your server won\'t crash from MySQL query overload!
gettime() would do it for you. Before saving data, check if last save was not very recently and then forward.
pawn Code:
new lastSaveTimestamp[MAX_PLAYERS];
public OnPlayerDeath(playerid, killerid, reason) {
new currentTimestamp = gettime();
if (currentTimestamp - lastSaveTimestamp[playerid] >= 600) { // 10 minutes interval
// save data if last update was 10 minutes atleast
mysql_tquery(...);
lastSaveTimestamp[playerid] = currentTimestamp; // update player\'s last save time to current timestamp
}
return 1;
}
But the above case is only for data which is significantly changed, other data like "AdminLevel" doesn\'t require to be updated in OnPlayerDeath. You should update AdminLevel whenever its changed in script, i.e. Update query for AdminLevel in your /setadmin command.
The whole idea about using Timer to save stats is nonsense.