Skip to content

playerViewEnded

Tells your gamemode that a player’s camera view from camera.setFixed or camera.attach ended, or that they stopped spectating. By then the player has their own camera back, and a spectator is back in their vehicle seat or on foot.

server.on("playerViewEnded", ({ player, mode, target, endReason }) => void)
Name Type Description
player PlayerSnapshot The player whose view ended.
mode "camera" | "spectating" A camera view, or spectating.
target CameraTarget | SpectateTarget | null What they watched; null for a fixed camera. A player who has left is their ID.
endReason PlayerViewEndReason Why it ended.
gamemodes/my-mode.ts
import { chat, server } from "nativemp";
server.on("playerViewEnded", ({ player, mode, endReason }) => {
if (mode === "spectating" && endReason !== "script") {
chat.sendServerMessage(`You stopped spectating (${endReason}).`, player);
}
});