# Customized Discoveries Tutorial

In this section I will explain you how to use my plugin [**ConditionalEvents**](https://www.spigotmc.org/resources/conditionalevents-custom-actions-for-certain-events-1-8-1-16.82271/) with **Codex**. ConditionalEvents allows you to assign multiple conditions to a certain event and execute different actions. For example, if a player pickups an item or clicks on a button, something configurable will happen.

So, with my plugin ConditionalEvents you can create as many Codex discoveries you want. Let's suppose you want players to unlock a discovery when they consume an item, for example eat an apple. We create the category and the discovery first:

```yaml
config:
  inventory_items:
    category:
      id: PLAYER_HEAD
      name: "&7Category: #a36bfe&lFood"
      lore:
        - "#eeeeeeInformation about different food you've eaten"
        - ""
        - "&7Unlocked: %unlocked% &8[%progress_bar%&8] &8(&7%percentage%&8)"
    discovery_unlocked:
      id: PAPER
      name: "%name%"
      lore:
        - "%description%"
        - ""
        - "&8Discovered on %date%"
    discovery_blocked:
      id: GRAY_DYE
      name: "&c??"
      lore:
        - "&7You haven't unlocked this discovery yet."
  rewards:
    per_discovery:
      - "centered_message: #a36bfe&m00                                                 00"
      - "centered_message: "
      - "centered_message: #eeeeee&lCODEX UPDATED"
      - "centered_message: &7Food: %name%"
      - "centered_message: "
      - "centered_message: &7Check it now by using #eeeeee/codex"
      - "centered_message: "
      - "centered_message: &7Rewards: &a+50XP"
      - "centered_message: "
      - "centered_message: #a36bfe&m00                                                 00"
      - "title: 20;60;20;#eeeeee&lCODEX UPDATED;&7Food: %name%"
      - "playsound: BLOCK_GILDED_BLACKSTONE_STEP;10;0.1"
      - "console_command: xp give %player% 50"
    all_discoveries: []

discoveries:
  mystery_apple:
    name: "#a36bfe&lMystery Apple"
    description:
    - "&7A mysterious apple found in the cave of"
    - "&7Gashmii. It will give you Strength II for"
    - "&730 seconds."
```

As you can see we have created just one discovery in the category of "Food" (the name of the file could be `food.yml`). Since the discovery can be unlocked only by command, no need to add a `discover_on` option. Now we proceed to create an event with ConditionalEvents:

```yaml
mystery_apple_eat:
    type: item_consume
    conditions:
    - '%item% equals APPLE'
    - '%item_name% equals Mystery Apple'
    actions:
      default:
      - 'give_potion_effect: INCREASE_DAMAGE;600;2'
      - 'console_command: codex unlock %player% food mystery_apple false'
```

This event will check if a player tries to eat an Apple called "Mystery Apple". If so, the Strength potion effect will be given to the player for 600 ticks (30 seconds) and the `/codex unlock %player% food mystery_apple false` command will be executed from the console. This will unlock the discovery we have created for the player. If the player eats a Mystery Apple again, the same command will be executed but nothing will happen since the player has already unlocked the discovery.

The same you can do with multiple events you want. If you are interested on my plugin ConditionalEvents you can check the wiki: [**CLICK HERE**](https://ajneb97.gitbook.io/conditionalevents/)


---

# 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://ajneb97.gitbook.io/codex/customized-discoveries-tutorial.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.
