Skip to content

Exports (server)#

DeleteVehicle#

Deletes a vehicle from the world and the internal table so that it doesn't respawn.

Parameters:
vehicle - int - The vehicle to delete.
keepInWorld? - bool - If the vehicle should stay in the world. Defaults to false.

Returns:
boolean - If deleting was successful.

local success = exports["AdvancedParking"]:DeleteVehicle(vehicle, false)

GetVehiclePosition#

Returns the position of a single vehicle. If vehicle is present on server side it will get the position using GetEntityCoords. If not present, it will check AdvancedParking's data for the last saved position.

Parameters:
plate - string - License plate text of a vehicle (not case sensitive) (checks full and trimmed plate).

Returns:
vector3? - Position of the vehicle or nil.

local position = exports["AdvancedParking"]:GetVehiclePosition(plate)

GetVehiclePositions#

Returns the positions of several given vehicles. If vehicle is present on server side it will get the position using GetEntityCoords. If not present, it will check AdvancedParking's data for the last saved position.

Parameters:
plates - table<string> - Table containing license plates (not case sensitive) (checks full and trimmed plate).

Returns:
dictionary<string, vector3> - Positions of the vehicles by plate. Can be empty if none was found.

local plateList = { plate1, plate2, plate3 }
local positions = exports["AdvancedParking"]:GetVehiclePositions(plateList)
for plate, position in pairs(positions) do
    print(plate, tostring(position))
end

DeleteVehicleUsingData#

Delete a vehicle without having access to the entity directly. At least one of the first three parameters must be provided.

Parameters:
identifier? - string - The unique identifier provided by AdvancedParking.
networkId? - int - Vehicle network id.
plate? - string - Vehicle license plate text.
keepInWorld? - bool - If the vehicle should stay in the world. Defaults to false.

Returns:
boolean - If deleting was successful.

local identifier = Entity(vehicle).state.ap_id
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
local plate = GetVehicleNumberPlateText(vehicle)

local success = exports["AdvancedParking"]:DeleteVehicleUsingData(identifier, networkId, plate, true)

GetVehicleFromStateBagValue#

Tries to find a vehicle that has a specific state bag value attached.

Parameters:
bagName - string - The key to search for.
bagValue - any - The value to search for.

Returns:
int? - Vehicle handle if a match was found or nil.

local vehicle = exports["AdvancedParking"]:GetVehicleFromStateBagValue(bagName, bagValue)

GetStateBagsFromVehicle#

Gets all state bags from a vehicle that has been saved by AdvancedParking.

Parameters:
vehicle - int - Vehicle handle.

Returns:
dictionary<bagName, bagValue>? - Table containing all state bag keys and values or nil if vehicle was not found.

local stateBags = exports["AdvancedParking"]:GetStateBagsFromVehicle(vehicle)
if (stateBags) then
    for bagName, bagValue in pairs(stateBags) do
        print(bagName, type(bagValue) == "table" and bagValue or json.encode(bagValue))
    end
end

GetStateBagsFromPlate#

Gets all state bags from a vehicle that has been saved by AdvancedParking given its plate.

Parameters:
plate - string - Vehicle license plate text.

Returns:
dictionary<bagName, bagValue>? - Table containing all state bag keys and values or nil if vehicle was not found.

local stateBags = exports["AdvancedParking"]:GetStateBagsFromPlate("KIMINAZE")
if (stateBags) then
    for bagName, bagValue in pairs(stateBags) do
        print(bagName, type(bagValue) == "table" and bagValue or json.encode(bagValue))
    end
end

AddStateBagsToIgnoreList#

Adds all given params to the state bag ignore list. Intended to be used from other resources to prevent state bags from being saved altogether.

Parameters:
... - string - State bag names to ignore.

-- example integration:
--   executes on resource start and when it is already started to prevent loadorder issues
AddEventHandler("onResourceStart", function(resourceName)
    if (resourceName == "AdvancedParking") then
        exports["AdvancedParking"]:AddStateBagsToIgnoreList("fuel", "attachments")
    end
end)

if (GetResourceState("AdvancedParking") == "started") then
    exports["AdvancedParking"]:AddStateBagsToIgnoreList("fuel", "attachments")
end

AddStateBagsToPreventAutoUpdateList#

Adds all params to the state bag list to prevent auto updates. Intended to be used from other resources to prevent state bags from being saved directly when they are updated. These will only be saved on a full save.

Parameters:
... - string - State bag names to not auto update.

-- example integration:
--   executes on resource start and when it is already started to prevent loadorder issues
AddEventHandler("onResourceStart", function(resourceName)
    if (resourceName == "AdvancedParking") then
        exports["AdvancedParking"]:AddStateBagsToPreventAutoUpdateList("fuel", "attachments")
    end
end)

if (GetResourceState("AdvancedParking") == "started") then
    exports["AdvancedParking"]:AddStateBagsToPreventAutoUpdateList("fuel", "attachments")
end

ForceVehicleUpdateInDB#

Forces an update of all currently set values of the specified vehicle to the database. Does nothing if identifier was not found.

Parameters:
identifier - string - The unique identifier provided by AdvancedParking.

local identifier = Entity(vehicle)?.state?.ap_id
exports["AdvancedParking"]:ForceVehicleUpdateInDB(identifier)

GetVehicleData#

Gets all of AdvancedParking's data from a specified vehicle.

Parameters:
vehicle - int - Vehicle handle.

Returns:
dictionary<key, value>? - Table containing all data from the vehicle or nil if vehicle was not found.

local data = exports["AdvancedParking"]:GetVehicleData(vehicle)

GetVehicleTuningFromData#

Gets all tuning data of AdvancedParking's data from a specified vehicle.

Parameters:
vehicle - int - Vehicle handle.

Returns:
table? - Table containing all tuning data from the vehicle or nil if vehicle was not found.

local tuning = exports["AdvancedParking"]:GetVehicleTuningFromData(vehicle)

UpdatePlate#

Updates a plate in AdvancedParking's data. This is necessary when changing a saved vehicle's plate so that it doesn't get caught by one of the error protection systems.

Parameters:
networkId - int - Vehicle network id.
newPlate - string - New plate to set.

exports["AdvancedParking"]:UpdatePlate(networkId, newPlate)

FreezeVehicle#

Freezes (or unfreezes) a vehicle. This is intended to be used from the fixFreezeEntity.lua but can be used when the file cannot be used. Can only be executed when using the forceUnfreezeVehicles config option.

Parameters:
vehicle - int - Vehicle handle.
freeze - boolean - true for freezing, false for unfreezing.

exports["AdvancedParking"]:FreezeVehicle(vehicle, true)