vehicles.setHasSiren
Gives a car or bike the game’s siren sound, for every player. Its driver switches it on and off by tapping the horn key
(H by default), and holds the horn for the fast tone, as in a police car. Each switch asks
vehicleSirenChangeRequest first, so your gamemode decides who may use
it; with no handler, the driver may. false takes an added siren away again and switches it off.
Signature
Section titled “Signature”vehicles.setHasSiren(id: number, hasSiren: boolean): Promise<ActionResult>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id |
number |
The vehicle’s ID (not its model). |
hasSiren |
boolean |
true to add a siren, false to take an added one away. |
Returns
Section titled “Returns”A promise of an ActionResult: applied once the server has set it (the players’ games
follow), rejected with a code, or timeout after five seconds without an answer.
| Code | Meaning |
|---|---|
invalid-siren |
id is not a number, or hasSiren is not a boolean. |
invalid-vehicle-id |
id is 0 or above 4294967295. |
vehicle-not-found |
No such vehicle. |
Example
Section titled “Example”import { chat, commands, server, vehicles } from "nativemp";
commands.register("addsiren", async (player) => { if (player.vehicleId === null) return chat.sendServerMessage("Get in a vehicle first.", player); const result = await vehicles.setHasSiren(player.vehicleId, true); if (result.status === "applied") chat.sendServerMessage("Tap H to switch your siren.", player);});
// Only these players may switch a siren.const officers = new Set(["Alice", "Bob"]);server.on("vehicleSirenChangeRequest", ({ player }) => officers.has(player.name));Related
Section titled “Related”vehicles.setSiren: switch the siren on or off yourselfvehicles.getSirenState: read it,hasAddedSirenamong itvehicleSirenChangeRequest: decide whether the driver may switch itvehicles.soundHorn: sound the horn