Skip to content

vehicles.setSiren

Switches a vehicle’s siren on or off for every player, and keeps it so: NPCs driving it do not switch it back. It holds until your gamemode switches it again, or someone in the vehicle switches it and vehicleSirenChangeRequest allows that. On a vehicle without a siren it sets the car alarm.

vehicles.setSiren(id: number, active: boolean): Promise<ActionResult>
Name Type Description
id number The vehicle’s ID (not its model).
active boolean true for on, false for off.

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 active 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, vehicles } from "nativemp";
commands.register("siren", async (player) => {
if (player.vehicleId === null) return chat.sendServerMessage("Get in a vehicle first.", player);
const current = vehicles.getSirenState(player.vehicleId);
const result = await vehicles.setSiren(player.vehicleId, !(current?.active ?? false));
if (result.status !== "applied") chat.sendServerMessage(result.status === "rejected" ? result.code : "timeout", player);
});