open.mp icon indicating copy to clipboard operation
open.mp copied to clipboard

OnPlayerStateChange in vehicle bug

Open PazzOnee opened this issue 2 years ago • 11 comments

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

PazzOnee avatar Feb 27 '23 01:02 PazzOnee

Couldn't reproduce this with latest nightly

Hual avatar Jun 23 '23 12:06 Hual

@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"

PazzOnee avatar Jun 23 '23 15:06 PazzOnee

Are you using spectating functions too? The only place I can see where player state is set to NONE is in setSpectating()

Hual avatar Jun 23 '23 15:06 Hual

@Hual When i use spectating functions all is alright. If you want i can share you screen on discord and reproduce it live

PazzOnee avatar Jun 23 '23 16:06 PazzOnee

@PazzOnee do you have any calls to TogglePlayerSpectating in OnPlayerDeath?

Hual avatar Jun 26 '23 09:06 Hual

@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.

NexiusTailer avatar Jun 26 '23 16:06 NexiusTailer

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

PazzOnee avatar Jun 29 '23 00:06 PazzOnee

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

PazzOnee avatar Jun 29 '23 00:06 PazzOnee

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.

NexiusTailer avatar Jun 29 '23 08:06 NexiusTailer

Okay, we found where is problem, so i will close this issue, and open it at weapon config

PazzOnee avatar Jun 29 '23 11:06 PazzOnee

It's an open.mp issue, should be reopened

Hual avatar Jun 30 '23 06:06 Hual