Using GetPlayerDrunkLevel after SetPlayerDrunkLevel
#1

Hello,

Take a look at this code:

pawn Код:
if(!strcmp(cmdtext,"/test",true))
{
    new currentLevel = GetPlayerDrunkLevel(playerid),newLevel = currentLevel + 1000,afterLevel;
    SetPlayerDrunkLevel(playerid, newLevel);
    afterLevel = GetPlayerDrunkLevel(playerid);
    format(string,128,"Old level: %d, new level: %d, re-fetched: %d",currentLevel,newLevel,afterLevel);
    SendClientMessage(playerid,-1,string);
}
I went ingame and typed /test, and now see the results:

Код:
[10:56:24] Old level: 0, new level: 1000, re-fetched: 0
[10:56:28] Old level: 850, new level: 1850, re-fetched: 850
[10:56:29] Old level: 1848, new level: 2848, re-fetched: 1848
[10:56:29] Old level: 2828, new level: 3828, re-fetched: 2828
As you see it returns the old drunk level. I will create an easy workaround, but it's not the way it should be.

Another example; At some time I set the drunk level to 2000, then a timer to add +1000 each 30 seconds. Using GetPlayerDrunkLevel in the timer will return 0. I know it decreases, but not THAT hard

Jochem
Reply
#2

There's many issues with using Get(...) functions after Set(...) ones. It seems to be an 'issue' with the way they work (sync).

This also goes for Set/GetPlayerFacingAngle, I made a topic about it: https://sampforum.blast.hk/showthread.php?tid=348860

Every OnPlayerUpdate call causes the player's data (such as drunk level) to be sent to the server and stored for use in GetPlayerDrunkLevel, I guess. I always assumed that when you used Get...() functions it sent a request to the player to return the data, but perhaps not.

So basically, this is what is happening:

Player's drunk level is 0.
OnPlayerUpdate called, '0' is sent and stored in the server.
Between an update you set it to 5000 then GetPlayerDrunk level returns 0 because OnPlayerUpdate hasn't been called since.

If I understood the sync system correctly there, it should be fixable by SetPlayerDrunkLevel setting the stored variable instead of waiting for the PLAYER to sync it.

So yeah, fixable.
Reply
#3

A fix should be added in fixes.inc in my opinion. It's not hard to work around.

Only for drunk levels there is a problem as it lowers each second with your FPS.
Reply
#4

It's actually really easy to 'fix' these problems with the script, but you have to use OnPlayerUpdate (CPU) and many arrays (memory). IMO this should be fixed internally.
Reply
#5

This is NOT a bug, it simply takes TIME for a player to sync the new value - until then, the old value is returned.

This is part of sa-mp's design and not a bug.
Reply
#6

Quote:
Originally Posted by JernejL
Посмотреть сообщение
This is NOT a bug, it simply takes TIME for a player to sync the new value - until then, the old value is returned.

This is part of sa-mp's design and not a bug.
I've noticed this, even with your tutorial, that, when you use GetPlayerDrunkLevel to get the FPS it goes to gigantic values over 1000, and in 0.3b and 0.3e I never experienced that, so something has changed
Reply
#7

So? have you actually checked out the wiki page on GetPlayerDrunkLevel? the value can be anything..
Reply
#8

GetPlayerDrunkLevel won't update right after you change the player's drunk level, it will after the first tick of OnPlayerUpdate since you changed the drunk level, at all I don't understand why do you want to get the player's drunklevel right after you change it, you can use the same value you used to change it instead of calling GetPlayerDrunkLevel.
Reply
#9

Well it's not just that, another script may use GetPlayerDrunkLevel before OnPlayerUpdate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)