Vehicle data & handling API
Attach your own data to a car, react to it on every client, and change how the car drives and how its dial reads. For when to use data, see Vehicle data.
Vehicle data
Attach data to a vehicle by name: saved in the car's row and replicated to every client with the car in scope. Set and Clear are server only; Get works on both sides, and with no key returns a copy of everything the car carries.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference ({ entity = veh } for a handle) |
| key | string | 1–40 characters of [A-Za-z0-9_] |
| value | any | Anything JSON-encodable, false included; nil removes it |
boolean, string|nil; reads the value (a stored false reads as false) or a copy of the blockA table in place of the key sets several keys in one replication and one database write, for installing a kit. Each key still fires its own whip_core:vehicle:dataChanged after the commit.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
| values | table | { [key] = value }, keys as for one |
number written, or false, reason when nothing was writtenClearVehicleData). Keys past your 32 are skipped and logged; a batch that would take the block past 8 KB, or touches another resource's key, is refused whole.Remove every key your resource put on a car: uninstalling a kit. Other resources' keys stay. Fires one dataChanged per key removed. Stats are untouched (see ClearVehicleStat).
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
boolean, string|nil: why not is no such vehicle, or the write failedBe called when one data key changes, on any vehicle: the server half of the client export, and cheaper than handling every dataChanged broadcast. Dropped when your resource stops.
| Param | Type | Description |
|---|---|---|
| key | string | The data key to watch |
| callback | function | (vehicleId, value, cleared, old), or one table with table = true |
| id | string? | Only for two listeners on one key; the same id replaces |
| opts | table? | { table = true, now = true }; may go third, in place of id |
boolean registeredWhip.register(function()
Whip.core:OnVehicleDataChanged('kit', function(change)
if change.cleared then --[[ the kit came off; change.old is what it was ]] end
end, { table = true, now = true })
end)
table = true: { vehicleId, key, value, old, cleared, resource } (plus entity on the client). Positional order differs: the client's callback gets (vehicleId, value, old, entity), and OnVehicleStatChanged's (vehicleId, value, previous, cleared, source). now = true also calls it at once for every car with the key.Run code while a car in scope carries a data key: the data twin of WatchVehicleStat. For what each client must do to a car itself because GTA doesn't replicate it: an engine sound, wheel stance, handling.
| Field | Type | Description |
|---|---|---|
| onGained | function? | (entity, value, vehicleId): a car in scope has the key (cars already in scope are announced on registration) |
| onChanged | function? | (entity, value, old, vehicleId): a new value; without it, onLost(old) then onGained(new) |
| onLost | function? | (entity, value, vehicleId): the key went or the car left scope; value is what it was |
| onStart | function? | (entity, value, vehicleId): starts for the car (with driverOnly: you now drive it) |
| onStop | function? | (entity, value, vehicleId): you got out, the key or car went. A new value while started fires onStop(old), onStart(new) |
| driverOnly | bool? | Narrow onStart/onStop to the car you drive, for handling. Default false |
| id | string? | Only for two watchers on one key; the same id replaces (with onStop) |
string|false, string|nil: watcher id, or false and whyexports.whip_core:WatchVehicleData('engine', {
onGained = function(entity, value) ForceUseAudioGameObject(entity, value.audio) end, -- every car in scope
onStart = function(entity, value) --[[ apply handling ]] end, -- you drive it
onStop = function(entity, value) --[[ restore handling ]] end,
driverOnly = true,
})
onStop. Put things back in your own onResourceStop too; a resource without dependency 'whip_core' also does it in Whip.onCoreLost. Values are compared by content, so another key changing doesn't re-fire you.Stop one of your data watchers. Fires onStop for what it started, not onLost. Watchers also go when their resource stops.
| Param | Type | Description |
|---|---|---|
| watcherId | string | The id WatchVehicleData returned |
boolean removedHandling and power
Physics belongs to the driver, so set these from a driverOnly watcher's onStart (WatchVehicleStat or WatchVehicleData) and clear them in its onStop. They apply to one car at a time: asking for a different car puts the previous one back first.
Never write handling yourself: declare a layer. WHIP captures each field's stock value, applies every resource's layers, and restores the car on every way out (layer cleared, another car, car gone, a resource stopping). Two features writing a field directly undo each other. Drivetrain changes are committed for you.
| Param | Type | Description |
|---|---|---|
| vehicle | table|number | A vehicle reference |
| name | string | Your layer's name, one per feature; setting it again replaces it |
| spec.set | table? | { field = value }: absolute, in handling.meta units; CHandlingData floats (f…) and whole numbers (n…); gears kept to 1–7 |
| spec.add | table? | { field = amount } (−1000 to 1000), added after every layer's set; layers' adds sum |
| spec.scale | table? | { field = factor } (0.01–100), applied after every set and add |
| spec.order | number? | When two layers set one field, the higher wins. Default 0 |
boolean, string|nil; Clear → boolean removed; GetVehicleHandlingBase → a field's value after every set and add, before scaleexports.whip_core:SetVehicleHandlingLayer({ entity = veh }, 'engine', { set = { fInitialDriveForce = 0.34 } })
exports.whip_core:SetVehicleHandlingLayer({ entity = veh }, 'tune', { scale = { fSuspensionForce = 1.2 } })
exports.whip_core:ClearVehicleHandlingLayer('tune')
SetVehiclePower, not a layer. fInitialDriveMaxFlatVel is the gearing (speed at redline in top gear), so scaling it with a turbo stretches every gear.Ask for more (or less) torque on the car this player drives: a turbo's boost, nitrous. Gearing is untouched, so more torque is more speed only where drag held the car back. Ask again as the amount changes; the car gets the product of every resource's ask each frame, and is normal again when nothing is asked.
| Param | Type | Description |
|---|---|---|
| vehicle | table|number | A vehicle reference |
| name | string | Your ask's name, one per feature; asking again replaces it |
| multiplier | number | 0 to 10: 1.25 is a quarter more torque, 1.0 the engine as it is |
boolean, string|nil; Clear → boolean removedexports.whip_core:SetVehiclePower({ entity = veh }, 'turbo', 1.0 + 0.25 * boost)
SetVehicleCheatPowerIncrease yourself. The last write in a frame wins, so it undoes WHIP's.The rev dial
Say which engine a vehicle's rev dial follows, on this player's game. The dial uses the engine's model in Config.VehicleHud.rpmByModel, else rpmElectric for an electric motor, else its kind in rpmByClass. After an engine swap, name the donor: a dump truck with an F1 engine then revs to 15k.
| Param | Type | Description |
|---|---|---|
| vehicle | table|number | A vehicle reference |
| engine | string|table|nil | A model's spawn name; { max, idle? } in thousands of rpm (max 2–20, idle 0 or more, under max); or nil for its own engine |
boolean, string|nil: why not is no such vehicle, not a vehicle model, a range out of bounds, or another running resource set itexports.whip_core:SetVehicleRevRange({ entity = veh }, 'formula') -- or { max = 11, idle = 1.2 }
WatchVehicleData watcher for every car in view, cleared in onLost. The car you're in updates at once; your settings go when your resource stops.Is the vehicle's engine electric? GTA's flag on its engine's model, its own or the one SetVehicleRevRange names. whip_fuel gives electric cars no fuel.
| Param | Type | Description |
|---|---|---|
| vehicle | table|number | A vehicle reference |
boolean: false for a vehicle not here, or a game build without the flagSet the forward gear the dial shows when your resource drives the gears (whip_autos keeps GTA in gear 1 and changes its ratio). Use 'speed' when you move the car yourself, as a recorded drive does: the dial works the gear out from speed and ratios, and shows R going backwards. Reverse and N stay the game's. This player's dial only; cleared when your resource stops. Clear it when you hand the car back: GTA's gearbox is put in the gear the dial showed.
| Param | Type | Description |
|---|---|---|
| vehicle | table|number | A vehicle reference |
| gear | number|string|nil | 1 to 20; 'speed'; or nil for the game's gear again |
boolean, string|nil: why not is no such vehicle, a gear out of bounds, or another running resource set itexports.whip_core:SetVehicleDialGear({ entity = veh }, 3)