SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/09/2016, 08:27 PM   #1
Dokins
Banned
 
Join Date: Jun 2010
Posts: 1,648
Reputation: 53
Default Player stats sometimes not saving.

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.
Dokins is offline   Reply With Quote
Old 25/09/2016, 08:42 PM   #2
PrO.GameR
Gangsta
 
PrO.GameR's Avatar
 
Join Date: Oct 2012
Posts: 694
Reputation: 121
Default Re: Player stats sometimes not saving.

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.
__________________
Blueberry Prison Roleplay will be back soon!
Follow the forums for more information about opening day.

Forums
PrO.GameR is offline   Reply With Quote
Old 25/09/2016, 08:55 PM   #3
Dokins
Banned
 
Join Date: Jun 2010
Posts: 1,648
Reputation: 53
Default Re: Player stats sometimes not saving.

I do every minute. No errors. What if the player times out? Does it save? thanks for reply.
Dokins is offline   Reply With Quote
Old 25/09/2016, 09:15 PM   #4
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 972
Reputation: 107
Default Re: Player stats sometimes not saving.

When player timeout, it won't be saved
Shinja is offline   Reply With Quote
Old 25/09/2016, 09:22 PM   #5
Dokins
Banned
 
Join Date: Jun 2010
Posts: 1,648
Reputation: 53
Default Re: Player stats sometimes not saving.

how do I combat this?
Dokins is offline   Reply With Quote
Old 25/09/2016, 09:32 PM   #6
SickAttack
High-roller
 
Join Date: Dec 2013
Posts: 4,761
Reputation: 754
Default Re: Player stats sometimes not saving.

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.
SickAttack is offline   Reply With Quote
Old 25/09/2016, 09:45 PM   #7
amirm3hdi
Banned
 
Join Date: Apr 2015
Location: Brain
Posts: 270
Reputation: 14
Default Re: Player stats sometimes not saving.

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.
amirm3hdi is offline   Reply With Quote
Old 25/09/2016, 10:40 PM   #8
Dokins
Banned
 
Join Date: Jun 2010
Posts: 1,648
Reputation: 53
Default Re: Player stats sometimes not saving.

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

Having issues.
Dokins is offline   Reply With Quote
Old 25/09/2016, 11:11 PM   #9
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 972
Reputation: 107
Default Re: Player stats sometimes not saving.

You can do the both, it's up to you
Shinja is offline   Reply With Quote
Old 25/09/2016, 11:15 PM   #10
SickAttack
High-roller
 
Join Date: Dec 2013
Posts: 4,761
Reputation: 754
Default Re: Player stats sometimes not saving.

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]".
SickAttack is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Player stats not saving on host flamur2012 Server Support 8 06/06/2015 10:13 AM
Player stats not saving GwENiko Scripting Help 12 01/11/2014 09:25 PM
need help for saving player stats MrTinder Scripting Help 5 09/05/2013 09:22 AM
Saving Player Stats On GMX Scripter12345 Scripting Help 33 26/04/2012 11:56 PM
Saving player stats? Torran Help Archive 20 11/03/2010 10:33 AM


All times are GMT. The time now is 04:56 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.