Saving players stats on changes or in timer? [MySQL]
#16

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.

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


Messages In This Thread
Saving players stats on changes or in timer? [MySQL] - by GospodinX - 21.10.2018, 14:28
Re: Saving players stats on changes or in timer? [MySQL] - by KinderClans - 22.10.2018, 15:04
Re: Saving players stats on changes or in timer? [MySQL] - by Dignity - 22.10.2018, 16:15
Re: Saving players stats on changes or in timer? [MySQL] - by DaniceMcHarley - 22.10.2018, 16:17
Re: Saving players stats on changes or in timer? [MySQL] - by Garr - 30.10.2018, 18:07
Re: Saving players stats on changes or in timer? [MySQL] - by BlackBank - 31.10.2018, 00:10
Re: Saving players stats on changes or in timer? [MySQL] - by TheToretto - 31.10.2018, 00:13
Re: Saving players stats on changes or in timer? [MySQL] - by BlackBank - 31.10.2018, 00:18
Re: Saving players stats on changes or in timer? [MySQL] - by TheToretto - 31.10.2018, 00:35
Re: Saving players stats on changes or in timer? [MySQL] - by BlackBank - 31.10.2018, 00:39
Re: Saving players stats on changes or in timer? [MySQL] - by TheToretto - 31.10.2018, 09:26
Re: Saving players stats on changes or in timer? [MySQL] - by Ermanhaut - 02.11.2018, 10:47
Re: Saving players stats on changes or in timer? [MySQL] - by TheToretto - 02.11.2018, 10:55
Re: Saving players stats on changes or in timer? [MySQL] - by AmigaBlizzard - 02.11.2018, 11:32
Re: Saving players stats on changes or in timer? [MySQL] - by IdonTmiss - 07.11.2018, 11:48
Re: Saving players stats on changes or in timer? [MySQL] - by Gammix - 12.11.2018, 22:56
Re: Saving players stats on changes or in timer? [MySQL] - by Alteh - 13.11.2018, 19:01
Re: Saving players stats on changes or in timer? [MySQL] - by DRIFT_HUNTER - 16.11.2018, 01:21

Forum Jump:


Users browsing this thread: 2 Guest(s)