> For the complete documentation index, see [llms.txt](https://docs.menanak47.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.menanak47.com/multi-framework/ak47_garage/events/server.md).

# Server

### Server Net Events

#### `ak47_garage:addgarage`

Inserts a newly created garage into the `ak47_garage` database table and broadcasts the garage to all connected clients.

```lua
TriggerServerEvent('ak47_garage:addgarage', gid, name, polyzone, spawns, setting, reposition, trailerpos)
```

**Parameters**

| Parameter    | Type      | Required | Description                                                     |
| ------------ | --------- | -------- | --------------------------------------------------------------- |
| `gid`        | `string`  | **Yes**  | Unique garage identifier.                                       |
| `name`       | `string`  | **Yes**  | Display name of the garage.                                     |
| `polyzone`   | `table`   | **Yes**  | PolyZone points and height boundaries (`{points, minZ, maxZ}`). |
| `spawns`     | `table`   | **Yes**  | Array of spawn points `{x, y, z, w}`.                           |
| `setting`    | `table`   | **Yes**  | Garage settings object.                                         |
| `reposition` | `vector4` | No       | Boat respawn point (for boat garages).                          |
| `trailerpos` | `vector4` | No       | Truck & trailer parking spot coordinates.                       |

***

#### `ak47_garage:updatesettting`

Updates existing garage settings in the database and synchronizes the change to all online clients.

```lua
TriggerServerEvent('ak47_garage:updatesettting', gid, setting)
```

**Parameters**

| Parameter | Type     | Required | Description             |
| --------- | -------- | -------- | ----------------------- |
| `gid`     | `string` | **Yes**  | Garage identifier.      |
| `setting` | `table`  | **Yes**  | Updated settings table. |

***

#### `ak47_garage:remove`

Deletes a garage and all associated RealParking records from the database and syncs deletion to all clients.

```lua
TriggerServerEvent('ak47_garage:remove', gid)
```

**Parameters**

| Parameter | Type     | Required | Description                  |
| --------- | -------- | -------- | ---------------------------- |
| `gid`     | `string` | **Yes**  | Garage identifier to remove. |

***

#### `ak47_garage:spawnvehicle`

Spawns a vehicle server-side, sets the number plate, deducts parking fees if applicable, sets `stored = 0` in the database, puts the player in the vehicle, and synchronizes with the client.

```lua
TriggerServerEvent('ak47_garage:spawnvehicle', pos, model, plate, type, gid, fee)
```

**Parameters**

| Parameter | Type             | Required | Description                                    |
| --------- | ---------------- | -------- | ---------------------------------------------- |
| `pos`     | `vector4`        | **Yes**  | Spawn position and heading `{x, y, z, w}`.     |
| `model`   | `number\|string` | **Yes**  | Vehicle model hash or name.                    |
| `plate`   | `string`         | **Yes**  | Vehicle license plate.                         |
| `type`    | `string`         | **Yes**  | Vehicle category type.                         |
| `gid`     | `string`         | **Yes**  | Garage identifier where vehicle was retrieved. |
| `fee`     | `number`         | **Yes**  | Accumulated parking fee to charge.             |

***

#### `ak47_garage:unrealparking`

Stores a vehicle into a standard garage, validates ownership, deletes the world entity, removes persistence records, and updates database records with vehicle properties and current timestamp.

```lua
TriggerServerEvent('ak47_garage:unrealparking', nid, mods, plate, gid, trailer)
```

**Parameters**

| Parameter | Type         | Required | Description                        |
| --------- | ------------ | -------- | ---------------------------------- |
| `nid`     | `number`     | **Yes**  | Network ID of the vehicle.         |
| `mods`    | `table`      | **Yes**  | Vehicle modifications table.       |
| `plate`   | `string`     | **Yes**  | Vehicle license plate.             |
| `gid`     | `string`     | **Yes**  | Target garage ID.                  |
| `trailer` | `table\|nil` | No       | Optional trailer properties table. |

***

#### `ak47_garage:setstate`

Generic event to update vehicle stored state in the framework database.

```lua
TriggerServerEvent('ak47_garage:setstate', plate, state, depotprice)
```

**Parameters**

| Parameter    | Type     | Required | Description                                  |
| ------------ | -------- | -------- | -------------------------------------------- |
| `plate`      | `string` | **Yes**  | Vehicle license plate.                       |
| `state`      | `number` | **Yes**  | `0` = Out, `1` = Stored, `2` = Impounded.    |
| `depotprice` | `number` | No       | Optional impound depot price (QBCore / QBX). |

***

#### `ak47_garage:saveVehicleImage`

Saves the FiveManage image URL of a vehicle photo into the database `image` column.

```lua
TriggerServerEvent('ak47_garage:saveVehicleImage', plate, url)
```

**Parameters**

| Parameter | Type     | Required | Description                  |
| --------- | -------- | -------- | ---------------------------- |
| `plate`   | `string` | **Yes**  | Vehicle license plate.       |
| `url`     | `string` | **Yes**  | FiveManage hosted image URL. |

***

#### `ak47_garage:saveModelStats`

Inserts or updates pre-calculated vehicle performance stats in the `ak47_vehicle_stats` database cache.

```lua
TriggerServerEvent('ak47_garage:saveModelStats', modelKey, stats)
```

***

#### `ak47_garage:realparking:clear`

Clears real-parked data and despawns the visual dummy for a specific vehicle plate.

```lua
TriggerServerEvent('ak47_garage:realparking:clear', gid, plate)
```

***

#### `ak47_garage:realparking:unpark_local`

Unparks a real-parked dummy vehicle, deletes the dummy on all clients, creates an active network vehicle at the parking spot, applies mods, and sets `stored = 0`.

```lua
TriggerServerEvent('ak47_garage:realparking:unpark_local', gid, plate, pos, modelHash)
```

***

#### `ak47_garage:persistent:updateState`

Dispatched from client periodically or upon exiting the driver seat to save vehicle location, damage, fuel, engine status, locks, and extended metrics into world persistence.

```lua
TriggerServerEvent('ak47_garage:persistent:updateState', plate, pos, mods, damage, status, fuel, locked)
```

***

#### `ak47_garage:persistent:reportSubmerged`

Dispatched when a vehicle is detected submerged in water or destroyed, immediately triggering auto-impound.

```lua
TriggerServerEvent('ak47_garage:persistent:reportSubmerged', plate)
```

***

### Server Callbacks

Registered via `Lib47.Callback` for client-server RPC requests.

#### `ak47_garage:getvehicles`

Returns all owned vehicles for the invoking player with real-time status and calculated parking fees.

```lua
local vehicles = Lib47.Callback.Await('ak47_garage:getvehicles', nil)
```

***

#### `ak47_garage:getvehiclestats`

Queries the server cache and returns cached performance stats for an array of vehicle models.

```lua
local statsMap = Lib47.Callback.Await('ak47_garage:getvehiclestats', nil, uniqueModelsList)
```

***

#### `ak47_garage:locatevehicle`

Deducts the GPS location fee (`Config.LocateVehicleFee`) and marks the vehicle on the player's minimap if active in the world.

```lua
local success = Lib47.Callback.Await('ak47_garage:locatevehicle', nil, plate)
```

***

#### `ak47_garage:getrescues`

Retrieves all active pending vehicle rescue operations from the server.

```lua
local rescues = Lib47.Callback.Await('ak47_garage:getrescues', nil)
```

***

#### `ak47_garage:rescuevehicle`

Initiates a rescue operation for a stranded vehicle at an impound garage. Deducts the rescue fee, despawns active entities, and either rescues instantly or starts a countdown timer (`Config.RescueVehicle.Timer`).

```lua
local success, result = Lib47.Callback.Await('ak47_garage:rescuevehicle', nil, plate, gid)
```

***

#### `ak47_garage:transfer:garage`

Deducts the destination garage transfer fee and transfers the vehicle to the new garage location.

```lua
local success = Lib47.Callback.Await('ak47_garage:transfer:garage', nil, plate, newGarageId)
```

***

#### `ak47_garage:payimpound`

Deducts the impound release fee, despawns active/persistent entities, clears timers, and sets `stored = 1` in the target impound garage.

```lua
local success = Lib47.Callback.Await('ak47_garage:payimpound', nil, gid, plate, fee)
```

***

#### `ak47_garage:canpark`

Checks if a standard garage has capacity available when `enableparkinglimit` is enabled.

```lua
local canPark = Lib47.Callback.Await('ak47_garage:canpark', nil, gid)
```

***

#### `ak47_garage:canpark:real`

Checks if a RealParking garage has capacity available.

```lua
local canPark = Lib47.Callback.Await('ak47_garage:canpark:real', nil, gid)
```

***

#### `ak47_garage:canpark:housing`

Checks if a house garage has capacity available based on `Config.HousingGarageLimit`.

```lua
local canPark = Lib47.Callback.Await('ak47_garage:canpark:housing', nil, gid)
```

***

#### `ak47_garage:pay:real`

Calculates and deducts the accumulated real-parking hourly fee when unparking a vehicle from a RealParking dummy spot.

```lua
local success = Lib47.Callback.Await('ak47_garage:pay:real', nil, gid, plate)
```

***

#### `ak47_garage:updatename`

Saves a custom vehicle display nickname to the database (`customname` column).

```lua
local success = Lib47.Callback.Await('ak47_garage:updatename', nil, plate, customName)
```

***

#### `ak47_garage:transferOwnership`

Transfers ownership of a vehicle from the sender to the target player server ID.

```lua
local success, message = Lib47.Callback.Await('ak47_garage:transferOwnership', nil, plate, targetServerId)
```

***

#### `ak47_garage:getmods`

Retrieves saved vehicle modifications from the framework database for a vehicle plate.

```lua
local mods = Lib47.Callback.Await('ak47_garage:getmods', nil, plate)
```

***

#### `VehiclePlateChanged`

Server event to notify `ak47_garage` that a vehicle's license plate has been modified by an external resource. Updates server entity plate, persistence caches, database tables, and broadcasts the plate update to all connected clients.

```lua
TriggerServerEvent('ak47_garage:server:VehiclePlateChanged', oldPlate, newPlate)
```

**Parameters**

| Parameter  | Type     | Required | Description                     |
| ---------- | -------- | -------- | ------------------------------- |
| `oldPlate` | `string` | **Yes**  | Previous vehicle license plate. |
| `newPlate` | `string` | **Yes**  | New vehicle license plate.      |

**Example**

```lua
TriggerServerEvent('ak47_garage:server:VehiclePlateChanged', "OLD123", "NEW456")
```
