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

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:

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

Example 2: Open Garage from a Custom Command

Example 3: Open Garage from a Target Interaction

Example 4: Store Vehicle via NPC Interaction

Example 5: Integration with Job System


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)

Last updated