ai-mechanic for developers
What ai-mechanic writes, its stash names, its usable item and its internal events.
ai-mechanic has no exports. Other scripts meet it through what it writes.
What it writes
- Tuning. A purchase writes the vehicle's
ai:propsstate bag (ai-core's client on the entity's owner applies it) and, for an owned vehicle, saves full props with ai-vehicles'SaveTuning. Plate, engine and body health and dirt are always taken from the entity, so a purchase never changes them. - Repairs save only engine and body health with ai-vehicles'
SaveVehicle. - Health, deformation and dirt can only be changed by the client that owns the entity, so the server sends
ai-mechanic:client:fixto that client.
Stashes
A job shop with a stash point registers a stash named mechanic_<shopId> (for example mechanic_lscustoms_burton) for the members of the shop's job, with the panel's slots and weight. Open it from your own script through the lib's inventory layer.
import { inventory } from "@aicore-fivem/lib/server";
// Count the repair kits in the Burton shop's stash.
const kits = inventory.getItemCount("mechanic_lscustoms_burton", "repairkit");Usable item
The panel's Kit item (repairkit by default) is registered as usable through ai-core's inventory layer. It brings a vehicle's engine up to the panel's Engine health after value and is used up only when the work finishes.
Events
All of ai-mechanic's events are internal (its client and its server); do not call them from other scripts.
| Name | Kind | What it does |
|---|---|---|
ai-mechanic:buy | client callback | (netId, change, base): buy one tuning change at the shop the player is in. |
ai-mechanic:repair | client callback | (netId): repair the vehicle at a shop. |
ai-mechanic:stash | client callback | (shopId): open a job shop's stash. |
ai-mechanic:wash | client callback | (netId): wash the vehicle at a car wash. |
ai-mechanic:bill | client callback | (target, amount, reason): an on-duty mechanic bills the nearest player. Limited to 3 per 10 seconds. |
ai-mechanic:client:fix | server to entity owner | (netId, engine): fix the body (engine null), set the engine health, or wash (-1). |