Skip to content

Conversation

@NexiusTailer
Copy link
Contributor

@NexiusTailer NexiusTailer commented Jan 11, 2026

Problem

When we do such code on the current version of open.mp server:

ForceClassSelection(playerid);
SetPlayerHealth(playerid, 0.0);

// must be applied in a single tick, at once
TogglePlayerSpectating(playerid, true);
TogglePlayerSpectating(playerid, false);

Player who entered class selection most likely won't be able to select a class and spawn: all buttons won't be clickable like something blocks OnPlayerRequestClass and OnPlayerRequestSpawn callbacks on the server even before they reach your pawn script. This method is actually used to spawn player immediately here, in weapon-config, so it's not something marginal.


The root cause is that TogglePlayerSpectating cannot manage to properly update the player's state when toggling on and off quickly, because the client doesn't have enough time to send at least one spectating sync packet back to the server (and thus the server won't update his state to spectating a bit further).

The validation checks inside class selection events fully rely on player state being always accurate, and thus reject any attempt to change classes or to spawn with selected class, if the player considered to be spawned (by being in one of such player states: onfoot, driver, passenger or spawned).

Finally, when our code above is executed, player who was in onfoot player state will still be with onfoot state for the server when he enters class selection, because toggling spectator mode was done too fast, without player state change to the spectating state which considered non-spawned one, and thus lets the validation checks inside class selection events to be passed.


Solution

We might be forcefully set player state to some non-spawned when TogglePlayerSpectating is called with toggle parameter set to false, but messing with player states is hacky and it previously lead to even more problems.

Instead, this PR implements transitional flag when the player is being left from spectating (which is true until spawn). This period between leaving spectator and actual spawn is now considered a valid case to process class selection events, even if validations inside them see that this player has inappropriate player state.

@NexiusTailer NexiusTailer marked this pull request as draft January 12, 2026 10:33
@ksenonadv
Copy link
Member

Fixed in #1187

@ksenonadv ksenonadv closed this Jan 12, 2026
@NexiusTailer NexiusTailer deleted the master branch January 15, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants