Vehicle Related Methods
xVehicle.setCoords
Sets the vehicle's coordinates and heading.
xVehicle.setCoords(coords)
- coords:
table
orvector3
orvector4
xVehicle.getCoords
Gets the vehicle's coordinates and heading
xVehicle.getCoords(vector)
- vector?:
boolean
(if true, it returns the vehicle coords as vector4, else it returns the coords as table) - @return
vector4
ortable
xVehicle.set
Sets the vehicle's non-persistant data for key to the given value which will be removes on vehicle deletion. Similar to statebag data.
xVehicle.set(key, value)
- key:
string
- value:
any
xVehicle.get
Gets a value from the vehicles's non-persistant data, or omit the argument to get all data.
xVehicle.get(key)
- key?:
string
(if omitted, it returns all data) - @return
any
xVehicle.setMetadata
Sets the vehicle's persistant data for key to the given value which will be saved on vehicle deletion. Unlike statebag data.
xVehicle.setMetadata(key, value, subValue)
- key:
string
- value?:
string
ornumber
ortable
- subValue?:
any
- @return
boolean
(indicating whether the action was successful or not)
xVehicle.getMetadata
Gets a value from the vehicles's persistant data, or omit the argument to get all data.
xVehicle.getMetadata(key, subKey)
- key?:
string
(if omitted, it returns all data) - subKey?:
any
- @return
any
xVehicle.delete
Removes/despawns the vehicle from the game world, optionally removes its entry from database.
xVehicle.delete(removeFromDb)
- removeFromDb?:
boolean
(delete the entry from database as well or no - defaults to false if omitted)
xVehicle.setStored
Updates the vehicle's stored
property and optionally despawns it.
xVehicle.setStored(value, despawn)
- value?:
boolean
- despawn?:
boolean
(remove the vehicle entity from the game world as well or no - defaults to false if omitted)
xVehicle.setOwner
Updates the vehicle's owner, matching a xPlayer's identifier
or nil to set it as unowned.
xVehicle.setOwner(newOwner)
- newOwner?:
string
xVehicle.setGroup
Updates the vehicle's group, which can be used for garage restrictions, unowned group vehicles, etc.
xVehicle.setGroup(newGroup)
- newGroup?:
string
xVehicle.setPlate
Sets the vehicle's plate, used in the database to ensure uniqueness. Does not necessarily match the vehicle's plate property (i.e. fake plates).
Plate is always formatted to 8 characters.
xVehicle.setPlate(newPlate)
- newPlate:
string
xVehicle.setField
Sets the value of the specified field for the xVehicle object. If a field with the same name already exist, its value will be overrided.
xVehicle.setField(fieldName, value)
- fieldName:
string
- value:
number
orstring
orboolean
ortable
- return
boolean
(whether the field registration was successful or not)
xVehicle.setMethod
Adds a new method/function to the current xVehicle object. If a method with the same name already exist, it will be overrided.
xVehicle.setMethod(fnName, fn)
- fnName:
string
- fn:
function
- return
boolean
(whether the method registration was successful or not)
Example using xVehicle.setMethod
function
local xVehicle = ESX.GetVehicle(65535)
-- registering a new method called "customCheck"
xVehicle.setMethod("customCheck", function(self)
return function(firstParameter)
print(("This is xVehicle(%s)'s 'customCheck' method being triggered"):format(self.entity))
print(("The parameter passed in the 'customCheck' method is '%s'"):format(firstParameter))
end
end)
-- reloading the xVehicle object after new method is registered
xVehicle = ESX.GetVehicle(xVehicle.entity)
-- calling the new registered method
xVehicle.customCheck("hello from customCheck")
p.s. In this way of registering a new method, only xVehicle object of vehicle(65535) will have the customCheck
method registered for it!
could be useful in scenarios when you don't want to populate all vehicle objects with the new method.