Garages API
Server exports for garages. A garage is a place and its bays; which cars are in it is each vehicle's own garage field. New to garages? Read Garages first.
Reading
One garage by key, or every garage. Both return copies.
| Param | Type | Description |
|---|---|---|
| key | string | The garage's key (GetGarage only) |
GetGarage → { garageId, key, resource, name, x, y, z, heading, spawnX, spawnY, spawnZ, spawnHeading, blipSprite, blipColor } or nil, plus private = true and managedBy for a property's garage. GetGarages → { [key] = garage }config.lua: a hardcoded key fails with "Wrong garage" once someone renames a garage.The garage closest to a point, measured to its marker or nearest bay, so a far bay of a big car park still counts. Never returns a private garage.
| Param | Type | Description |
|---|---|---|
| x, y, z | number | The point |
| maxRange | number? | Only a garage within this many metres |
string|nil key, number|nil distancelocal c = GetEntityCoords(GetPlayerPed(source))
local key = exports.whip_core:GetNearestGarage(c.x, c.y, c.z, 15.0)
if key then exports.whip_core:DespawnVehicle(vehicleId, { garage = key, refuseOccupied = true }) end
The vehicles stored in one garage, as GetVehicle snapshots.
| Param | Type | Description |
|---|---|---|
| key | string | The garage's key |
table[]; {} for a key that names no garageManaging garages
Make, change and remove garages at runtime; blips and markers update on every client. A new garage gets one bay, at the spawn point; add more in /whip → Vehicles → Garages. Update changes only the fields you send.
| Field | Type | Description |
|---|---|---|
| key | string | Unique; set at creation, never changed |
| name | string | Shown on the blip |
| x, y, z, heading | number | The garage marker |
| spawnX, spawnY, spawnZ, spawnHeading | number | The first bay (default the marker) |
| blipSprite, blipColor | number | Map blip style |
CreateGarage(data) → table|false, string|nil; UpdateGarage(key, data), DeleteGarage(key) → boolean, string|nil. A garage another running resource made is refused; one made in /whip, by a property, or by a stopped resource is open to anylocal garage, err = exports.whip_core:CreateGarage({
key = 'impound', name = 'Impound Lot', x = 409.3, y = -1623.1, z = 29.3, heading = 230.0,
})
exports.whip_core:UpdateGarage('impound', { name = 'City Impound' })
exports.whip_core:DeleteGarage('impound')
DeleteGarage moves them to the nearest other garage (or the default one) and tells online owners where. In /whip, a garage with cars can't be deleted until the admin picks the public garage they move to.Move a stored vehicle to another garage: an impound releasing a car, a dealer delivering to the buyer's garage. DespawnVehicle with a garage refuses a car already put away ("Vehicle is already stored"); this moves it.
| Param | Type | Description |
|---|---|---|
| vehicleId | number|table | A vehicle reference |
| garageKey | string | The garage it now belongs to |
boolean ok, string|nil errCanUseGarage before moving a player's car into a property garage; if they can't use it, WHIP moves the car to a public garage the next time access changes.May this person use this garage? Always true for a public one. A private garage (a property's, keyed property:<id>) is for its owner and keyholders only: hidden bays, no blip, and its bay events refuse anyone else.
| Param | Type | Description |
|---|---|---|
| key | string | The garage |
| who | number|table | A person: server id, or { charId = n } |
true, or false, why ('No such garage', 'That garage belongs to …')local ok, why = exports.whip_core:CanUseGarage(garageKey, source)
if not ok then return false, why end
exports.whip_core:SetVehicleGarage(vehicleId, garageKey)