Skip to main content
The Vehicles component handles owned vehicles, temporary vehicle spawning, vehicle keys, garage management, and vehicle state management. It integrates with the inventory, characters, jobs, and properties systems.

Vehicle Ownership

AddToCharacter

Add a vehicle to a character’s ownership. Parameters:
NameTypeRequiredDescription
charSIDnumberYesCharacter State ID
vehicleHashnumberYesVehicle model hash
vehicleTypenumberYesVehicle type (0=car, 1=boat, 2=aircraft)
infoDatatableYesVehicle information (make, model, class, value)
cbfunctionYesCallback function (success, vehicleData)
propertiestableNoVehicle customization properties
defaultStoragetableNoStorage location {Type, Id}
suppliedVINstringNoCustom VIN (auto-generated if not provided)
Returns:
TypeDescription
functionCalls callback with success status and vehicle data
Example:
-- Server side
local characterId = 123
local vehicleHash = GetHashKey('adder')

COMPONENTS.Vehicles.Owned:AddToCharacter(
    characterId,
    vehicleHash,
    0, -- Car type
    {
        make = 'Truffade',
        model = 'Adder',
        class = 'Super',
        value = 1000000
    },
    function(success, vehicleData)
        if success then
            print('Vehicle added:', vehicleData.VIN)
            print('Plate:', vehicleData.RegisteredPlate)

            -- Give keys to player
            COMPONENTS.Vehicles.Keys:Add(source, vehicleData.VIN)
        else
            print('Failed to add vehicle')
        end
    end,
    nil, -- Properties (will use defaults)
    nil, -- Default storage
    nil  -- Auto-generate VIN
)
Use Cases:
-- Add vehicle from dealership purchase
AddEventHandler('dealership:server:PurchaseVehicle', function(modelName, price)
    local src = source
    local player = Fetch:Source(src)

    if not player then
        return
    end

    local char = player:GetData('Character')
    if not char then
        return
    end

    local stateId = char:GetData('SID')

    local vehicleHash = GetHashKey(modelName)

    -- Charge player
    if COMPONENTS.Characters:RemoveMoney(stateId, 'bank', price, 'Vehicle purchase') then
        -- Add vehicle to character
        COMPONENTS.Vehicles.Owned:AddToCharacter(
            stateId,
            vehicleHash,
            0,
            {
                make = GetMakeName(modelName),
                model = GetModelName(modelName),
                class = GetVehicleClass(modelName),
                value = price
            },
            function(success, vehicleData)
                if success then
                    -- Give keys
                    COMPONENTS.Vehicles.Keys:Add(src, vehicleData.VIN)

                    -- Notify player
                    TriggerClientEvent('mythic-notifications:client:Send', src, {
                        message = 'Vehicle purchased! Check your garage.',
                        type = 'success'
                    })
                end
            end
        )
    end
end)

AddToFleet

Add a vehicle to a job fleet. Parameters:
NameTypeRequiredDescription
jobIdstringYesJob identifier
jobWorkplacestringNoWorkplace ID (for multi-department jobs)
vehicleLevelnumberYesMinimum grade level required to access
vehicleHashnumberYesVehicle model hash
vehicleTypenumberYesVehicle type (0=car, 1=boat, 2=aircraft)
infoDatatableYesVehicle information
cbfunctionYesCallback function
propertiestableNoVehicle customization
qualstringNoRequired qualification/certification
Example:
-- Server side - Add police vehicle to fleet
local policeCarHash = GetHashKey('police')

COMPONENTS.Vehicles.Owned:AddToFleet(
    'police',          -- Job ID
    'lspd',            -- Workplace (LSPD department)
    10,                -- Level 10 (Officer) required
    policeCarHash,
    0,                 -- Car type
    {
        make = 'Generic',
        model = 'Police Cruiser',
        class = 'Emergency',
        value = 50000
    },
    function(success, vehicleData)
        if success then
            print('Fleet vehicle added:', vehicleData.VIN)
        end
    end,
    {
        -- Custom livery
        livery = 0,
        extras = {
            [1] = true,  -- Extra 1 enabled
            [2] = false,
        }
    },
    nil  -- No special qualification required
)
Fleet Vehicle Access:
-- Only officers (level 10+) at LSPD can spawn this vehicle
-- Checked automatically when spawning fleet vehicles

GetActive

Get active (spawned) vehicle data by VIN. Parameters:
NameTypeRequiredDescription
VINstringYesVehicle Identification Number
Returns:
TypeDescription
table/booleanVehicle DataStore object or false if not spawned
Example:
-- Server side
local VIN = 'ABC123456789'
local vehicleData = COMPONENTS.Vehicles.Owned:GetActive(VIN)

if vehicleData then
    print('Vehicle is spawned')
    print('Entity ID:', vehicleData:GetData('EntityId'))
    print('Fuel:', vehicleData:GetData('Fuel'))
    print('Mileage:', vehicleData:GetData('Mileage'))

    -- Update vehicle data
    vehicleData:SetData('Fuel', 50)
else
    print('Vehicle is not currently spawned')
end

GetVIN

Get vehicle data from database by VIN. Parameters:
NameTypeRequiredDescription
VINstringYesVehicle Identification Number
cbfunctionYesCallback function
Returns:
TypeDescription
functionCalls callback with vehicle data or false
Example:
-- Server side
COMPONENTS.Vehicles.Owned:GetVIN('ABC123456789', function(vehicleData)
    if vehicleData then
        print('Owner:', vehicleData.Owner.Type, vehicleData.Owner.Id)
        print('Make/Model:', vehicleData.Make, vehicleData.Model)
        print('Storage:', vehicleData.Storage.Type, vehicleData.Storage.Id)
        print('Fuel:', vehicleData.Fuel)
        print('Mileage:', vehicleData.Mileage)
    else
        print('Vehicle not found')
    end
end)

GetAll

Get all vehicles matching criteria. Parameters:
NameTypeRequiredDescription
vehTypenumberNoVehicle type filter (0=car, 1=boat, 2=aircraft)
ownerTypenumberNoOwner type (0=character, 1=fleet)
ownerIdnumber/stringNoOwner ID (character SID or job ID)
cbfunctionYesCallback function
storageTypenumberNoStorage type (0=impound, 1=garage, 2=property)
storageIdstringNoStorage location ID
ignoreSpawnedbooleanNoExclude currently spawned vehicles
checkFleetOwnertableNoCheck fleet access
Returns:
TypeDescription
functionCalls callback with array of vehicle data
Example:
-- Get all character's vehicles
COMPONENTS.Vehicles.Owned:GetAll(0, 0, characterId, function(vehicles)
    if vehicles then
        print(string.format('Found %d vehicles', #vehicles))
        for k, v in ipairs(vehicles) do
            print(v.Make, v.Model, v.RegisteredPlate)
            print('Storage:', v.Storage.Type, v.Storage.Id)
            print('Spawned:', v.Spawned and 'Yes' or 'No')
        end
    end
end, nil, nil, false)

-- Get vehicles in specific garage
COMPONENTS.Vehicles.Owned:GetAll(
    0,              -- Cars only
    0,              -- Character owned
    characterId,    -- Owner
    function(vehicles)
        -- Display garage menu
    end,
    1,              -- Garage storage
    'legion_square' -- Garage ID
)

-- Get job fleet vehicles accessible to player
local player = Fetch:Source(source)

if not player then
    return
end

local char = player:GetData('Character')
if not char then
    return
end

local jobId = char:GetData('Job')

COMPONENTS.Vehicles.Owned:GetAll(
    0,    -- Cars
    nil,  -- Any owner type
    nil,  -- Any owner
    function(vehicles)
        -- Display fleet menu
    end,
    nil,  -- Any storage
    nil,  -- Any location
    true, -- Ignore spawned
    {     -- Fleet access check
        Id = jobId,
        Workplace = char:GetData('JobWorkplace'),
        Level = char:GetData('JobGrade')
    }
)

Spawn

Spawn an owned vehicle into the world. Parameters:
NameTypeRequiredDescription
sourcenumberYesPlayer source (0 for server-spawned)
VINstringYesVehicle Identification Number
coordsvector3YesSpawn coordinates
headingnumberNoSpawn heading
cbfunctionYesCallback function
Returns:
TypeDescription
functionCalls callback with (success, vehicleData, entityId)
Example:
-- Server side
local VIN = 'ABC123456789'
local spawnCoords = vector3(100.0, 200.0, 30.0)
local heading = 90.0

COMPONENTS.Vehicles.Owned:Spawn(
    source,
    VIN,
    spawnCoords,
    heading,
    function(success, vehicleData, entityId)
        if success then
            print('Vehicle spawned:', entityId)
            print('Plate:', vehicleData.RegisteredPlate)

            -- Give keys to player
            COMPONENTS.Vehicles.Keys:Add(source, VIN)

            -- Notify client
            TriggerClientEvent('mythic-vehicles:client:VehicleSpawned', source, entityId)
        else
            TriggerClientEvent('mythic-notifications:client:Send', source, {
                message = 'Failed to spawn vehicle',
                type = 'error'
            })
        end
    end
)
Garage System Example:
-- Spawn vehicle from garage
AddEventHandler('garage:server:SpawnVehicle', function(VIN, spawnLocation)
    local src = source
    local player = Fetch:Source(src)

    if not player then
        return
    end

    local char = player:GetData('Character')
    if not char then
        return
    end

    local stateId = char:GetData('SID')

    -- Verify ownership
    COMPONENTS.Vehicles.Owned:GetVIN(VIN, function(vehicleData)
        if vehicleData and vehicleData.Owner.Type == 0 and vehicleData.Owner.Id == stateId then
            -- Spawn vehicle
            COMPONENTS.Vehicles.Owned:Spawn(
                src,
                VIN,
                spawnLocation.coords,
                spawnLocation.heading,
                function(success, vehData, entityId)
                    if success then
                        COMPONENTS.Vehicles.Keys:Add(src, VIN)
                    end
                end
            )
        end
    end)
end)

Store

Store a spawned vehicle in a garage/property. Parameters:
NameTypeRequiredDescription
VINstringYesVehicle Identification Number
storageTypenumberYesStorage type (0=impound, 1=garage, 2=property)
storageIdstringYesStorage location ID
cbfunctionYesCallback function
Example:
-- Server side
COMPONENTS.Vehicles.Owned:Store(
    'ABC123456789',
    1,              -- Garage storage
    'legion_square',
    function(success)
        if success then
            print('Vehicle stored successfully')
        end
    end
)

Delete

Delete a spawned vehicle (despawn and save to database). Parameters:
NameTypeRequiredDescription
VINstringYesVehicle Identification Number
cbfunctionYesCallback function
ignoreExistsbooleanNoSkip entity exists check
Example:
-- Server side
COMPONENTS.Vehicles.Owned:Delete('ABC123456789', function(success)
    if success then
        print('Vehicle deleted (saved to database)')
    end
end)

ForceSave

Force save vehicle data to database immediately. Parameters:
NameTypeRequiredDescription
VINstringYesVehicle Identification Number
Example:
-- Server side
COMPONENTS.Vehicles.Owned:ForceSave('ABC123456789')

-- Use before server shutdown
AddEventHandler('onResourceStop', function(resourceName)
    if resourceName == GetCurrentResourceName() then
        for VIN, vehicleData in pairs(ACTIVE_OWNED_VEHICLES) do
            COMPONENTS.Vehicles.Owned:ForceSave(VIN)
        end
    end
end)

Track

Get vehicle location (spawned or storage). Parameters:
NameTypeRequiredDescription
VINstringYesVehicle Identification Number
Returns:
TypeDescription
vector3Vehicle location coordinates
Example:
-- Server side (sync)
local location = COMPONENTS.Vehicles.Owned:Track('ABC123456789')
if location then
    print('Vehicle location:', location)
end

Vehicle Keys

Has

Check if player has keys to a vehicle. Parameters:
NameTypeRequiredDescription
sourcenumberYesPlayer source
VINstringYesVehicle Identification Number
groupKeysstringNoGroup key check (e.g., ‘police’, ‘ems’)
Returns:
TypeDescription
booleanTrue if player has keys
Example:
-- Server side
local hasKeys = COMPONENTS.Vehicles.Keys:Has(source, 'ABC123456789')

if hasKeys then
    print('Player has keys to this vehicle')
end

-- Check with group keys (police/ems can access without personal keys if on duty)
local hasAccess = COMPONENTS.Vehicles.Keys:Has(source, 'ABC123456789', 'police')

Add

Give vehicle keys to a player. Parameters:
NameTypeRequiredDescription
sourcenumberYesPlayer source
VINstringYesVehicle Identification Number
Example:
-- Server side
COMPONENTS.Vehicles.Keys:Add(source, 'ABC123456789')

-- Give keys when player buys a vehicle
AddEventHandler('dealership:vehiclePurchased', function(source, vehicleData)
    COMPONENTS.Vehicles.Keys:Add(source, vehicleData.VIN)

    TriggerClientEvent('mythic-notifications:client:Send', source, {
        message = 'You received the vehicle keys',
        type = 'success'
    })
end)

Remove

Remove vehicle keys from a player. Parameters:
NameTypeRequiredDescription
sourcenumberYesPlayer source
VINstringYesVehicle Identification Number
Example:
-- Server side
COMPONENTS.Vehicles.Keys:Remove(source, 'ABC123456789')

-- Remove keys when vehicle is sold
AddEventHandler('dealership:vehicleSold', function(source, VIN)
    COMPONENTS.Vehicles.Keys:Remove(source, VIN)
end)

Temporary Vehicles

SpawnTemp

Spawn a temporary (non-owned) vehicle. Parameters:
NameTypeRequiredDescription
sourcenumberYesPlayer source (0 for server)
modelnumberYesVehicle model hash
coordsvector3YesSpawn coordinates
headingnumberYesSpawn heading
cbfunctionYesCallback function
vehicleInfoDatatableNoVehicle info (Make, Model, Class, Value)
propertiestableNoVehicle customization
preDamagetableNoInitial damage state
suppliedPlatestringNoCustom plate
suppliedVINstringNoCustom VIN
Returns:
TypeDescription
functionCalls callback with (entityId, VIN, plate)
Example:
-- Server side
local model = GetHashKey('adder')
local coords = vector3(100.0, 200.0, 30.0)
local heading = 90.0

COMPONENTS.Vehicles:SpawnTemp(
    source,
    model,
    coords,
    heading,
    function(entityId, VIN, plate)
        print('Temp vehicle spawned:', entityId)
        print('VIN:', VIN)
        print('Plate:', plate)
    end,
    {
        Make = 'Truffade',
        Model = 'Adder',
        Class = 'Super',
        Value = 1000000
    },
    nil,  -- No custom properties
    nil,  -- No pre-damage
    nil,  -- Auto-generate plate
    nil   -- Auto-generate VIN
)
Use Cases:
-- Rental vehicle
AddEventHandler('rental:server:RentVehicle', function(modelName, duration)
    local src = source
    local model = GetHashKey(modelName)
    local spawnCoords = GetRentalSpawnLocation()

    COMPONENTS.Vehicles:SpawnTemp(
        src,
        model,
        spawnCoords.coords,
        spawnCoords.heading,
        function(entityId, VIN, plate)
            -- Give temp keys
            COMPONENTS.Vehicles.Keys:Add(src, VIN)

            -- Set rental expiry
            SetTimeout(duration * 60000, function()
                COMPONENTS.Vehicles:Delete(entityId, function() end)
            end)
        end
    )
end)

-- Mission vehicle
AddEventHandler('missions:spawnVehicle', function(location)
    COMPONENTS.Vehicles:SpawnTemp(
        0,  -- Server spawn
        GetHashKey('burrito'),
        location.coords,
        location.heading,
        function(entityId, VIN, plate)
            -- Store for mission cleanup
            MissionVehicles[missionId] = entityId
        end
    )
end)

Delete (Any Vehicle)

Delete any vehicle (owned or temporary). Parameters:
NameTypeRequiredDescription
vehicleIdnumberYesVehicle entity ID
cbfunctionYesCallback function
Example:
-- Server side
COMPONENTS.Vehicles:Delete(vehicleEntity, function(success)
    if success then
        print('Vehicle deleted')
    end
end)

Garage Management

GetAll

Get all garage locations. Returns:
TypeDescription
tableTable of garage data {label, location}
Example:
-- Server side
local garages = COMPONENTS.Vehicles.Garages:GetAll()

for id, data in pairs(garages) do
    print(id, data.label, data.location)
end

Get

Get specific garage data. Parameters:
NameTypeRequiredDescription
idstringYesGarage identifier
Returns:
TypeDescription
tableGarage data or nil
Example:
-- Server side
local garage = COMPONENTS.Vehicles.Garages:Get('legion_square')

if garage then
    print('Garage:', garage.name)
    print('Location:', garage.coords)
    print('Type:', garage.vehType) -- 0=car, 1=boat, 2=aircraft
end

Impound

Get impound lot data. Returns:
TypeDescription
tableImpound location data
Example:
-- Server side
local impound = COMPONENTS.Vehicles.Garages:Impound()

print('Impound:', impound.name)
print('Location:', impound.coords)

Property Garage

Store

Store character vehicle in property garage. Parameters:
NameTypeRequiredDescription
sourcenumberYesPlayer source
VINstringYesVehicle Identification Number
propertyIdstringYesProperty identifier
cbfunctionYesCallback function
Example:
-- Server side
COMPONENTS.Vehicles.Owned.Properties:Store(
    source,
    'ABC123456789',
    'property_123',
    function(success)
        if success then
            TriggerClientEvent('mythic-notifications:client:Send', source, {
                message = 'Vehicle stored in property garage',
                type = 'success'
            })
        end
    end
)

Get

Get vehicles stored in property garage. Parameters:
NameTypeRequiredDescription
propertyIdstringYesProperty identifier
ownerStateIdnumberNoFilter by owner character SID
cbfunctionYesCallback function
Example:
-- Server side
COMPONENTS.Vehicles.Owned.Properties:Get(
    'property_123',
    characterId,
    function(vehicles)
        if vehicles then
            print(string.format('Found %d vehicles in property', #vehicles))
        end
    end
)

GetCount

Get count of vehicles in property garage. Parameters:
NameTypeRequiredDescription
propertyIdstringYesProperty identifier
ignoreVINstringNoExclude specific VIN from count
Returns:
TypeDescription
numberVehicle count
Example:
-- Server side (sync)
local count = COMPONENTS.Vehicles.Owned.Properties:GetCount('property_123')
print('Vehicles in property:', count)

-- Check capacity before storing
local maxCapacity = 4
local currentCount = COMPONENTS.Vehicles.Owned.Properties:GetCount('property_123', VIN)

if currentCount >= maxCapacity then
    -- Property garage is full
end

Next Steps

Vehicle State: Spawned vehicles have state stored in Entity(vehicle).state including VIN, Owner, Fuel, Damage, Mileage, and more. Access using Entity(veh).state.PropertyName.
Vehicle Saving: Vehicle data is automatically saved when despawned. Use ForceSave() before server shutdown to prevent data loss.