OnPlayerStateChange in vehicle bug
If you are in vehicle (PLAYER_STATE_DRIVER OR PLAYER_STATE_PASSANGER), and you die, OnPlayerStateChange will output oldstate PLAYER_STATE_SPAWNED, and newstate PLAYER_STATE_NONE, than PLAYER_STATE_ONFOOT, so if i try make per player timer when they sit as driver, and die, timer won't kill when newstate != PLAYER_STATE_DRIVER
In samp this work correctly, when player die in vehicle, oldstate first is PLAYER_STATE_DRIVER, than others
code example
static speedoMeter[MAX_PLAYERS] = {-1, ...};
OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_DRIVER)
{
KillTimer(speedoMeter[playerid]);
}
if(newstate == PLAYER_STATE_DRIVER)
{
speedoMeter[playerid] = SetTimerEx(...);
}
}
So, sit in vehicle as driver, kill yourself (SetPlayerHealth(...)), or explode in gas station, then see that oldstate will not be PLAYER_STATE_DRIVER, though you was PLAYER_STATE_DRIVER
Couldn't reproduce this with latest nightly
@Hual I just download latest build and i can confirm i can reproduce it, not fixed. So, when you are in vehicle (PLAYER_STATE_DRIVER), do SetPlayerHealth to 0.0 to kill yourself, print oldstate and newstate in public OnPlayerStateChange, and you will see that oldstate isnt PLAYER_STATE_VEHICLE, but 17:01:27 > "oldstate: PLAYER_STATE_NONE, newstate: PLAYER_STATE_SPAWNED", 17:01:27 > "oldstate: PLAYER_STATE_SPAWNED, newstate: PLAYER_STATE_ONFOOT"
Are you using spectating functions too? The only place I can see where player state is set to NONE is in setSpectating()
@Hual When i use spectating functions all is alright. If you want i can share you screen on discord and reproduce it live
@PazzOnee do you have any calls to TogglePlayerSpectating in OnPlayerDeath?
@Hual I just download latest build and i can confirm i can reproduce it, not fixed.
Was it the one from releases section or a build from github actions (like this)?
UPD: Anyway, both variants works good for me, I also tried to test this and can't face the issue. Maybe try to test this on a blank gamemode (without anything else, but only OnPlayerStateChange logging) and see if this still occurs.
It test it on blank mode, it would be bug in weapon-config i think, but when i use samp-server it's okay, i will close this
It is weapon-config.inc bug, in WC_PlayerDeathRespawn callback, there are TogglePlayerSpectating to true, then to false, when you replace it with SpawnPlayer, then will be fixed, so i will open issue at weapon config include
Oh, this probably used there to immediate spawn a player without additional death delay. SpawnPlayer does this too, but it can cause a double spawn (the one which is still pending + the next which was just set by the function). So, fixing it in wc by changing TogglePlayerSpectating to anything else like SpawnPlayer could lead to new issues.
Okay, we found where is problem, so i will close this issue, and open it at weapon config
It's an open.mp issue, should be reopened