# Elevator script

🚪 Vespucci Elevators System

### Overview

The **Vespucci Elevator System** (`cfx_gn_vespucci_elevator_script`) allows players to **use elevators seamlessly without teleportation**.\
The system automatically configures itself on startup and integrates perfectly with interaction frameworks.

***

### ⚙️ Setup

1. **Start the resource:**

   ```lua
   ensure cfx_gn_vespucci_elevator_script
   ```
2. That’s it — everything is configured automatically.\
   If you prefer teleportation-based elevators, simply **do not start this resource**.

***

### 🧭 Teleportation vs. Physical Elevators

| Mode                            | Description                                                             | How to Enable                                              |
| ------------------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------- |
| **Non-Teleportation (default)** | Elevators move physically without teleporting the player.               | Start the `cfx_gn_vespucci_elevator_script` resource.      |
| **Teleportation**               | The classic mode where players are instantly teleported between floors. | Do **not** start the resource; manage entitysets manually. |

{% hint style="info" %}
Please note you can disable the whole interaction by setting true to Elevator.Config.DisableInteraction in the config file of the elevator script. You will need to enable the static elevator.
{% endhint %}

#### How to enable static elevator?

In \`cfx\_gn\_vespucci\_pd\`, you can enable the entities missing in the \`Config.lua\` by setting true to Config.StaticElevators.

***

### 🧩 Interaction Integration Example

You can register your own interactions with elevators by using the built-in exports from `gn_elevator`.

```lua
function LoadVespucciInteractions()
    if GetResourceState("cfx_gn_vespucci_elevator_script") ~= "started" then return end

    local gnElevator = exports.cfx_gn_vespucci_elevator_script
    local elevators = gnElevator:GetElevatorConfigs()

    for elevatorId, elevator in pairs(elevators) do
        -- Register each floor panel
        for id, floorCfg in pairs(elevator.floors) do
            RegisterInteractionSpot("elev_panel_" .. elevatorId .. "_" .. id, floorCfg.panel + vec3(0, 0, 1.25), {
                point = { text = "call", distance = 5.0 },
                canLoad = function()
                    return gnElevator:GetElevatorCurrentFloor(elevatorId) ~= id and not gnElevator:IsInAnyElevator()
                end,
                onInteract = function()
                    gnElevator:CallElevator()
                end
            })
        end

        -- Register lift interaction
        RegisterInteractionModel(elevator.model, {
            point = { text = "use", distance = 5.0 },
            offset = elevator.insidePanelOffset,
            skipVisionCheck = true,
            skipRoomCheck = true,
            canLoad = function()
                return gnElevator:IsInAnyElevator()
            end,
            onInteract = function()
                gnElevator:OpenElevatorKeypad()
            end
        })
    end
end
```

***

### 🔐 Access Control

You can restrict or allow access to be call from specific floors per player.

| Function                                                  | Description                                                           |
| --------------------------------------------------------- | --------------------------------------------------------------------- |
| `CanPlayerAccessFloor(elevatorId, floorIndex)`            | Returns whether a player has permission to go to the specified floor. |
| `SetPlayerAccessFloor(elevatorId, floorIndex, canAccess)` | Grants or removes access to a floor for the current player.           |

***

### 📦 Exported Functions

Below is the complete list of available exports for integration with other scripts.

| Export                                       | Arguments           | Returns             | Description                                                  |
| -------------------------------------------- | ------------------- | ------------------- | ------------------------------------------------------------ |
| **`OpenElevatorKeypad()`**                   | none                | –                   | Opens the keypad UI inside an elevator.                      |
| **`CallElevator()`**                         | none                | –                   | Calls the elevator to the current floor.                     |
| **`GetElevatorCurrentFloor(elevatorId)`**    | `string elevatorId` | `number floorIndex` | Gets the current floor of a specific elevator.               |
| **`IsInElevator(elevatorId)`**               | `string elevatorId` | `boolean`           | Returns whether the player is currently in a given elevator. |
| **`IsInAnyElevator()`**                      | none                | `boolean`           | Returns `true` if the player is in *any* elevator.           |
| **`SetElevatorInteractionEnabled(enabled)`** | `boolean enabled`   | –                   | Enables or disables all elevator interaction.                |

***

### 🧠 Notes

* The system dynamically links to the main `cfx_gn_vespucci_elevator_script` resource.
* Each elevator’s floor and model information is automatically discovered.
* Interactions can be safely added or removed at runtime.
* Access control allows complex logic (e.g. jobs, keycards, staff, etc.).


---

# 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://gnstudio.gitbook.io/doc/los-santos/vespucci-police-department/elevator-script.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.
