# Configuration

### Change open key

To change the key that opens the x menu you have to go to the `config.lua` in line 4 and change the key to what ever you want it to be. Be carefuel, you only can chnage it once.

```lua
Config.OpenKey = "X"
```

{% hint style="info" %}
Note: The script's key can only be set during initial installation. Changing it later has no effect on players that already have been using it, becuase the key is saved in their game cache.
{% endhint %}

In `Config.KeyDescription` you can chnage the Description for the Keymapping shown in the GTA Settigs.

## Move while open & click on close

In the config.lua you will notice at the very top you will notice these two options

```lua
Config.CloseMenuOnClick = false
Config.MoveWhileOpen = false
```

But what do they mean?

```lua
Config.CloseMenuOnClick = true
```

If true, the menu closes automaticly after you click a button, if false the menu is still open after clicking. If you only want the x menu to close on certian button, you can add this to the buttons config:

<pre class="language-lua"><code class="lang-lua">execute = function()

<a data-footnote-ref href="#user-content-fn-1">CloseXMenu() </a>          
end
</code></pre>

```lua
Config.MoveWhileOpen = true
```

If true, your controls are still enabled while the menu is open and you can still walk. If false your controls are getting blocked while the menu is open and you cant move.

### Configure the default menu

In the 'Config.Buttons' section, you can set the buttons for the default menu that can be opened by all players if the job lock is inactive. An example is provided in the configuration, but I'll explain it here. You need to add seven elements, named button0 to button6. Button0 is the middle button, which typically serves as a display for the logo and has no function. I'll walk you through how to build one of these 'button elements'.

```lua
['button'] = {
        active = true,
        image = "imgs/image.png",
        hovertext = true,
        text = "TEXT",
        execute = function()
           
        end,
        submenu = {
            active = false
        }
    }
```

#### active

```lua
active = true | false
```

This value determines the button's active status. If set to false, the button will be inactive and not be clickable.

#### image

```lua
image = "pathtoimage/image.png"
```

Here you can configure what image is shown on the button. jp, png, svg are supported. Either put a path to a image in the /html/imgs folder or a direct link to the image. leave it blank for no image.

#### hovertext

```lua
hovertext = true | false
```

Whether you want to show a text while hovering the button or not

#### text

```lua
text = "string" -- max. 8 characters
```

Here you can set the text which is shwon on hover if hovertext = true

#### execute

```lua
execute = function()
           -- execute something if button is clicked
end
```

This function is executed if the button is klicked, you can put anything there

### Submenus

The X Menu supports to set a unique submenu for every button.

```lua
submenu = {
    active = false
}
```

#### How to configure a Submenu?

Just `set active = true` in the submenu section. Now you have to add three Button elements, similar to them in the main menu to the submenu. The names always have to be `button1, button2 and button3`.

#### Heres a example:

{% hint style="info" %}
Note that a submenu button can´t have a submenu itself. Trying todo this will cause errors.
{% endhint %}

```lua
['button1'] = {
    active = true,
    image = "imgs/image.png",
    hovertext = true,
    text = "text",
    execute = function()
        
    end,
    submenu = {
        active = true,
        ['button1'] = {
            active = true,
            image = "imgs/image.png",
            hovertext = true,
            text = "text",
            execute = function()
                
            end
        },
        ['button2'] = {
            active = true,
            image = "imgs/image.png",
            hovertext = true,
            text = "text",
            execute = function()
                
            end
        },
        ['button3'] = {
            active = true,
            image = "imgs/image.png",
            hovertext = true,
            text = "text",
            execute = function()
                
            end
        }
    } 
}
```

## Block the menu

The menu can be blocked under certein circumstances.

#### While player is dead

If you want the x menu to be blocked while the player is dead. You can do this in config.lua line 135 - 138. Just set `Config.BlockMenuIfDead = true` and if not already done configure the events for the death & revive.

```lua
Config.BlockMenuIfDead = true
Config.OnDeathEvent = "esx:onPlayerDeath"
Config.ReviveEvent = "esx_ambulancejob:revive"
Config.PlayerSpawnedEvent = "playerSpawned"
```

#### While player is cuffed, etc.

You can lock the x menu under any circumstance, for example when the player is tied up. You only have to configure the function `ShouldMenuBeLocked()` , for example with an export of your cuff script, so that it returns true if the menu is to be blocked.

{% hint style="info" %}
If not used this function has to return false so the x menu isent locked permanently
{% endhint %}

```lua
function ShouldMenuBeLocked()

    return false
end
```

#### while player is swinning or falling

You can lock the x menu in case the player is falling or swimming at the moment with thes two config options in line 140 & 141:

```lua
Config.LockWhileFalling = true
Config.LockWhileSwimming = true
```

#### exports

You also can lock and unlock the x menu from other scripts whith these exports:

```lua
exports['next-xmenu']:LockXMenu() -- Lock the X Menu
exports['next-xmenu']:UnlockXMenu() -- Unlock the X Menu
exports['next-xmenu']:CloseXMenu() -- Close the X Menu
```

[^1]: Closes the X Menu on button click


---

# 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://docs.nextscripts.pro/x-menu/installation/configuration.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.
