> For the complete documentation index, see [llms.txt](https://5scripts-1.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://5scripts-1.gitbook.io/docs/assets/5s_building/editable.md).

# Editable

## Editable

> **Note:**\
> This documentation describes the functions in the `editable` folders.\
> You are free to modify, extend, or adapt to fit your server's needs.

### Client Side (`client/editable/`)

#### 1. `keyBinds.lua`

**Key Hints System**

* **showKeyHints(type, subType)**\ <sub>Displays key hints for the current editor mode.</sub>
  * <sub>`type`</sub><sub>: Main mode (e.g., "building", "rotate", "doors", "upgrade").</sub>
  * <sub>`subType`</sub><sub>: Optional, for sub-modes.</sub>
* **disableControls()**\ <sub>Disables player controls while editing or upgrading.</sub>

**Keybinds**

* **rotateObjectLeft** (`Q`): Rotates the object left if free rotation is allowed.
* **rotateObjectRight** (`E`): Rotates the object right if free rotation is allowed.
* **flipDoorOpen** (`B`): Flips the open direction of a door/gate while placing it.
* **moveObjectUp** (`F`): Moves the object up when free movement is allowed.
* **moveObjectDown** (`G`): Moves the object down when free movement is allowed.
* **changeObjectPosition** (`H`): Overrides the last edit object position.
* **placeObject** (`MOUSE_LEFT`): Places the currently selected object.
* **selectObject** (`MOUSE_RIGHT`): Opens the object selection menu (regular building pieces).
* **selectObjectSpecial** (`MOUSE_RIGHT`): Opens the object selection menu for special models with `includedInToolBox = true`.
* **upgradeObject** (`MOUSE_RIGHT`): Opens the upgrade menu when in upgrade mode.
* **stopEditing** (`X`): Stops the editing mode and hides key hints.
* **stopUpgrading** (`X`): Stops the upgrade mode.
* **getUpFromChair** (`X`): Gets up from a chair.
* **useDoor** (`E`): Uses a door when not editing or upgrading.
* **manageDoor** (`G`): Opens the door management menu when not editing or upgrading.

**Hints Table**

<sub>Defines which keys are locked and which hints are shown for each mode.</sub>

***

#### 2. `events.lua`

* **stopEditor()**\ <sub>Stops the editor and upgrade modes, re-enables controls, and hides the UI.</sub>\ <sub>Called automatically on player death events.</sub>

***

#### 3. `chest.lua`

* **OpenChest(chestId)**\ <sub>Opens a chest inventory using the</sub> <sub>`ox_inventory`</sub> <sub>system.</sub>
  * <sub>`chestId`</sub><sub>: The unique identifier of the chest.</sub>

***

#### 4. `doors.lua`

Handles door creation and interaction using `lib.points`. Doors are created via the `5s_building:createDoor` event and use raycasting to detect when the player is looking at a door within range.

* When the player looks at a door within 1.5m, it highlights the door and shows key hints.
* Door data includes the owner, entity, heading, and display state.

> **Note:** If you change doors to use a target system instead, remember to comment out the door keybinds in `keyBinds.lua`.

***

#### 5. `target.lua`

Helper functions for creating and removing target interactions. Supports `ox_target` and `qb-target` based on `5s_lib's config`.

* **createTarget(entity, name, label, icon, onSelect, distance)**\ <sub>Adds a target interaction to an entity.</sub>
* **removeTarget(entity, name)**\ <sub>Removes a target interaction from an entity.</sub>

***

#### 6. `toolbox.lua`

Handles chair interactions. Chairs are registered via the `5s_building:createChair` event and use a target interaction to sit.

* **sitOnChair(id)** - Makes the player sit on a chair using a scenario.
* **getUpFromChair()** - Makes the player get up from the chair.
* Sitting is validated server-side via the `5s_building:canSitOnChair` callback.

***

### Server Side (`server/editable/`)

#### 1. `auth.lua`

* **checkAuthAdmin(src)**\ <sub>Checks if the player (source) has admin authorization.</sub>
  * <sub>Returns</sub> <sub>`true`</sub> <sub>if authorized, otherwise</sub> <sub>`false`</sub><sub>.</sub>
  * <sub>Placeholder for custom admin logic.</sub>

***

#### 2. `inventory.lua`

* **getItemCount(source, itemName)**\ <sub>Returns the count of a specific item in the player's inventory.</sub>
* **removeItem(source, itemName, count)**\ <sub>Removes a specified amount of an item from the player's inventory.</sub>
* **addItem(source, itemName, count)**\ <sub>Adds a specified amount of an item to the player's inventory.</sub>

***

#### 3. `chest.lua`

* **RegisterChest(chestId, slots, weight)**\ <sub>Registers a new chest (stash) in the</sub> <sub>`ox_inventory`</sub> <sub>system.</sub>
  * <sub>`chestId`</sub><sub>: Unique identifier.</sub>
  * <sub>`slots`</sub><sub>: Number of inventory slots.</sub>
  * <sub>`weight`</sub><sub>: Maximum weight.</sub>
* **OpenChest(source, chestId)**\ <sub>Opens a chest for a player using the</sub> <sub>`ox_inventory`</sub> <sub>system (server-side opening).</sub>

***

#### 4. `damage.lua`

Custom damage handlers for structures. Offline raid protection and raid schedule are handled automatically via Config - these callbacks let you add extra logic on top.

* **onStructureExplosionDamage(source, buildingUid, damage, explosionPosition, explosionType)**\ <sub>Called when a structure takes explosion damage. Return</sub> <sub></sub><sub>`true`</sub> <sub></sub><sub>to allow damage,</sub> <sub></sub><sub>`false`</sub> <sub></sub><sub>to block it.</sub>
* **onStructureWeaponDamage(source, buildingUid, damage, weaponHash)**\ <sub>Called when a structure takes weapon damage. Return</sub> <sub></sub><sub>`true`</sub> <sub></sub><sub>to allow damage,</sub> <sub></sub><sub>`false`</sub> <sub></sub><sub>to block it.</sub>

```lua
function onStructureExplosionDamage(source, buildingUid, damage, explosionPosition, explosionType)
    -- returning false will cancel the damage
    return true
end

function onStructureWeaponDamage(source, buildingUid, damage, weaponHash)
    -- returning false will cancel the damage
    return true
end
```

***

#### 5. `toolbox.lua`

Server-side chair management. Prevents multiple players from sitting on the same chair simultaneously.

* Registers the `5s_building:canSitOnChair` callback - returns `true` if the chair is free, `false` if occupied.
* Automatically frees chairs when a player disconnects.

***
