Skip to content

How decisions work

Your gamemode hears from the server in two ways, both through server.on:

  • An event tells you that something already happened, for instance playerEnteredVehicle. What your handler returns is ignored.
  • A decision asks you before something happens, for instance playerEnterVehicleRequest, and waits for your answer. Every decision’s name ends in Request.

When a decision has an event that goes with it, the decision comes first: playerEnterVehicleRequest, then, if you allowed it, playerEnteredVehicle. Default behaviour that has no decision, such as the global chat, is decided with its own function: chat.onPlayerMessage.

Return your answer from the handler. Most decisions take false to refuse and true, or nothing, to allow; a few take an object or a word (see the table). The handler may be async and await a database or a web request: the server waits for the answer, and the rest of the server goes on meanwhile.

gamemodes/my-mode.ts
import { server } from "nativemp";
server.on("playerEnterVehicleRequest", async ({ player, vehicleId }) => {
const owner = await vehicleOwners.get(vehicleId); // your own lookup
return owner === undefined || owner === player.name;
});

Each decision has a deadline: half a second for gameplay, five seconds to join or spawn. You cannot ask for more time. Without an answer by then, the decision’s default applies, and an answer that comes later is ignored.

“No answer” is any of these:

  • no handler is registered;
  • the handler throws, or its promise rejects;
  • the answer comes after the deadline;
  • your gamemode is restarting or reloading;
  • too many decisions are waiting for an answer already.

The default is what the game would do without you, in most cases: allow. Where allowing could hurt a server, the default is to refuse: an unanswered playerConnectRequest keeps the player out, and one more helicopter or police car than the game’s limit needs your true. When too many decisions are waiting, gameplay decisions take the safe side; each decision’s page says which.

You can register several handlers for one decision; they run in the order you registered them. For most decisions the first false decides: the handlers after it are not asked. The table says how each decision combines its handlers.

Between the question and your answer the world goes on: the player may have left, or got into another vehicle. The server checks the request again when your answer comes, and drops it when it no longer holds. So “allowed” means “may go ahead”, not “will happen”. Listen to the event that follows, such as playerEnteredVehicle, to know that it did.

Decision Answer Deadline No answer Several handlers
playerConnectRequest ConnectDecision or false 5 s refused the first refusal decides
playerSpawnRequest SpawnDecision or false 5 s spawned at the server’s spawn point (or held, with spawnTimeout: "hold") the first allow or hold decides
virtualWorldChangeRequest boolean, or a virtual world to go to instead 0.5 s allowed the first false or number decides
playerEnterVehicleRequest boolean 0.5 s allowed the first false decides
playerCarjackRequest boolean 0.5 s allowed the first false decides
playerCheatSuspicionRequest CheatAction 0.5 s kicked the first action decides; an error moves on to the next handler
playerTakePickupRequest boolean 0.5 s allowed the first false decides
playerStartInteractionRequest boolean 0.5 s allowed the first false decides
playerOpenParachuteRequest boolean 0.5 s allowed the first false decides
playerWantedLevelChangeRequest boolean 0.5 s allowed the first false decides
playerCameraChangeRequest boolean or ViewDecision<CameraView> 0.5 s allowed the first false or deny decides; the last override is used
playerSpectateRequest boolean or ViewDecision<SpectateTarget> 0.5 s allowed (a spectator whose target left stops watching) the first false or deny decides; the last override is used
playerCommitObjectEditRequest boolean 0.5 s discarded on timeout, accepted with no handlers the first false decides
playerMarkerVisibilityRequest boolean 0.5 s shown, asked again 5 s later any false hides
vehicleMarkerAppearanceRequest boolean or VehicleMarkerAppearance 0.5 s the default, asked again 5 s later any false hides; objects apply in order
vehicleRadioStationChangeRequest boolean 0.5 s allowed the first false decides
vehicleSirenChangeRequest boolean 0.5 s allowed the first false decides
vehicleControlChangeRequest boolean 0.5 s allowed the first false decides
vehicleAppearanceChangeRequest boolean 0.5 s kept the first false decides
vehicleRespawnRequest boolean 0.5 s put back the first false decides
carGeneratorSpawnRequest CarGeneratorSpawnDecision 0.5 s the story’s vehicle the first false or { vehicleModel } decides
venuePanicRequest boolean 0.5 s allowed the first false decides
gateOpenRequest boolean 0.5 s allowed the first false decides
crimeReportForwardRequest boolean 0.5 s allowed the first false decides; an error moves on to the next handler
policeUnitDispatchRequest boolean 0.5 s allowed the first false decides
emergencyServiceDispatchRequest boolean 0.5 s allowed the first false decides
helicopterCapExceedRequest boolean 0.5 s refused the first false decides; otherwise any true allows
policeCarCapExceedRequest boolean 0.5 s refused the first false decides; otherwise any true allows
policeChaseTargetSwitchRequest boolean 0.5 s allowed the first false decides
sharedFireWaterInteractionRequest boolean 0.5 s allowed the first false decides
streetFoodVendorSpawnRequest boolean 0.5 s allowed the first false decides
streetFoodVendorAttackRequest boolean 0.5 s allowed the first false decides
chat.onPlayerMessage false keeps the line from everyone’s chat 1 s broadcast the first false decides