Skip to content

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.

vehicles.setHasSiren(id: number, hasSiren: boolean): Promise<ActionResult>
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.

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.
gamemodes/my-mode.ts
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));