ai-sirens for developers
Client exports, state bags and the event of ai-sirens.
ai-sirens has client exports only. They do the same as the driver's keys. vehicle is optional: without it, the vehicle the player sits in is used. A vehicle that is not an emergency vehicle (class 18 and in the panel's model list) is ignored.
Changes (tone, siren) are asked from the server, which accepts them only from the driver. Call the setters on the driver's client. Lights (SetLights, ToggleLights) are the game's own siren light state on that client.
Lua calls them as exports['ai-sirens']:Name(...). They are not typed in @aicore-fivem/shared: in TypeScript use callExport("ai-sirens", "Name", ...args) from @aicore-fivem/lib/client.
Client exports
SetLights
Turns the emergency lights on or off (and the ONX lightbar's, if any).
Side: Client · Waits: no
SetLights(vehicle: number | undefined, on: boolean): booleanlocal ok = exports['ai-sirens']:SetLights(vehicle, true)Parameters
Prop
Type
Returns
true when the vehicle is an emergency vehicle and the lights were set. false otherwise.
ToggleLights
Flips the emergency lights.
Side: Client · Waits: no
ToggleLights(vehicle?: number): booleanlocal ok = exports['ai-sirens']:ToggleLights()Returns
true when the vehicle is an emergency vehicle. false otherwise.
SetSirenTone
Sets the main siren tone. A tone above 0 turns the lights on first.
Side: Client · Waits: no (the server answers later; the local value shows at once)
SetSirenTone(vehicle: number | undefined, tone: 0 | 1 | 2 | 3): booleanlocal ok = exports['ai-sirens']:SetSirenTone(nil, 2)Parameters
Prop
Type
Returns
true when the request was sent. false for a vehicle that is not an emergency vehicle or a tone outside 0-3. A request the server does not confirm within 1.5 seconds counts as refused and the old tone shows again.
Example
import { callExport } from "@aicore-fivem/lib/client";
// A pursuit script: tone 2 when the chase starts.
export function startPursuit(): void {
if (!callExport("ai-sirens", "SetSirenTone", undefined, 2)) return;
console.log("pursuit tone on");
}ToggleSiren
Stops the siren if it runs, otherwise starts it on tone 1 (turning the lights on first).
Side: Client · Waits: no
ToggleSiren(vehicle?: number): booleanlocal ok = exports['ai-sirens']:ToggleSiren()Returns
true when the request was sent, false for a vehicle that is not an emergency vehicle.
CycleTone
The next tone: 1, 2, 3, then 1 again. With the siren off it starts tone 1 (turning the lights on first).
Side: Client · Waits: no
CycleTone(vehicle?: number): booleanlocal ok = exports['ai-sirens']:CycleTone()Returns
true when the request was sent, false for a vehicle that is not an emergency vehicle.
GetSirenTone
The current main siren tone.
Side: Client · Waits: no
GetSirenTone(vehicle?: number): numberlocal tone = exports['ai-sirens']:GetSirenTone(vehicle)Returns
0 (off) to 3. Also 0 for a vehicle that is not an emergency vehicle.
AreLightsOn
Whether the emergency lights are on.
Side: Client · Waits: no
AreLightsOn(vehicle?: number): booleanlocal on = exports['ai-sirens']:AreLightsOn(vehicle)Returns
true when on. false when off or not an emergency vehicle.
GetAirManuState
The airhorn and manual siren state.
Side: Client · Waits: no
GetAirManuState(vehicle?: number): numberlocal state = exports['ai-sirens']:GetAirManuState(vehicle)Returns
0 off, 1 airhorn, 2 manual siren, 3 both. 0 for a vehicle that is not an emergency vehicle.
GetLightbarModel
The ONX lightbar model attached to the vehicle.
Side: Client · Waits: no
GetLightbarModel(vehicle?: number): string | nulllocal model = exports['ai-sirens']:GetLightbarModel(vehicle)Returns
The model name ("onx_pol_lbar_mdn1a"), or null when the vehicle has none or is not an emergency vehicle.
State bags
Written only by the server after its checks. Read them on any client to know a vehicle's siren state.
| Bag | Type | Meaning |
|---|---|---|
siren:lx | number | Main siren tone: 0 off, 1-3 a tone. |
siren:manu | number | Airhorn / manual siren: 0 off, 1 horn, 2 manual, 3 both. |
siren:lightbar | string | The ONX lightbar model attached (absent: none). |
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local tone = Entity(vehicle).state['siren:lx'] or 0Events
| Name | Kind | What it does |
|---|---|---|
ai-sirens:setState | client to server | (netId, key, value): the driver asks for a tone or airhorn change, or the network owner sets the lightbar model. The server accepts only listed emergency models, a value above 0 only from the driver, a reset to 0 from a player within 10 m while the driver seat is empty, and only lightbar models the panel lists. Internal: use the exports. |