# State dependent modules

### custom module config

Each custom module can configure these 3 optional configuration parameters:

| option           | description                                                                                          |
| ---------------- | ---------------------------------------------------------------------------------------------------- |
| enabled-on-state | A string value which defines that this module should only get enabled when the given state is active |
| enable-state     | Tell staff++ to enable this state when the module is executed.                                       |
| disable-state    | Tell staff++ to disable this state when the module is executed.                                      |

### Modes config

In the modes config we can specify which states should be active when entering the mode:

```yaml
modes:
  default:
    ...
    initial-item-states:
    - nightvision-off
```

Using this system we can create modules which are enabled only on certain states.\
Because state changes can be done by staff modules themselves we can create some flexible configurations.

## Examples

### Nightvision modules

We defined 2 modules. 1 for toggling night mode on. And one for turning it off.\
The first module switches the state to `nightvision-on` This state change makes it so that the second module will be enabled and shown inside the player's inventory.\
Vice versa the second module triggers the state to `nightvision-off`

{% code title="custom-modules.yml" %}

```yaml
custom-modules:
  - name: TurnOnNightVisionModule
    enabled: true
    enabled-on-state: nightvision-off
    enable-state: nightvision-on
    disable-state: nightvision-off
    type: COMMAND_STATIC
    item: 
      type: OBSIDIAN
      name: '&bEnables night vision'
      lore: '&7Click to enable night vision'
    commands: 
       - "nightvision on"
  - name: TurnOffNightVisionModule
    enabled: true
    enabled-on-state: nightvision-on
    enable-state: nightvision-off
    disable-state: nightvision-on
    type: COMMAND_STATIC
    item: 
      type: DIAMOND
      name: '&bDisables night vision'
      lore: '&7Click to disable night vision'
    commands: 
       - "nightvision off"
```

{% endcode %}

### Modes config

To configure the mode I did the following:

* disable the default night vision of staff mode
* Disable night vision when exiting staff mode
* Set initial state to night vision off. So when you enter staff mode the obsidian block will be in your inventory
* We defined the module on the same inventory location. Due to the state only one will be shown at a time.

```yaml
modes:
  default:
    # other config here
    ...
    night-vision: false
    disable-commands:
    - command: nightvision off %staff%
    initial-item-states:
    - nightvision-off
    gui:
    - TurnOnNightVisionModule:1
    - TurnOffNightVisionModule:1
```

<figure><img src="/files/WvlP3nUIlssPy16Qb1cG" alt=""><figcaption></figcaption></figure>


---

# 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://wiki.staffplusplus.org/features/staff-mode/custom-staff-modules/state-dependent-modules.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.
