Vehicles API
Calls for a car's whole life: reading it, keys and locks, making, spawning and garaging cars, ownership, appearance and the catalog. Every call names the car with a vehicle reference. New to vehicles? Read Vehicles & Keys first.
Reading a car
A copy of everything the server knows about a vehicle, or nil if WHIP doesn't know it. Editing the copy changes nothing.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicleId or a vehicle reference: { plate = }, { netId = }, { entity = } |
| opts | table? | { occupants = true } adds who is sitting in it (slower: it checks every player) |
table|nillocal v = exports.whip_core:GetVehicle(vehicleId) -- or GetVehicle({ plate = 'ABC123' })
if not v then return false, 'No such vehicle' end
print(v.plate, v.model, v.owner.charId, v.state, v.locked)
Also on it: displayName and class (nil for a model the catalog lacks), vehType, owner.name, owner.online, garage, coords, heading, temp, session, secure, spawned, entity, netId, stats, data, properties, occupants when asked, and storage once the car's storage is loaded (storage.trunk = { slots, maxWeight, used }).
session = true means nobody owns it, rentals included. temp = true means a SpawnTempVehicle car only.Everything this client knows about a vehicle, or nil when it isn't streamed in here: live damage, colours, lock and engine state and every occupant, but not ownership or the garage. Takes a vehicleId or a vehicle reference.
table|nil: vehicleId, plate, mine, hasKey, entity, netId, model, modelHash, class (GTA's number), vehType, session, keyInIgnition (your car only), coords, heading, locked, engineOn, engineHealth, bodyHealth, colorPrimary, colorSecondary, occupants ({ seat, ped, isPlayer, serverId }), stats (a copy, defaults filled in), datalocal v = exports.whip_core:GetVehicle({ entity = GetVehiclePedIsIn(PlayerPedId(), false) })
Every vehicle a person owns, as full snapshots.
| Param | Type | Description |
|---|---|---|
| who | number|table | A person: a server id, or { charId = n }, online or not |
table[], or {}, why when who names nobodyIs this player driving this vehicle, or in it at all? Three natives and no copy, so prefer these to GetVehicle on a hot path.
| Param | Type | Description |
|---|---|---|
| source | number | Player server id |
| vehicleId | number | Vehicle ID |
booleanWhose game drives this car: the player at the wheel, or the one whose game plays a Director take (a recorded drive) on it. Ask before moving a car to another game to pull it: a take's game reclaims its car every two seconds.
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicleId, { netId } / { entity } (any networked car, WHIP's or not), or { plate } |
source, 'seat' | 'take', or nil when nobody drives it (parked, an NPC at the wheel)Which WHIP car this player sits in, from the server's view, not the client's word. An in-car item (nitrous, a part fitted from inside) starts here.
| Param | Type | Description |
|---|---|---|
| source | number | Player server id |
| opts | table? | { driver = true }: only the driver's seat counts |
vehicleId, or false, why, a sentence for the player: not in a vehicle, not driving, or a car WHIP doesn't look afterWhich seat this player is in, as the server sees it, in any vehicle including street cars. Seat -1 is the driver's, 0 the front passenger's, then the rear seats.
| Param | Type | Description |
|---|---|---|
| source | number | Player server id |
{ seat, driver, vehicleId, netId } (vehicleId is nil for a street car), or false, why: not in a vehicle, or still getting inPut a player, one of WHIP's NPCs or any ped into a seat, by its own door or at once. The game that runs them does it, and it is done when the server sees them in that seat. Each has one job: a new one ends the last. One of WHIP's NPCs gets in as its own Get In task, in place of the tasks it had.
| Param | Type | Description |
|---|---|---|
| who | number|table | A player's server id, { entity = ped }, { netId = n } or { npc = npcId } |
| vehicle | number|table | A vehicle reference, or { entity } / { netId } for any vehicle, a street car too |
| seat | number|string | -1 the driver's, 0 the front passenger's, then the rear; 'any' (the first free) or 'nearest' |
| opts | table? | how 'walk' (default) or 'warp'. ifTaken when someone sits there: 'refuse' (default), 'other' (another free seat), 'wait' (another, then over to its own once free) or 'jack' (pull them out; still there after jackMs, 10 s, they are put out unless held). moving 'wait' (default: no walk to a moving vehicle) or 'warp'. pace 'walk' or 'run'. elsewhere: already in it, move to another seat. warpAfter, timeoutMs (ms). force: off a hold first. onEnd(ok, why): called once when it is over |
true, jobId, or false, why (the seat is taken and ifTaken is 'refuse', they are held in another vehicle, no such vehicle)Whip.core:PutInSeat(source, { netId = taxiNet }, 'nearest', { ifTaken = 'other', onEnd = function(ok, why)
if not ok then Whip.core:NotifyPlayer(source, why, 'error') end
end })
Get a player or a ped out of whatever they sit in. A door against a wall: out at once after a while. Someone dead in their seat is laid beside their door. Someone held is only taken out with force, which lets go of every hold on them.
| Param | Type | Description |
|---|---|---|
| who | number|table | As PutInSeat's |
| opts | table? | how 'walk' (default) or 'now'. moving while the vehicle moves: 'wait' (default, until it stops), 'jump' (bail out) or 'now'. timeoutMs, force, onEnd(ok, why) |
true, jobId (true alone when they are not in a vehicle; onEnd is told at once), or false, whyKeep a player or a ped in the seat they sit in now until you call ReleaseSeatHold with the same reason, or your resource stops. Several reasons stack, from any resources. A player who presses the exit is told they can't get out right now. Moving them within the same vehicle takes the hold along. One of WHIP's NPCs is held by its own ride.
| Param | Type | Description |
|---|---|---|
| who | number|table | As PutInSeat's |
| reason | string | A short name of your own ('escort', 'ride') |
| opts | table? | Each on unless false: noExit (their exit is held), noJack (nobody can pull them out, and they never go through the windscreen), putBack (thrown out alive, they are put back in). tag: a run tag that releases it |
true, or false, why (not in a vehicle)Let go of the hold you put on them for reason. Another resource's holds on them stay.
true, or false, whyWhich seat a player or a ped sits in, as the server sees it, and whether something holds them there.
{ seat, driver, netId, vehicleId, held } (vehicleId is nil for a street car), or false, whyWho sits in a seat of a vehicle.
{ source, held } for a player, { npc, entity, held } for a ped (npc only for one of WHIP's NPCs), or false, 'Nobody sits there'Where a vehicle is right now, for a distance check or a blip. A garaged, despawned or lost car returns nil, so a near check fails. Last seen: GetVehicle(id).coords. A SecureEvent with a 'vehicle' param checks distance with near = { at = 'vehicle' }.
x, y, z, or nil if the car isn't in the worldIs this car blown up or sunk? A job's "car lost" check. The game running the car reports a sinking.
| Param | Type | Description |
|---|---|---|
| vehicle | number|table | A vehicle reference |
boolean: false for a car not out in the worldKeys and locks
A car's boot, glovebox and ignition are stores: address them as { kind = 'vehicle', id = vehicleId, sub = 'trunk' } (or 'glovebox', 'key'), where id may be a reference such as { plate = 'ABC 123' }. Use StoreRead, StoreCount, GetItemAt, StoreGive, StoreTake, StoreMove, OpenStore and CloseStore.
Lock or unlock a vehicle; saved, and whip_core:vehicle:lockChanged fires when the state changes. After a restart a car is as it was left, except one locked with its own key in the ignition, which is unlocked. A car leaving a garage is locked unless its own key is in the ignition.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
| locked | bool | true = locked |
bool, string|nilPut a vehicle_key for the car in a player's inventory. A player who already holds one is refused, unless opts.spare asks for another.
| Param | Type | Description |
|---|---|---|
| who | number|table | A person who is playing: server id, or { charId = n } |
| vehicleId | number | Vehicle ID |
| opts.spare | bool | true cuts a key even when they hold one, a second key to hand to someone |
true, or false, reason ('Already has a key for this vehicle', no room, not online)Change an owned car's locks. Every key of it cut so far stops fitting, wherever it is: someone's pockets (playing or not), a stash, a boot, its own ignition or the ground. Keys cut after fit, and the change lasts through a restart. A car running on an old key in its ignition stops. Old keys stay where they are as items that no longer open anything. A street car or a temporary one is refused; a temporary car takes secure = true instead.
-- The owner lost a key: new locks, and one new key for them
local ok, why = exports.whip_core:ChangeVehicleLocks(vehicleId)
if ok then exports.whip_core:GiveVehicleKey(source, vehicleId) end
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
true, or false, reason ('Only a car someone owns', 'Vehicle not found', a save that failed)How many keys fit the car now, wherever they are: every character's pockets (playing or not), every stash, every car's boot, glovebox and ignition, and the ground. A key inside another item (a bag), a resource's own stores and an open panel's slots aren't counted. Keys from before a ChangeVehicleLocks don't fit, so they aren't counted either.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
number, or false, reason (no such vehicle, the database couldn't be read)Take every key that fits this car from all of a player's containers: an impound confiscating keys.
| Param | Type | Description |
|---|---|---|
| who | number|table | A person who is playing: server id, or { charId = n } |
| vehicleId | number | Vehicle ID |
bool, string?: true if any key was removed, else false and why ('They have no key for that vehicle', 'Player not loaded', ...)Whether a person has a key for the vehicle in their pockets. A character who isn't playing is read from the database.
| Param | Type | Description |
|---|---|---|
| who | number|table | A person: a server id, or { charId = n } |
| vehicleId | number|table | A vehicle reference |
bool, string?: false and why when it couldn't ask (no such person, a bad reference)Every vehicle key in a person's pockets. A character who isn't playing is read from the database.
| Param | Type | Description |
|---|---|---|
| who | number|table | A person: a server id, or { charId = n } |
{ [vehicleId] = plateText }; {}, why for no such personEngine holds
Keep a car's engine off and tell the driver why: no fuel, a flat battery, an immobiliser. While any hold is on, the engine won't start and a running one stops; the car still rolls. A hold ends when you release it, your resource stops, or the car's id goes for good.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | Vehicle ID |
| key | string | Names your hold; the same key again replaces its reason |
| reason | string | Shown to the driver, 80 letters at most |
true, or false, why (no such vehicle)Release your hold key; with no key, all your holds on the car.
true when one went, false, why when you had noneWhether anything holds the car's engine off, whoever's hold it is.
nilMaking cars
Make a car owned by a player's character, the only way a resource mints one. With opts it also spawns the car and gives the key; if either fails the car is removed and you get false, reason. The owner comes from the player record, never from data.
| Param | Type | Description |
|---|---|---|
| source | number | The receiving player |
| data | table | { model, plate?, garage?, stats?, properties?, vehType?, trunkSlots?, trunkMaxWeight?, gloveboxSlots?, gloveboxMaxWeight? } |
| data.stats | table? | Starting values, { fuel = 100 }; one left out reads its registered default |
| data.garage | string? | An existing garage (GetNearestGarage, GetGarage); default the default garage |
| data.vehType | string? | Left out, the catalog's class picks bike, boat, heli or plane |
| opts | table? | { giveKey?, spawnAt? }: spawnAt (vector4, vector3 or { x, y, z, heading }) makes it out there; else it starts garaged. data.state = 'out' without it is refused; data.x/y/z aren't read |
number|false vehicleId, string|nil err, boolean|nil saved. Read the plate from GetVehicle(vehicleId).plate. Refused before any car is made: an occupied spawnAt ('Something is already parked in that spot'), or a builder in Isolate world ('Leave Isolate world first: cars come out in the shared world')local canOut, outWhy = exports.whip_core:CanBringOutVehicleFor(source)
if not canOut then return false, outWhy end
local receipt, err = exports.whip_core:ChargePlayer(source, 250000, { reason = 'Adder' })
if not receipt then return false, err end
local vehicleId, why = exports.whip_core:CreateOwnedVehicle(source, { model = 'adder' }, {
giveKey = true, spawnAt = vector4(-56.7, -1097.2, 26.4, 160.0),
})
if not vehicleId then exports.whip_core:RefundPlayer(receipt) return false, why end
false, err, true. saved means a database fault after the car was saved with the payment; it reaches their garage with its key once it reads back. Refund only on a plain false.Whether a car can be brought out for this player now. Ask before charging for a car with spawnAt: a builder in the Director's Isolate world is refused, since cars come out in the shared world.
| Param | Type | Description |
|---|---|---|
| source | number | The player the car is for |
boolean ok, string|nil whyWhether this game has a vehicle called model, add-ons included. Players' games report their lists at the character screen; the server saves them per platform and game build and drops a name unreported for 14 days. Spawning a missing model is refused with 'There is no vehicle called "x" in this game'.
| Param | Type | Description |
|---|---|---|
| model | string | The model name, like 'sultan' |
boolean|nil: nil before any game has reported, or for a model not on a full list (20,000 names); nothing is refused then, so test == falseA temporary car: a rental, a job van, a test drive. Nobody owns it and it's never saved, but it has an id, stats, data, a boot and keys. It's removed when your resource stops, despawnAfter runs out, nobody is near for ten minutes, or DespawnVehicle; its key goes too and whip_core:vehicle:released fires.
| Param | Type | Description |
|---|---|---|
| model | string | Vehicle model name |
| coords | vector4|vector3|table | Where; { x, y, z, heading } works too |
| opts.forSource | number? | Who it's for; they get a key unless giveKey = false |
| opts.despawnAfter | number? | Seconds until it's removed |
| opts.locked | boolean? | Spawns locked; false stands open |
| opts.keyInIgnition | boolean? | A key in the ignition, so anyone at the wheel can start it |
| opts.idleDespawn | boolean? | false: never removed for being left alone |
| opts.tag | string? | One of your tags: ReleaseTag removes the car and stops new spawns |
| opts.secure | boolean? | No lockpick or hack; only a key cut for this car works |
| opts.force | boolean? | Spawn on an occupied spot (GTA pushes things aside); else refused |
| opts.plate, opts.vehType | any | Normally left out |
number|false vehicleId, string|nil errlocal vehicleId, err = exports.whip_core:SpawnTempVehicle('blista', vector4(x, y, z, h), {
forSource = source, despawnAfter = 1800, -- a rental, gone in half an hour
})
despawnAfter removes the car even while driven. Warn the driver first.ClaimVehicle makes a car nobody owns (temp or street) an owned one: the end of a boosting job. The new car (new id, new plate unless given) keeps the model, look, fuel, boot and glovebox, and takes the old one's place with the driver still in it. A failure changes nothing; a model the catalog doesn't know is refused. SetVehiclePlate changes any car's plate; old keys still fit.
| Param | Type | Description |
|---|---|---|
| who | number|table | A person: server id, or { charId = n } |
| opts.plate | string? | Its new plate (8 characters at most, unused); default a new one |
| opts.here | boolean? | false: put away in their garage instead |
| opts.garage | string? | Its garage (default the default garage) |
| opts.key | boolean? | false: no key for them |
| opts.reason | string? | For their activity log |
| opts.leave | function? | function(metadata, item): true leaves that stack in the old car |
vehicleId (plus a note when it waits in its garage), or false, reason; fires whip_core:vehicle:claimed. SetVehiclePlate: true, or false, reason; fires whip_core:vehicle:plateChangedRegister a car already in the world as a session vehicle; a car WHIP knows returns its id. It never creates a car. On the client, ResolveVehicle does this from an entity.
| Param | Type | Description |
|---|---|---|
| ref | string|table | { entity = vehicle }, { netId = networkId }, or a plate (the first car wearing it). Prefer the car |
| ref.player | number? | When a player's action brings it in: counts against their street-car limit (20) |
number|false vehicleId, string|nil errGetVehicle({ plate = }).In and out of the world
Put a vehicle in the world; the server creates the entity. A car already out is moved, not cloned.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | The vehicle to place |
| coords | vector3|vector4? | Default its saved position; a vector4's w is the heading. Refused if occupied: 'Something is already parked in that spot', 'Someone is standing in that spot' |
number|false: the network ID, or false and an errorTake a vehicle out of the world into the garage it's filed under, even with somebody inside; storage is flushed first. It stays put away after a restart. A temp car is removed for good.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
| opts.garage | string? | Put it away in this garage instead (an impound). Only an owned car that is out: 'A street car cannot be put in a garage', 'A temporary car cannot be put in a garage', 'Vehicle is already stored', 'No such garage: …' |
| opts.refuseOccupied | boolean? | Refuse a car with somebody inside: 'Somebody is still in that vehicle'. On by default with a garage, off without one |
boolean ok, string|nil err: success if already out of the world; false, 'Vehicle is busy' mid-spawn, store or delete (retry shortly)released fires.Take a vehicle out of a garage: marks it out and locked. Then spawn it where you choose.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | Vehicle ID |
| garageKey | string? | Default: its own garage |
boolean ok, string|nil errlocal ok, err = exports.whip_core:RetrieveVehicle(vehicleId)
if ok then exports.whip_core:SpawnVehicle(vehicleId, vector4(x, y, z, heading)) end
Ownership
Sell a vehicle to another player. Writes the owner, re-syncs both players' lists and fires whip_core:vehicle:ownerChanged.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | Vehicle ID |
| newOwner | number|table | The buyer: an online server id, or { charId = n } for an online or offline character that exists and is not deleted |
| opts | table? | { giveKey, revokeOldKeys, expectedOwner }. Key options default true and only affect online players. expectedOwner is the expected current owner character id; a changed owner is refused |
boolean, string|nil: 'No such character', 'Vehicle ownership changed', 'Vehicle is in custody', 'Session vehicles have no owner' (use ClaimVehicle), 'Already owned by that character'revokeOldKeys only empties their pockets while online; keys in a stash, a boot, on the ground or in the ignition still work. With full pockets the buyer gets no key and this still returns true.Hold an owned vehicle for the calling resource. While that resource runs, retrieval, spawning, transfer and deletion are refused, including calls from the holder. Release the hold before those actions. Another running resource cannot replace or release it; a stopped resource's hold is ignored. The stored claim is not erased on stop and becomes active again if that resource restarts.
| Param | Type | Description |
|---|---|---|
| ref | number|table | Vehicle id or vehicle reference; session cars are refused |
| held | boolean | true to hold, false to release |
| expectedOwner | number? | Expected owner character id; refuses a changed owner |
boolean ok, string|nil reasonThis only changes the hold. It does not despawn, garage, lock or move a car. To impound, use CreateGarage for a lot without a position, then DespawnVehicle(vehicleId, { garage = 'impound', refuseOccupied = true }). Release any hold before RetrieveVehicle and SpawnVehicle.
Destroy an owned car for good, with its boot, glovebox, ignition and entity, in one transaction. Items are logged as lost; fires whip_core:vehicle:deleted. Any resource may call it, so check who may first.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | Vehicle ID |
boolean, string|nilDeleteVehicle and DeleteEntity.Appearance
Properties are GTA's look on an entity, set on the client (SetVehicleProperties). Appearance is the look WHIP stores for a vehicleId, on the server. A shop holds the car, previews with properties, saves what was paid for with SetVehicleAppearance, strips the rest with RestoreVehicleAppearance, then releases the hold.
Change and store how a vehicle looks. Props merge over the current look, one level into mods, so setting mod 11 keeps mod 23. Performance mods are allowed; plate and model are never written.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | Vehicle ID |
| props | table | Fields to apply ({} for none) |
| opts | table? | data = { key = value }, clearData = { 'key' }: your vehicle data, in the same write |
true, or false, why with nothing changed. A session car (street, rental) keeps the look only while it existsexports.whip_core:SetVehicleAppearance(vehicleId, { mods = { ['23'] = 4 }, color1 = 27 },
{ data = { myStance = { height = -0.05 } } })
Push the stored look back onto the car for everyone: the undo for a client's preview.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
boolean, string|nilMark a car as being previewed, so WHIP doesn't report or log the preview. If your resource stops while holding it, WHIP restores the stored look.
| Param | Type | Description |
|---|---|---|
| vehicleId | number | Vehicle ID |
| held | boolean | true to hold, false to release |
true, or false, reason: another resource holds it, or the hold isn't yours. Releasing an unheld car is trueCatalog and pictures
The vehicle catalog, keyed by model: 930 cars from server/vehicle_catalog_list.lua, plus packs' cars from RegisterVehicles. A car has a picture when a media pack, or WHIP's CDN, has its img/vehicles/<model>.webp.
{ [model] = { model, displayName, class, hasImage, image, inGame } }: image is a URL for your NUI or false; don't sell inGame == falseAdd a car pack's cars to the catalog while the pack runs. The list is the whole list: a car left out later goes, and all go when the pack stops. A model WHIP lists already keeps its name and class and takes your picture. List pictures in your files { }.
| Param | Type | Description |
|---|---|---|
| list | table[] | { model, name, class, image }; class is a name below or GetVehicleClass's number |
true, or false, why and nothing added (missing model, unknown class, picture not in your resource, another pack's model)Whip.register(function()
Whip.core:RegisterVehicles({
{ model = 'mypack_gt', name = 'Velo GT', class = 'sports', image = 'img/mypack_gt.webp' },
})
end)
Classes: compacts sedans suvs coupes muscle sportsclassics sports super motorcycles offroad industrial utility vans cycles boats helicopters planes service emergency military commercial trains openwheel.
The URL of a vehicle's picture for any resource's NUI: from its media pack over cfx-nui, or from WHIP's CDN when that pack isn't installed.
| Param | Type | Description |
|---|---|---|
| model | string | Model name, any case |
string|nil: e.g. https://cfx-nui-whip_media_previews/img/vehicles/sultan.webp, or https://media.whipfx.net/media/img/vehicles/sultan.webp?v=v1.0.0Whether a model has a picture.
| Param | Type | Description |
|---|---|---|
| model | string | Model name, any case |
boolean