Skip to content

server.on

Registers a handler for an event or a decision. You can register several handlers for the same name; they run in the order you registered them. Events and decisions are explained in how decisions work.

server.on(eventName: string, handler: (payload, context: HandlerContext) => unknown): void
Name Type Description
eventName string The event or decision; see the tables below.
handler (payload, context: HandlerContext) => unknown Gets the payload, which you cannot change, and a HandlerContext. The second argument is optional.

Nothing.

gamemodes/my-mode.ts
import { server } from "nativemp";
server.on("playerDied", ({ player, position }) => {
server.log(`${player.name} died at ${position.map((n) => n.toFixed(0)).join(", ")}`);
});

Something already happened. The return value is ignored.

Event When
playerConnected A player joined.
playerDisconnected A player left.
playerSpawned A player spawned, the first time or after dying.
playerDied A player died.
playerArrested A cop arrested a player.
playerHitEntity A player hit another player, their car or an NPC.
playerAimedAtPed A player aims at another player or an NPC.
playerHealthOrArmourDecreased A player lost health or armour.
playerStateChanged A player’s state changed, for instance from on foot to driving.
playerSnapshotUpdated The server has a newer snapshot of a player.
playerEnteredVehicle A player got into a vehicle.
playerExitedVehicle A player got out of a vehicle.
playerChangedVehicleSeat A player moved to another seat.
playerWantedLevelChanged A player’s wanted level changed.
playerTookPickup A player took one of your pickups.
playerEnteredRaceCheckpoint A player reached their race checkpoint.
playerLeftRaceCheckpoint A player left their race checkpoint.
playerAudioZoneChanged A player came into another of the game’s audio zones.
playerInteriorChanged A player went into or out of an interior.
playerVirtualWorldChanged A player is in another virtual world now.
playerEnteredCheckpoint A player came into one of your checkpoints.
playerLeftCheckpoint A player went out of one of your checkpoints.
playerEnteredArea A player came into one of your areas.
playerLeftArea A player went out of one of your areas.
playerParachuteOpened A player’s parachute opened.
playerParachuteStartedGliding A player’s parachute started gliding.
playerParachuteLanded A player’s parachute landed.
playerParachuteEnded A player’s parachute descent ended.
crimeReportForwarded A crime report reached the offender’s game.
molotovImpactReported A player’s game saw a Molotov hit.
sharedFireStarted A fire started.
sharedFireUpdated A fire got weaker, stronger or moved.
sharedFireStopped A fire went out.
vehicleHornStarted A vehicle started honking.
vehicleSirenChanged A vehicle’s siren went on or off.
vehicleStateAvailable A vehicle’s shared state became available or reset.
vehicleStateRemoved A vehicle left the shared world.
vehicleControlChanged A vehicle control changed.
vehicleDamaged A vehicle’s health or damage changed.
vehicleSnapshotsUpdated Vehicles were created, removed, entered, damaged or moved.
vehicleAppearanceChanged A vehicle’s colors, paintjob, components or plate changed.
interactionStarted A player started using a vending machine, food cart, gym machine or interactive object.
interactionEnded A player stopped using one.
gymExerciseModeChanged A player on a gym machine changed the intensity.
gymExerciseCompleted A player finished a gym session.
streetFoodVendorAttackStarted A street food vendor started attacking a player.
scriptObjectCreated One of your objects was placed.
scriptObjectUpdated One of your objects was edited or finished moving.
playerObjectEditEnded A player’s object edit session ended.
scriptObjectDestroyed One of your objects was removed.
scriptMapEditCreated Your gamemode hid stock objects.
scriptMapEditRestored Your gamemode removed a map edit.
scriptMarkerCreated One of your text labels, map icons, checkpoints or areas was created.
scriptMarkerUpdated One of them changed.
scriptMarkerDestroyed One of them was removed.
playerViewEnded A player’s camera view or spectating ended.
worldStateChanged The clock, the weather, a world rule or the marker settings changed.
uiViewBecameReady An HTML view is ready with its first complete frame.
uiViewClosed An HTML view ended.
uiViewFailed An HTML view failed.
uiEventReceived An HTML page sent a named message.

The server waits for your answer before the action goes ahead. How decisions work has what each one returns and how several handlers combine.

Decision Asks Deadline No answer in time
playerConnectRequest May this player join? 5 s refused
playerSpawnRequest Where does this player spawn, or are they held? 5 s spawned at the server’s spawn point
virtualWorldChangeRequest May this player or vehicle go to this virtual world, or to another? 0.5 s allowed
playerEnterVehicleRequest May this player get into this vehicle? 0.5 s allowed
playerCarjackRequest May this player pull another player out of the driver’s seat? 0.5 s allowed
playerCheatSuspicionRequest Kick, ban or keep a player the server suspects of cheating? 0.5 s kicked
playerTakePickupRequest May this player take this pickup? 0.5 s allowed
playerStartInteractionRequest May this player use this vending machine, food cart, gym machine or object? 0.5 s allowed
playerOpenParachuteRequest May this player open their parachute? 0.5 s allowed
playerWantedLevelChangeRequest May this player’s wanted level change? 0.5 s allowed
playerCameraChangeRequest May this player’s camera be set to this view, or to another? 0.5 s allowed
playerSpectateRequest May this player spectate this target, or another? 0.5 s allowed
playerCommitObjectEditRequest May this player save an object edit? 0.5 s discarded
playerMarkerVisibilityRequest May this viewer see this player’s marker? 0.5 s shown
vehicleMarkerAppearanceRequest How does this empty vehicle show on the radar? 0.5 s the default
vehicleRadioStationChangeRequest May this occupant change the radio station? 0.5 s allowed
vehicleSirenChangeRequest May this driver switch the siren? 0.5 s allowed
vehicleControlChangeRequest May this player’s vehicle control change? 0.5 s allowed
vehicleAppearanceChangeRequest Is this player’s mod shop or paint shop change kept? 0.5 s kept
vehicleRespawnRequest Does this vehicle of yours go back to where you created it? 0.5 s put back
carGeneratorSpawnRequest Does this story parked vehicle appear, and as which vehicle? 0.5 s the story’s vehicle
venuePanicRequest May this bar, casino, strip club or shop panic at this player? 0.5 s allowed
gateOpenRequest May this army base’s or airport’s gate open for this player? 0.5 s allowed
crimeReportForwardRequest May this crime report reach the offender? 0.5 s allowed
policeUnitDispatchRequest May this police unit come? 0.5 s allowed
emergencyServiceDispatchRequest May this ambulance or fire truck come? 0.5 s allowed
helicopterCapExceedRequest May one more helicopter come than the limit? 0.5 s refused
policeCarCapExceedRequest May one more police car come than the limit? 0.5 s refused
policeChaseTargetSwitchRequest May this police unit switch to a nearer wanted player? 0.5 s allowed
sharedFireWaterInteractionRequest May this player’s water weaken another player’s fire? 0.5 s allowed
streetFoodVendorSpawnRequest May a vendor appear at this food cart or hotdog van? 0.5 s allowed
streetFoodVendorAttackRequest May this vendor attack the player who knocked over their cart? 0.5 s allowed

Chat lines are decided by chat.onPlayerMessage, not server.on.