Player stats sometimes not saving.
#1

pawn Code:
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.
Reply
#2

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:
Quote:

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

I do every minute. No errors. What if the player times out? Does it save? thanks for reply.
Reply
#4

When player timeout, it won't be saved
Reply
#5

how do I combat this?
Reply
#6

Quote:
Originally Posted by Shinja
View Post
When player timeout, it won't be saved
Why wouldn't it save? OnPlayerDisconnect is called when a player times out.
Reply
#7

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

I save them every 5 minutes to be safe.
Should I do this under a player timer or global timer?

Having issues.
Reply
#9

You can do the both, it's up to you
Reply
#10

Quote:
Originally Posted by amirm3hdi
View Post
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]".
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)