GetPlayerMoney Bug
#1

Sometimes, on a system that I built with a timer to 5000ms (1000ms or so as it was before that) GetPlayerMoney function returns zero (0) even if I have money, and then return back to the real value.

Sorry for my bad English.
Reply
#2

Give us the code please.
Reply
#3

Put this in the code where you use it

pawn Код:
GivePlayerMoney(playerid, 100);
new CurrentMoney = GetPlayerMoney(playerid);
printf("%d", CurrentMoney);
Just to debug it!
Reply
#4

pawn Код:
for(new i; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        printf("*** GetPlayerMoney %d Moneys %d", GetPlayerMoney(i),pL[i][Moneys]);
           
        if(GetPlayerMoney(i) > pL[i][Moneys])
        {
            ResetPlayerMoney(i);
            GivePlayerMoney(i, pL[i][Moneys]);
        }
        else
        {
            pL[i][Moneys] = GetPlayerMoney(i);  
        }
    }
}
CONSOLE:

[14:10:47] *** GetPlayerMoney 1500 Moneys 1500
[14:10:52] *** GetPlayerMoney 1500 Moneys 1500
[14:10:57] *** GetPlayerMoney 1500 Moneys 1500
[14:11:02] *** GetPlayerMoney 0 Moneys 1500
[14:11:08] *** GetPlayerMoney 1500 Moneys 0

[14:11:14] *** GetPlayerMoney 0 Moneys 0
[14:11:19] *** GetPlayerMoney 0 Moneys 0
[14:11:25] *** GetPlayerMoney 0 Moneys 0
[14:11:30] *** GetPlayerMoney 0 Moneys 0


pawn Код:
GivePlayerMoneyEx(playerid, cashs)
{
    pL[playerid][Moneys] += cashs;
    GivePlayerMoney(playerid, cashs);
}
Reply
#5

pawn Код:
GivePlayerMoneyEx(playerid, cashs)
{
    pL[playerid][Moneys] += cashs;
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid, pL[playerid][Moneys]);
}
Reply
#6

Quote:
Originally Posted by Knappen
Посмотреть сообщение
pawn Код:
GivePlayerMoneyEx(playerid, cashs)
{
    pL[playerid][Moneys] += cashs;
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid, pL[playerid][Moneys]);
}
The problem isn't in the set value of money but on the value the function GetPlayerMoney return. Look the console... suddenly the return value is zero and then back to 1500, without my money is changed.

sorry for my bad english.
Reply
#7

This is likely due to sync. I'll try my best to explain.

When you send GivePlayerMoney, it sends a packet of information to the client to set their money to whatever you set it to. During the time that the instruction is being sent (such as directly after, in your case), the money will still be the old one because the 'change' instruction hasn't been recieved by the client at that time.

When you use GetPlayerMoney, it doesn't send a packet to the client requesting the money, but instead the money is saved on the server (synced) every time OnPlayerUpdate is called, hence the new money amount will only be returned by GetPlayerMoney after (or on) the next OnPlayerUpdate call.

The same applies for many different functions such as health, armour and weapons, and was a pain in the ass when scripting an anti-cheat, as I had no idea.

Hopefully that sums it up for you. Here's a great topic: https://sampforum.blast.hk/showthread.php?tid=184118
Reply
#8

I found the problem on localhost (ping 15), a chance to happen in "common hosting" (ping 80 +) is higher or lower?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)