> For the complete documentation index, see [llms.txt](https://atiysus-organization.gitbook.io/aty-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atiysus-organization.gitbook.io/aty-scripts/motels/motels.md).

# Motels

`aty_motels` is a premium FiveM motel system that allows players to purchase motels, rent rooms, hire workers, manage finances, and review motel feedback. It uses routing buckets (instances) to virtualize rooms inside custom shells, supporting various inventory and clothing scripts.

***

### Table of Contents

1. Key Features
2. Dependencies
3. Installation & Database Setup
4. Configuration Reference (`settings/config.lua`)
5. Command Reference
6. Core Technical Mechanics
   * Virtualization (Routing Buckets)
   * NUI Initialization Safety
   * Dynamic Config Reload
   * Shell Loading Safety & Timeout
7. NUI Callback Reference

***

### Key Features

* **Motel Ownership:** Players can buy motels, manage their status (active/inactive), and withdraw motel funds generated by room rentals.
* **Worker Management:** Motel owners can hire other players as workers to manage the motel.
* **Room Rentals:** Customers can rent rooms on an hourly or daily basis.
* **Virtual Stashes and Wardrobes:** Inside each room, renters can open stashes (supporting multiple inventory types) and customize clothing (supporting multiple appearance scripts).
* **Reviews & Ratings:** Rented motel rooms support player feedback with comments and star ratings.
* **Routing Buckets:** Instanced shells allow multiple players to occupy the same room coordinates in different virtual worlds.
* **Live Configuration Reload:** Admins can reload settings instantly without restarting the resource.

***

### Dependencies

The script relies on the following dependencies:

* **`aty_lib`**: Core helper framework.
* **`K4MB1-StarterShells`**: Shell assets for generating room interiors.

***

### Installation & Database Setup

1. Import the corresponding database file to your MySQL database:
   * For **ESX**: Import `db-esx.sql`
   * For **QBCore**: Import `db-qb.sql`
2. Ensure you have the required dependencies started in your `server.cfg` **before** `aty_motels`:

   ```cfg
   ensure aty_lib
   ensure K4MB1-StarterShells
   ensure aty_motels
   ```

***

### Configuration Reference (`settings/config.lua`)

The `settings/config.lua` file is shared between client and server:

#### General Config

| Option                  | Type      | Description                                                                                                                                             |
| ----------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ServerDebug`           | `boolean` | Activates console logging for debugging database queries and event triggers.                                                                            |
| `Inventory`             | `string`  | The active inventory system. Supported: `"ox_inventory"`, `"qb-inventory"`, `"mf-inventory"`, `"lj-inventory"`, `"qs-inventory"`, `"esx_inventoryhud"`. |
| `Clothing`              | `string`  | The active clothing system. Supported: `"esx_skin"`, `"qb-clothing"`, `"fivem-appearance"`, `"illenium-appearance"`, `"ox_appearance"`.                 |
| `OpenCabinetFromServer` | `boolean` | If true, triggers the cabinet stash opening logic from the server side.                                                                                 |

#### Blips Configuration

Customizable blips for motel locations and player-owned rooms:

* **`Blips.Motels`**: Customizes the map blips for all motel complexes. Color shifts dynamically depending on ownership status (Purchasable, Owned by player, or Owned by someone else).
* **`Blips.MyRoom`**: Customizes the blip pointing directly to the rooms rented by the player.

#### Integrations

* **`Config.OpenCabinet(motelId, roomId, src, capacity)`**: Dynamically opens stashes based on the chosen inventory system.
* **`Config.OpenClothing(motelId, roomId, src)`**: Opens the wardrobe customization menu based on the active appearance script.

***

### Command Reference

#### Player Commands

* **`/acceptmotel`**: Accept an invite to join a rented room.
* **`/acceptworkinvite`**: Accept an invite to become a motel worker.

#### Admin Commands

* **`/reloadmotelconfig`**: Reloads `settings/config.lua` on the fly. Sends the updated config string to all clients and executes it. Rebuilds blips dynamically. (Only usable by admins/gods).

***

### Core Technical Mechanics

#### 1. Virtualization (Routing Buckets)

When a player enters a room, the server assigns them a unique routing bucket using the pattern `motelId-roomId`. This prevents players inside different rooms of the same motel from seeing or colliding with each other. When exiting, the player's routing bucket is reset to the default (`0`).

#### 2. NUI Initialization Safety

To prevent menu data from being lost during UI startup:

* The UI triggers a `loaded` callback once Vue mounts.
* Client callbacks `openMotelMenu` and `openManagementMenu` verify `UILoaded` is true and execute a slight delay (`Wait(150)`) before sending data payloads via `SendNUIMessage`.

#### 3. Dynamic Config Reload

The admin command `/reloadmotelconfig` uses the Lua functions `load()` and `LoadResourceFile()` to dynamically reload client and server-side configurations. This synchronizes logic changes and updates map blips instantly without resource restarts.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://atiysus-organization.gitbook.io/aty-scripts/motels/motels.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.
