playerStateChanged
Tells your gamemode when a player’s state changes, for instance from on foot to driving.
Renamed in 0.28 from playerStateChange; see renamed names.
Signature
Section titled “Signature”server.on("playerStateChanged", ({ player, fromState, toState }) => void)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
player |
PlayerSnapshot |
The player. |
fromState |
PlayerState |
The state before. |
toState |
PlayerState |
The state now. |
Example
Section titled “Example”import { server } from "nativemp";
server.on("playerStateChanged", ({ player, fromState, toState }) => { server.log(`${player.name}: ${fromState} -> ${toState}`);});States
Section titled “States”| State | Meaning |
|---|---|
held |
Connected but not spawned, waiting for a spawn decision or players.spawn. |
spawning |
A spawn is under way. |
onFoot |
Alive, on foot. |
driver |
Driving a vehicle. |
passenger |
A passenger in a vehicle. |
dead |
Dead, waiting to respawn. A playerDied event fired. |
busted |
Arrested, waiting to respawn. Health is kept and no playerDied event fires. |
Related
Section titled “Related”playerSnapshotUpdated: every snapshot updatePlayerSnapshot:toStatein the snapshot