Wanted and emergency gameplay
GTA:SA’s own police, ambulances, fire trucks and fires run in the players’ games and every player sees the same ones.
Your gamemode decides about them with decisions, hears about them with events, and changes them with a few functions.
Turn the wanted and emergency world rules on first.
Decide
Section titled “Decide”Each of these is a decision with a half-second deadline. Return false to refuse,
true or nothing to allow; the first false stops the handlers after it.
| Decision | Decides | No answer in time |
|---|---|---|
crimeReportForwardRequest |
Whether a crime another player’s game saw reaches the offender | allowed |
playerWantedLevelChangeRequest |
Whether a player’s wanted level changes | allowed |
policeUnitDispatchRequest |
Whether a police unit comes | allowed |
emergencyServiceDispatchRequest |
Whether an ambulance or fire truck comes | allowed |
helicopterCapExceedRequest |
Whether one more helicopter may come than the limit | refused |
policeCarCapExceedRequest |
Whether one more police car may come than the limit | refused |
policeChaseTargetSwitchRequest |
Whether a police unit switches to a nearer wanted player | allowed |
sharedFireWaterInteractionRequest |
Whether a player’s water weakens another player’s fire | allowed |
When too many decisions are waiting, the server takes the safe side: the wanted level stays, the report or water is
dropped, the unit stays away and the chase stays as it is. Changes from players.setWantedLevel are still allowed.
import { server, world } from "nativemp";
await world.setRule("wanted", true);await world.setRule("emergency", true);server.on("playerWantedLevelChangeRequest", ({ requestOrigin, toWantedLevel }) => requestOrigin === "script" || toWantedLevel <= 3);server.on("emergencyServiceDispatchRequest", ({ service }) => service === "fire");server.on("policeUnitDispatchRequest", ({ unit }) => unit.model !== 497); // no police helicoptersPolice the game would send wait, unseen, until the wanted level is settled. An allowed exception to a limit still goes
through policeUnitDispatchRequest. None of these decisions can make the game send a unit it would not send.
Events come after the fact; their return value is ignored.
| Event | Tells |
|---|---|
crimeReportForwarded |
A crime report reached the offender |
playerWantedLevelChanged |
A wanted level changed |
sharedFireStarted |
A fire started |
sharedFireUpdated |
A fire changed, at most ten times a second |
sharedFireStopped |
A fire went out |
molotovImpactReported |
A player’s game saw a Molotov hit |
vehicleSirenChanged |
A siren went on or off |
A crime or Molotov report comes from a player’s game: an observation, not proof. A crime the offender’s own game sees, or water on a fire in the player’s own game, does not go through the decisions above. An ambulance or fire truck comes without saying which patient or fire it is for.
Change
Section titled “Change”| Function | Does |
|---|---|
fires.listAll |
Lists the fires burning now |
fires.getById |
Reads one fire |
fires.extinguish |
Puts a fire out |
vehicles.getSirenState |
Reads a vehicle’s siren |
vehicles.setSiren |
Switches a siren and keeps it so |
vehicles.setHasSiren |
Gives any car or bike a siren its driver switches with the horn key |
players.setWantedLevel |
Sets a wanted level, through playerWantedLevelChangeRequest |
They return an ActionResult. applied means the server made the change; the players’
games follow.
After a reload
Section titled “After a reload”When your gamemode loads, read the current fires with fires.listAll and sirens with vehicles.getSirenState. Earlier
starts, reports and changes are not sent again, so you do not give rewards twice. Keep fire IDs as strings: they can be
larger than a JavaScript number holds exactly.
import { fires, server } from "nativemp";
const burning = new Map(fires.listAll().map((fire) => [fire.id, fire]));server.on("sharedFireStarted", ({ fire }) => { burning.set(fire.id, fire); });server.on("sharedFireUpdated", ({ fire }) => { burning.set(fire.id, fire); });server.on("sharedFireStopped", ({ fire }) => { burning.delete(fire.id); });