vehicles.soundHorn
Sounds a vehicle’s horn for durationMs, for every player near it, as if its driver held the horn key. It works on an
empty vehicle too, for a car alarm for example. Peds around it react to it as they do to any horn. Calling it again
replaces the time left; 0 stops a horn this function started.
Signature
Section titled “Signature”vehicles.soundHorn(id: number, durationMs: number): Promise<ActionResult>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id |
number |
The vehicle’s ID (not its model). |
durationMs |
number |
How long, in milliseconds: a whole number from 0 to 60000. |
Returns
Section titled “Returns”A promise of an ActionResult: applied once the server has started it, rejected with
a code, or timeout after five seconds without an answer.
| Code | Meaning |
|---|---|
invalid-duration |
durationMs is not a whole number from 0 to 60000. |
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";
const alarmedCarId = 42; // the ID vehicles.create gave your parked car
commands.register("honk", async (player) => { if (player.vehicleId === null) return chat.sendServerMessage("Get in a vehicle first.", player); await vehicles.soundHorn(player.vehicleId, 1500);});
// A car alarm: the horn goes off for 10 seconds when someone hits this parked car.server.on("vehicleDamaged", ({ vehicleId }) => { if (vehicleId === alarmedCarId) void vehicles.soundHorn(vehicleId, 10000);});Related
Section titled “Related”vehicleHornStarted: a vehicle’s horn startedvehicles.setHasSiren: give a vehicle a siren