> For the complete documentation index, see [llms.txt](https://docs.t1ger.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.t1ger.net/resources/t1ger-library.md).

# T1GER Library

## Note

This resource will be used in all T1GER resources as a dependency. The main purpose of the library is to add configurable support between frameworks, inventories, target systems and etc. for the gameplay resources. All options must be set in `config.lua`.

{% hint style="danger" %}
Do not edit/customize functions if you have no knowledge of LUA and FiveM Coding!
{% endhint %}

## Get Player/Owned Vehicles

This is a function to retrieve all owned vehicles for a player. This function will be used throughout T1GER resources. According to what columns you have in your owned\_vehicles or player\_vehicles table, you might need to update something inside the function.&#x20;

1. Navigate to `t1ger_lib/server/framework.lua`.
2. Find the function named: `GetAllVehicles`.
3. You should see a `table.insert()` function containing the keys and values below:

```lua
table.insert(vehicles, {
    plate = results[i].plate,
    props = results[i].vehicle or results[i].mods,
    type = results[i].type or nil,
    job = results[i].job or nil,
    stored = results[i].stored or results[i].state or nil,
    garage = results[i].garage or results[i].parking or nil,
    impound = results[i].impound or results[i].pound or nil,
    seized = results[i].seized or nil,
    model = results[i].model or nil,
    name = results[i].name or nil,
    category = results[i].category or nil,
    fuel = results[i].fuel or nil,
    engine = results[i].engine or nil,
    body = results[i].body or nil,
})
```

{% hint style="warning" %}
Do not alter the key name, as these key names are used throughout the resources and may break them!
{% endhint %}

4. You can alter the values starting with results\[i] if your table columns are named something else. Look below for examples.

**Example #1: garage column is named `t1ger_garage`.**

```lua
garage = results[i].t1ger_garage
```

**Example #2: stored column is named `parked`.**

```lua
stored = results[i].parked
```

## Update Owned Vehicle

This is a function to update owned vehicle, when the respective vehicle is either spawned or stored from/in a garage. According to what columns you have in your `owned_vehicles` or `player_vehicles` table, you might need to update something inside the function.&#x20;

1. Navigate to `t1ger_lib/server/framework.lua`.
2. Find the function named: `UpdateOwnedVehicle`.

   ```lua
   UpdateOwnedVehicle = function(src, stored, garage, props)
   -- stored (boolean) true/false
   -- garage (string)
   -- props (table)
   ```
3. Do not edit the `'@'` but only the value before the `"="`, as it's the exact column-name from your database table.&#x20;
4. Please read the end-line comments for brief information on the edits you are about to do.
5. Start with updating the SQL string to your server's preferences:
   * is it the correct table?&#x20;
   * is your stored state called: `'stored'`, `'state'`, `'parked'` or something else?
   * do you even have a `'garage'` or `'parked'` column, if not delete it from the SQL string. If you have it, then make sure to name it the same as your table column.&#x20;
   * are you using `'vehicle'`, `'mods'` or something else for vehicle properties? If so, update it!&#x20;
6. After updating the SQL, make sure to update the keys & values inside the MySQL call. Only do this if you've added/removed keys from the SQL string.&#x20;
7. That's it - you are now all set.&#x20;
   * Please note; if your database column for stored uses other value than boolean, then you need to re-code the true/false to return INT or whatever it may be.&#x20;

## Notifications

* You should see a `table.insert()` function containing the keys and values below:

Set the config option `UseFrameworkNotification` to either `true` or `false`. If true, the system will use default ESX or QB notifications. If false, by default it will use ox notifications. Inside utils, you can easily customize/change to your own notification system.

Throughout the gameplay resources, all notification messages will be sent as a table with title, message and type. Integration of your own notifcation system won't get any easier.&#x20;

If you want to parse more data through the notification, then you'd have to find the specific notification in the gameplay resource and add your extra values.

## Create Vehicle Meta

You can use this server sided export to create vehicle meta on spawned vehicles in run-time.

{% hint style="danger" %}
The vehicle must be added to the database as an owned vehicle, when using this. &#x20;
{% endhint %}

```lua
exports['t1ger_lib']:CreateVehicleMeta(plate, src)
```

Parameters:

* plate(string): the plate string of the vehicle to create metadata for.
* src(int): the player handle (player server id)

{% hint style="info" %}
**EXAMPLE #1**&#x20;

This example will make sure that when `/admincar` command is used in `qb-core`, the vehicle in question will have metadata created and synced.&#x20;

```lua
RegisterNetEvent('qb-admin:server:SaveCar', function(mods, vehicle, _, plate)
    local src = source
    if QBCore.Functions.HasPermission(src, 'admin') or IsPlayerAceAllowed(src, 'command') then
        local Player = QBCore.Functions.GetPlayer(src)
        local result = MySQL.query.await('SELECT plate FROM player_vehicles WHERE plate = ?', { plate })
        if result[1] == nil then
            MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state) VALUES (?, ?, ?, ?, ?, ?, ?)', {
                Player.PlayerData.license,
                Player.PlayerData.citizenid,
                vehicle.model,
                vehicle.hash,
                json.encode(mods),
                plate,
                0
            })
            exports['t1ger_lib']:CreateVehicleMeta(plate, src)
            TriggerClientEvent('QBCore:Notify', src, Lang:t("success.success_vehicle_owner"), 'success', 5000)
        else
            TriggerClientEvent('QBCore:Notify', src, Lang:t("error.failed_vehicle_owner"), 'error', 3000)
        end
    else
        BanPlayer(src)
    end
end)
```

{% endhint %}

## Utils

Inside the utils.lua you'll find various functions. Feel free to use these in your resources as you please.
