Client vehicles API
Client calls for finding cars, checking keys, previewing a look, taking network control, and the points and prompts on a car. All are instant cache reads except ResolveVehicle and TakeVehicleControl, which wait.
Finding cars
A car's vehicleId from the cache, or nil for a car WHIP has never seen (ResolveVehicle registers it).
| Param | Type | Description |
|---|---|---|
| entity | number|table | Entity handle, or { entity = veh } |
number|nilThe entity handle for a vehicleId, for GTA natives, or nil when the car isn't streamed in nearby. WHIP's own exports take the id itself.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
number|nil: entity handleA car's vehicleId, registering it as a session vehicle first if WHIP doesn't know it, which costs a server round trip.
| Param | Type | Description |
|---|---|---|
| entity | number|table | Entity handle, or { entity = veh } |
number, or false, why, a sentence for the player: not there or not a vehicle, no plate, the plate belongs to an owned car elsewhere, or too many street cars heldlocal vehicleId, why = exports.whip_core:ResolveVehicle(ctx.entity) -- in onSelect
if not vehicleId then return ctx.refuse(why) end
onSelect, never in canInteract, a label, a loop or frequent code.Every vehicle near the local player, closest first, from GetGamePool('CVehicle').
| Param | Type | Description |
|---|---|---|
| radius | number? | Metres; default 25, max 100 |
table[]: { entity, plate, vehicleId, distance, model }Whether the local player has a key for a vehicle, from the cache. { plate = } finds a car that isn't streamed in here too.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
boolif exports.whip_core:HasVehicleKey({ plate = plate }) then ... end
Look and network control
These change the entity now, unsaved; the server stores a look with SetVehicleAppearance (see Appearance). Each needs network control first, or the natives silently do nothing.
How a vehicle looks now, in the shape SetVehicleProperties takes. Toggle mods 18, 20 and 22 come back as turbo, smokeEnabled and xenon, not in mods (slots 0–49).
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicle reference |
{ model, plate, plateIndex, color1, color2, customColor1, customColor2, pearlescent, wheelColor, mods, wheelType, turbo, smokeEnabled, xenon, tyreSmoke, neonColor, neonEnabled, windowTint, livery, extras, dirtLevel, headlightColor, interiorColor, dashboardColor }; empty for an invalid handleApply a look, unsaved: right for previews. Mods are networked, so everyone sees it; the car reverts when the server next pushes its appearance.
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicle reference |
| props | table | As GetVehicleProperties returns; absent fields are left alone |
true, or false, why: no such car here, or a bare entity handle (unlike QBCore and ox_lib, pass { entity = veh })local before = exports.whip_core:GetVehicleProperties({ entity = veh })
exports.whip_core:SetVehicleProperties({ entity = veh }, { livery = 3 }) -- preview
exports.whip_core:SetVehicleProperties({ entity = veh }, before) -- undo
Switch a vehicle's extras (light bars, roof racks) and keep its damage. Unsaved; the server stores them with SetVehicleAppearance's extras.
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicle reference |
| extras | table | { [n] = true } on, false off, extras 1 to 14; missing ones are left alone |
SetVehicleExtra, which repairs the car (health, doors, tyres, fuel, dirt). Dents still can't be kept.Take network control of a vehicle: ask, wait, retry. It waits, so call it from a thread or handler through Whip.core. Refused while another player drives, since the car would rubber-band: make the change on the driver's client.
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicle reference |
| opts | table? | { attempts = 3, wait = 500 }: tries, and milliseconds per try |
true, or false, why: 'no such vehicle', 'another player is driving it', 'control was not granted'if Whip.core:TakeVehicleControl({ entity = veh }) then
Whip.core:SetVehicleExtras({ entity = veh }, { [1] = true, [2] = false })
end
Points on a car
Where a named point on a vehicle is, on the side nearest the player: 'fuel' (the filler), 'engine', 'storage' (boot), 'mount' (bike), 'board' (boat), or yours. A car's filler is its petrol cap, else above a rear wheel, on the side in Config.VehicleFillers, else its side tank's, else one picked per model.
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicle reference |
| action | string | The point's name |
{ x, y, z, heading, side, fixed }, or nil if the model has none. side: 'left', 'right', 'front', 'rear'; heading faces out of it; fixed: the side doesn't follow the playerDefine a point of your own (a charging port). WHIP's and other resources' points can't be taken; yours go when your resource stops.
| Param | Type | Description |
|---|---|---|
| action | string | Your point's name |
| rules | table | { default = { place, … }, bike = { … }, boat = { … } }, tried in order. A place: a bone name or list, 'entry', 'box', 'box:rear', 'box:front' or 'filler' |
true, or false, whyexports.whip_core:SetVehiclePointRules('charge', { default = { 'petrolcap', 'box:front' } })
Adding options to a vehicle part
Add a choice to a part's prompt with AddAction and at = { vehiclePart = ... }; ctx.entity is the car. The parts are 'hood', 'trunk', 'door_dside_f', 'door_pside_f', 'door_dside_r', 'door_pside_r', and the one prompt of a 'bike', 'bicycle' or 'boat'. A 'hood' option shows only while the bonnet is open or torn off: put engine work there.
Whip.register(function()
for _, door in ipairs({ 'door_dside_f', 'door_pside_f', 'door_dside_r', 'door_pside_r' }) do
exports.whip_core:AddAction({
id = 'jerrycan:' .. door, -- one action per part
at = { vehiclePart = door },
icon = 'fuel', label = 'Refuel (jerry can)',
canInteract = function(ctx) return JerryCanInHand() and not TankFull(ctx.entity) end,
onSelect = function(ctx)
TriggerServerEvent('myfuel:pourCan', NetworkGetNetworkIdFromEntity(ctx.entity))
end,
})
end
end)