PDA

View Full Version : Player stats sometimes not saving.


Dokins
25/09/2016, 08:27 PM
stock SavePlayerData(playerid)
{
if(LoggedIn[playerid] == 1 && playerid != INVALID_PLAYER_ID)
{
new Float: x, Float: y, Float: z;
GetPlayerPos(playerid, x, y, z);
GetPlayerArmour(playerid, PlayerArmour[playerid]);
new query[600];
format(query, sizeof(query), "UPDATE `accounts` SET LastX = %f, LastY = %f, LastZ = %f, LastVW = %d, LastInt = %d WHERE id = %d", x, y, z,GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid), PlayerSQLID[playerid]);
mysql_tquery(dbHandle, query, "", "");
format(query, sizeof(query), "UPDATE `accounts` SET `TotalTime` = %d, `Money` = %d, ThiefCooldown = %d,HotwireCooldown = %d, `SGrip` = %d, `MGrip` = %d, `LGrip` = %d,`SFrame` = %d, `MFrame` = %d, `LFrame` = %d,`SBarrel` = %d, `MBarrel` = %d, `LBarrel` = %d, `Jail` = %d, `AdminJail` = %d, FishBait = %d, `Armour` = %f, LastLogin = %d, JobCooldown = %d, PizzaCooldown = %d, WepTime = %d, DrugTime = %d, MFrags = %d, LastPayday = %d, SweepCooldown = %d WHERE `id` = %d LIMIT 1"
, TotalTime[playerid], PlayerMoney[playerid], ThiefCooldown[playerid],HotwireCooldown[playerid],SGrip[playerid], MGrip[playerid], LGrip[playerid],SFrame[playerid],MFrame[playerid],LFrame[playerid], SBarrel[playerid],MBarrel[playerid],LBarrel[playerid], Jail[playerid], AdminJail[playerid],FishBait[playerid],PlayerArmour[playerid],LastLogin[playerid], JobCooldown[playerid], PizzaCooldown[playerid],WepTime[playerid], DrugTime[playerid], MFrags[playerid], LastPayday[playerid],
SweepCooldown[playerid], PlayerSQLID[playerid]);
mysql_tquery(dbHandle, query,"", "");
for(new w = 0; w < 13; w++)
{
if(PlayerWeapons[playerid][w] > 0)
{
MySQL_SetInteger(PlayerWeapons[playerid][w], "WepAmmo", WepAmmo[PlayerWeapons[playerid][w]], "weapons");
}
}
}

//Simple mysql query.
return 1;
}

It mostly seems to be total time played that gets lost.

Could anyone assist? I save on disconnect and every 5 minutes.

PrO.GameR
25/09/2016, 08:42 PM
Is it possible that you don't update TotalTime[playerid] itself? because if it's "mostly" that, I don't know, if it's the second update you send, I suggest you merge them together
Simply instead of second update:
UPDATE `accounts` SET
put a %s and format the query into the query again.

Again tho mysql queries don't get lost nor do they change value, either your server is crashing while performing that, or you have a mysql error.

Dokins
25/09/2016, 08:55 PM
I do every minute. No errors. What if the player times out? Does it save? thanks for reply.

Shinja
25/09/2016, 09:15 PM
When player timeout, it won't be saved

Dokins
25/09/2016, 09:22 PM
how do I combat this?

SickAttack
25/09/2016, 09:32 PM
When player timeout, it won't be saved

Why wouldn't it save? OnPlayerDisconnect is called when a player times out.

amirm3hdi
25/09/2016, 09:45 PM
No, OnPlayerDisconnect doesn't get called untill SMAP finds out that player is timed out,
When a player times out, it freezes into the state that player was, server will find out about it, maybe 30 sec to 1 min later.

Saving players stat every 1 min is a bad idea, make that every 10 minutes and also save when user is disconnecting.
You should not be worried about players timing out, they will be saved eventually after disconnecting.

Also try debugging your code, debug variables and check out mysql errors (set error reporting).

I hope that was helpful.

Dokins
25/09/2016, 10:40 PM
I save them every 5 minutes to be safe.
Should I do this under a player timer or global timer?

Having issues.

Shinja
25/09/2016, 11:11 PM
You can do the both, it's up to you

SickAttack
25/09/2016, 11:15 PM
No, OnPlayerDisconnect doesn't get called untill SMAP finds out that player is timed out,
When a player times out, it freezes into the state that player was, server will find out about it, maybe 30 sec to 1 min later.

Saving players stat every 1 min is a bad idea, make that every 10 minutes and also save when user is disconnecting.
You should not be worried about players timing out, they will be saved eventually after disconnecting.

Also try debugging your code, debug variables and check out mysql errors (set error reporting).

I hope that was helpful.

That's complete non-sense, it doesn't take that long. Even if it did take that long, variables holding player statistics should/are only reset at the end of the player's disconnection, or after stats were saved.

The player is still connected during that "freeze" state. There should be no issue there.

--------------------------------------------------

Change "playerid != INVALID_PLAYER_ID" for "IsPlayerConnected(playerid)" in "stock SavePlayerData(playerid)".

I don't see how you're getting the value of "TotalTime[playerid]", use timestamp(s) in combination with that variable if you aren't already.

Kill player-related timers on disconnect. Use a global timer. You could also change "LoggedIn[playerid] == 1" for "LoggedIn[playerid]".

Dokins
26/09/2016, 02:48 PM
Total time is on a global timer (1 minute)