ATY Scripts Logo
ATY Scripts/Dokümanlar/Garages/Exports

Exports

This document provides detailed information on how to use the StoreVehicle and OpenGarage exports from the aty_garage resource.


Table of Contents

  1. StoreVehicle Export
  2. OpenGarage Export
  3. Garage Configuration Structure
  4. Examples

StoreVehicle Export

The StoreVehicle export allows you to programmatically store a vehicle into a garage from external resources.

Function Signature

exports['aty_garage']:StoreVehicle(garage, vehicle)

Parameters

Parameter Type Description
garage table A garage configuration table (see Garage Configuration Structure)
vehicle number The vehicle entity handle (obtained via GetVehiclePedIsIn() or similar)

Return Value

This function does not return a value. It handles the storage process internally including:

  • Checking if the vehicle is owned by the player
  • Saving vehicle properties (mods, colors, damage, etc.)
  • Saving body and engine damage states
  • Saving fuel level
  • Removing all passengers from the vehicle
  • Playing a fade-out animation before deleting the vehicle
  • Displaying success/error notifications

Behavior

  1. Ownership Check: The function first validates that the vehicle belongs to the player via a server callback.
  2. Property Collection: Collects all vehicle properties including modifications, damage, and fuel.
  3. Database Update: Updates the vehicle record in the database with the new garage location and stored state.
  4. Passenger Ejection: Forces all passengers (including the driver) to exit the vehicle.
  5. Visual Effect: Plays a fade-out animation before deleting the vehicle entity.
  6. Notification: Shows a success or error notification to the player.

Requirements

  • Player must own the vehicle
  • Vehicle must be a valid entity

OpenGarage Export

The OpenGarage export allows you to programmatically open the garage UI from external resources.

Function Signature

exports['aty_garage']:OpenGarage(garage)

Parameters

Parameter Type Description
garage table A garage configuration table (see Garage Configuration Structure)

Return Value

This function does not return a value. It opens the garage NUI interface for the player.

Behavior

  1. Data Retrieval: Fetches all vehicles stored in the specified garage from the database.
  2. Vehicle Information: For each vehicle, it retrieves:
    • Brand name
    • Model name
    • Health status
    • Storage state
    • Mileage (via custom MileAgeFunction)
  3. UI Display: Opens the NUI garage interface with the vehicle list.
  4. Empty Check: If no vehicles are found, it prints a debug message and does not open the UI.

Notes

  • The UI will set SetNuiFocus(1, 1) to enable cursor and keyboard input
  • The player should not be in a vehicle when calling this export
  • Uses the Config.MileAgeFunction to calculate vehicle mileage

Garage Configuration Structure

Both exports require a garage configuration table. This table must follow the structure defined in config.lua:

{
    label = "Garage Name",           -- Display name of the garage
    garage = "garageid",             -- Unique identifier for the garage (used in database)
    pedCoords = vector4(x, y, z, h), -- Coordinates and heading for the garage ped
    vehicleCoords = vector3(x, y, z),-- Coordinates for storing vehicles
    heading = 0.0,                   -- Default vehicle heading
    radius = 5.0,                    -- Interaction radius
    job = "all",                     -- Job restriction ("all" for public, or specific job name)
    blip = {
        show = true,
        sprite = 357,
        color = 3,
        size = 0.8,
        label = "Garage",
    },
    spawnCoords = {                  -- Available spawn positions for vehicles
        vector4(x, y, z, h),
        -- ... more spawn points
    }
}

Key Properties

Property Type Description
label string Human-readable name shown in UI
garage string Database identifier for the garage
pedCoords vector4 NPC position (x, y, z) and heading (w)
vehicleCoords vector3 Position to detect vehicles for storage
job string Job requirement ("all" for no restriction)
spawnCoords table Array of vector4 spawn positions

Examples

Example 1: Store Current Vehicle to a Custom Garage

-- Define a custom garage configuration
local myGarage = {
    label = "My Custom Garage",
    garage = "customgarage",
    pedCoords = vector4(100.0, 200.0, 30.0, 180.0),
    vehicleCoords = vector3(105.0, 205.0, 30.0),
    heading = 0.0,
    radius = 5.0,
    job = "all",
    blip = {
        show = false,
        sprite = 357,
        color = 3,
        size = 0.8,
        label = "Custom Garage",
    },
    spawnCoords = {
        vector4(110.0, 210.0, 30.0, 90.0),
    }
}

-- Store the player's current vehicle
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)

if vehicle ~= 0 then
    exports['aty_garage']:StoreVehicle(myGarage, vehicle)
end

Example 2: Open Garage from a Custom Command

RegisterCommand('opengarage', function()
    -- Use an existing garage from config
    local garage = Config.Garages["motelgarage"]

    -- Open the garage UI
    exports['aty_garage']:OpenGarage(garage)
end, false)

Example 3: Open Garage from a Target Interaction

-- Example with ox_target or similar targeting system
exports['ox_target']:addBoxZone({
    coords = vector3(-331.0, -780.0, 34.0),
    size = vector3(2, 2, 2),
    rotation = 0,
    options = {
        {
            name = 'open_parking',
            label = 'Open Parking Garage',
            onSelect = function()
                local garage = Config.Garages["sapcounsel"]
                exports['aty_garage']:OpenGarage(garage)
            end
        }
    }
})

Example 4: Store Vehicle via NPC Interaction

-- Example: Store vehicle when player interacts with a custom NPC
RegisterNetEvent('myresource:storeVehicle')
AddEventHandler('myresource:storeVehicle', function()
    local ped = PlayerPedId()

    if IsPedInAnyVehicle(ped, false) then
        local vehicle = GetVehiclePedIsIn(ped, false)

        -- Use the impound garage configuration
        local impoundGarage = Config.Garages["impound"]

        exports['aty_garage']:StoreVehicle(impoundGarage, vehicle)
    end
end)

Example 5: Integration with Job System

-- Example: Police impound function
RegisterCommand('impound', function()
    local ped = PlayerPedId()
    local playerJob = GetPlayerJob() -- Your framework's job getter

    if playerJob ~= "police" then
        return print("You are not authorized to impound vehicles")
    end

    local vehicle = GetVehiclePedIsIn(ped, false)

    if vehicle == 0 then
        -- Get closest vehicle if not in one
        vehicle = GetClosestVehicle(GetEntityCoords(ped), 5.0, 0, 70)
    end

    if vehicle ~= 0 then
        local impoundGarage = {
            label = "Police Impound",
            garage = "impound",
            pedCoords = vector4(408.99, -1622.87, 29.29, 230.40),
            vehicleCoords = vector3(402.28, -1632.41, 29.29),
            heading = 0.0,
            radius = 5.0,
            job = "police",
            blip = { show = false },
            spawnCoords = {
                vector4(396.89, -1643.64, 29.29, 320.61),
            }
        }

        exports['aty_garage']:StoreVehicle(impoundGarage, vehicle)
    end
end, false)

Database State Values

When using these exports, the vehicle's state in the database is managed as follows:

For ESX (es_extended)

State Meaning
stored = 0 Vehicle is out (not in garage)
stored = 1 Vehicle is stored in garage
stored = 2 Vehicle is impounded

For QBCore

State Meaning
state = 0 Vehicle is out (not in garage)
state = 1 Vehicle is stored in garage
state = 2 Vehicle is impounded

Important Notes

[!IMPORTANT] The garage property in the garage configuration table is what determines where the vehicle is stored in the database. Make sure this matches your database records.

[!WARNING] When using OpenGarage, ensure the player is NOT in a vehicle, as the UI is designed for on-foot interaction.

[!TIP] If Config.UseSharedGarages is set to true, players can access their vehicles from any garage location, regardless of where they stored them.


Dependencies

These exports require:

  • aty_lib - Core utility library
  • Properly configured database tables (owned_vehicles for ESX, player_vehicles for QBCore)
ATY Scripts LogoATY SCRIPTS

QBCore & ESX için yüksek optimizasyonlu FiveM scriptleri üretiyoruz. Maksimum performans, hassas kod, sıfır gecikme.

Topluluğa Katıl

Partner

Tebex resmi partneri. Güvenli ödeme ve Cfx.re Keymaster entegrasyonu.

Yasal

Rockstar Games, Cfx.re, FiveM veya Take-Two Interactive ile bağlantılı değildir. Satın alımlar Tebex Hizmet Şartları'na tabidir.

© 2026 ATY SCRIPTS. Tüm hakları saklıdır.