playerSnapshotUpdated
Tells your gamemode when the server accepts new state for a player: position, health, weapon and the rest. Updates are combined to at most ten per second per player; lifecycle and vehicle changes come at once.
A spectator or freecam player sends no state of their own, so they get none, with two opt-in exceptions: a
view started with listenAtView keeps updating their listenPosition (at the
same rate), and players.setListenPosition updates it once. Their
position stays where they started watching.
Renamed in 0.28 from playerStateUpdate; see renamed names.
Signature
Section titled “Signature”server.on("playerSnapshotUpdated", ({ player }) => void)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
player |
PlayerSnapshot |
The updated snapshot. |
Example
Section titled “Example”Keep players out of a square of the map.
import { players, server } from "nativemp";
server.on("playerSnapshotUpdated", async ({ player }) => { const [x, y] = player.position ?? [0, 0]; if (x > 1000 && x < 1200 && y > 1000 && y < 1200) { await players.setPosition(player, [1100, 950, 20]); }});Related
Section titled “Related”playerStateChanged: only when the state changesplayers.getById: read a snapshot any time