# events and callbacks

This page documents all client events and NUI callbacks exposed by `moh-jobgarage`.

## Client Events

| Event                               | Parameters            | Description                                                                                                                                                                                                              |
| ----------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `moh-jobgarage:client:OpenMenu`     | `locationId` (number) | <p>Opens the NUI garage menu for the specified location.<br>Called internally by the target interaction on each ped.<br>Can also be triggered from an external script to open a garage programmatically.</p>             |
| `moh-jobgarage:client:SpawnVehicle` | `data` (table)        | <p>Spawns the vehicle described in <code>data</code>, warps the local player into it, applies colors/extras/livery, sets fuel, and gives keys.<br>Called internally from the <code>spawnVehicle</code> NUI callback.</p> |

### Triggering OpenMenu from an external script

```lua
-- Open garage location 3 (Police) for the local player
TriggerEvent('moh-jobgarage:client:OpenMenu', 3)
```

{% hint style="info" %}
Job/gang access checks still run — the player must qualify for the location or they will see an "access denied" notification.
{% endhint %}

## NUI Callbacks

| Callback name  | Triggered by                                 | What it does                                                                                                         |
| -------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `spawnVehicle` | Clicking a vehicle button in the NUI         | Fires `moh-jobgarage:client:SpawnVehicle` with the selected vehicle data, then closes the menu.                      |
| `storeVehicle` | Clicking the Store Vehicle button            | Deletes the active `SpawnedVehicle` entity, resets the reference to `nil`, notifies the player, and closes the menu. |
| `close`        | Clicking the Close button or pressing Escape | Removes NUI focus and hides the menu. No vehicle action is taken.                                                    |

## NUI message — open

When the menu opens, `client.lua` sends the following message to the NUI:

```lua
SendNUIMessage({
    action = 'open',
    title = 'Police Garage', -- ped name
    vehicles = { ... }, -- filtered vehicle list
    hasVehicle = true, -- whether Store button is shown
    logo = 'logos/police.png', -- logo path
    theme = { ... } -- theme color table
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mohssins.gitbook.io/mohscriptsdocs/moh-jobgarage/events-and-callbacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
