Esc to clear, Enter to open the best match, click an export to open it in its page
Vehicles

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

GetVehicleId(entity)CLIENT#

A car's vehicleId from the cache, or nil for a car WHIP has never seen (ResolveVehicle registers it).

ParamTypeDescription
entitynumber|tableEntity handle, or { entity = veh }
Returns: number|nil
GetVehicleEntity(vehicleId)CLIENT#

The 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.

ParamTypeDescription
vehicleIdnumber|tableA vehicle reference
Returns: number|nil: entity handle
ResolveVehicle(entity)CLIENTWAITS#

A car's vehicleId, registering it as a session vehicle first if WHIP doesn't know it, which costs a server round trip.

ParamTypeDescription
entitynumber|tableEntity handle, or { entity = veh }
Returns: 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 held
local vehicleId, why = exports.whip_core:ResolveVehicle(ctx.entity)   -- in onSelect
if not vehicleId then return ctx.refuse(why) end
It waits. Use it in onSelect, never in canInteract, a label, a loop or frequent code.
GetNearbyVehicles(radius)CLIENT#

Every vehicle near the local player, closest first, from GetGamePool('CVehicle').

ParamTypeDescription
radiusnumber?Metres; default 25, max 100
Returns: table[]: { entity, plate, vehicleId, distance, model }
HasVehicleKey(vehicleId)CLIENT#

Whether the local player has a key for a vehicle, from the cache. { plate = } finds a car that isn't streamed in here too.

ParamTypeDescription
vehicleIdnumber|tableA vehicle reference
Returns: bool
if 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.

GetVehicleProperties(vehicle)CLIENT#

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).

ParamTypeDescription
vehiclenumber|tableA vehicle reference
Returns: { 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 handle
SetVehicleProperties(vehicle, props)CLIENT#

Apply a look, unsaved: right for previews. Mods are networked, so everyone sees it; the car reverts when the server next pushes its appearance.

ParamTypeDescription
vehiclenumber|tableA vehicle reference
propstableAs GetVehicleProperties returns; absent fields are left alone
Returns: 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
SetVehicleExtras(vehicle, extras)CLIENT#

Switch a vehicle's extras (light bars, roof racks) and keep its damage. Unsaved; the server stores them with SetVehicleAppearance's extras.

ParamTypeDescription
vehiclenumber|tableA vehicle reference
extrastable{ [n] = true } on, false off, extras 1 to 14; missing ones are left alone
Returns: how many were switched
Use this, not SetVehicleExtra, which repairs the car (health, doors, tyres, fuel, dirt). Dents still can't be kept.
TakeVehicleControl(vehicle, opts)CLIENTWAITS#

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.

ParamTypeDescription
vehiclenumber|tableA vehicle reference
optstable?{ attempts = 3, wait = 500 }: tries, and milliseconds per try
Returns: 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

GetVehiclePoint(vehicle, action)CLIENT#

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.

ParamTypeDescription
vehiclenumber|tableA vehicle reference
actionstringThe point's name
Returns: { 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 player
SetVehiclePointRules(action, rules)CLIENT#

Define a point of your own (a charging port). WHIP's and other resources' points can't be taken; yours go when your resource stops.

ParamTypeDescription
actionstringYour point's name
rulestable{ default = { place, … }, bike = { … }, boat = { … } }, tried in order. A place: a bone name or list, 'entry', 'box', 'box:rear', 'box:front' or 'filler'
Returns: true, or false, why
exports.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)