> For the complete documentation index, see [llms.txt](https://docs.kojascripts.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kojascripts.eu/free/carmarket/exports-and-commands.md).

# Exports & Commands

All public API surface of `koja-carmarket`.

***

## 🖥️ Client exports

### `OpenTablet()`

Open the market tablet UI for the local player. No-op if already open.

```lua
exports['koja-carmarket']:OpenTablet()
```

### `CloseTablet()`

Force-close the tablet UI.

```lua
exports['koja-carmarket']:CloseTablet()
```

### `IsTabletOpen()`

```lua
local open = exports['koja-carmarket']:IsTabletOpen()
if open then ...
end
```

Returns `boolean`.

### `RefreshZone(zoneId)`

Re-fetch and re-spawn vehicles in the given zone. Useful after a manual SQL change or an external script that listed a vehicle.

```lua
exports['koja-carmarket']:RefreshZone('zone1')
```

| Arg      | Type                 |
| -------- | -------------------- |
| `zoneId` | `string` \| `number` |

***

## 🛰️ Server exports

### `GetCarsInZone(zoneId)`

Returns a table of every vehicle currently spawned/listed in the zone, keyed by plate.

```lua
local cars = exports['koja-carmarket']:GetCarsInZone('zone1')
for plate, car in pairs(cars) do
    print(plate, car.owner, car.vehicle)
end
```

| Arg      | Type                 |
| -------- | -------------------- |
| `zoneId` | `string` \| `number` |

Returns `{ [plate] = { owner, vehicle, plate, coords, heading, slot_id }, ... }`.

### `GiveVehicleToPlayer(targetSource, modelName, cb)`

Insert a vehicle directly into a player's garage (ESX `owned_vehicles` or QBCore `player_vehicles`).

```lua
exports['koja-carmarket']:GiveVehicleToPlayer(source, 'zentorno', function(ok, plate)
    if ok then
        print('granted, plate:', plate)
    end
end)
```

| Arg            | Type                                        |
| -------------- | ------------------------------------------- |
| `targetSource` | `int` — player's server ID                  |
| `modelName`    | `string` — spawn name (e.g. `'zentorno'`)   |
| `cb`           | `function(ok: boolean, plate: string\|nil)` |

{% hint style="info" %}
The plate is randomly generated as `XXXXABCD` where `XXXX` is `math.random(4444, 9999)`. Collisions are statistically unlikely but not impossible — handle the error in `cb`.
{% endhint %}

***

## ⌨️ Commands

### `/savecar <model> <playerId>`

Grant a vehicle (by model name) to a player's garage. **Admin only.**

```
/savecar zentorno 4
```

| Permission | ACE group                                          |
| ---------- | -------------------------------------------------- |
| Required   | `Config.Commands.AdminAce` (default `group.admin`) |

Configurable in `shared/config.lua`:

```lua
Config.Commands = {
    AdminAce = 'group.admin',
}
```

***

## 🔔 Client events you can hook into

| Event                                  | When                                                       |
| -------------------------------------- | ---------------------------------------------------------- |
| `koja_carmarket:client:vehicleSold`    | Any vehicle changes hands; arg = plate (string, 1–8 chars) |
| `koja_carmarket:client:auctionUpdated` | Auction state changes; arg = `{ listingId, event }`        |
| `koja_carmarket:client:notifyContact`  | A buyer clicked "Contact seller" on your listing           |

Example:

```lua
RegisterNetEvent('koja_carmarket:client:vehicleSold', function(plate)
    print('Vehicle sold:', plate)
end)
```
