Right Callback for Updating Money?
#1

I'm making a TDM script with MySql. I have Money as player's stat and its stored in MySql table. I've scripted a Stats saving function which is called under OnPlayerDisconnect. Its alright when player leaves the game. But when player timesout, OnPlayerDisconnect isnt called and stats arent updated. I dont want to call that function in OnPlayerUpdate 'cause its just a single stat 'Money' and it doesnt needs to be updated so often and i believe it would be buggy and would consume more processing. So is there any other callback or any other way i can save stats after some time or when player timesout?

Any help would be appreciated.
Reply
#2

Use OnPlayerDisconnect, it works fine.
Код:
This forum requires that you wait 120 seconds between posts. Please try again in 67 seconds.
Damnit.
Reply
#3

OnPlayerDisconnect is suppose to be called when player is timedout (if correct), so I'm not sure why it's not working.

Otherwise, you could always create a timer for x amount of seconds to save the money.
Reply
#4

Quote:
Originally Posted by Kindred
Посмотреть сообщение
OnPlayerDisconnect is suppose to be called when player is timedout (if correct), so I'm not sure why it's not working.

Otherwise, you could always create a timer for x amount of seconds to save the money.
Right, as much as i know OnPlayerDisconnect is called when
Player Leaves-Crashes/Timeouts and kicked/banned.
Reply
#5

Just made sure, and it is suppose to call when timedout:

Quote:
Originally Posted by SA-MP Wiki, OnPlayerDisconnect
Reasons:

0 Timed out
1 Left normally (/q or ESC menu and quit)
2 Kicked or banned
Reply
#6

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerMoney(playerid) != yourMoneyVariable[playerid])
        return OnPlayerMoneyChange(playerid, GetPlayerMoney(playerid), yourMoneyVariable[playerid]), 1;

    return 1;
}

forward OnPlayerMoneyChange(playerid, newmoney, oldmoney);
public OnPlayerMoneyChange(playerid, newmoney, oldmoney)
{
    // Do stuff
    return 1;
}
That should work fine. You can also use it for anticheat and stuff.
Reply
#7

Yea..i tried it again and it works. OnPlayerDisconnect is called when player is timedout. Thanks everyone who helped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)