# Create a Custom Quest Condition

It is not difficult to create custom Quest Condition scripts. Often your game will have unique mechanics, and you may wish to include those in condition comparisons.

Read on to learn more about the anatomy of a Quest Condition Inspector, or visit the pages below to create the required scripts, and then code your first custom Quest Condition.

{% content-ref url="/pages/YNyCemNWAVET74prR3Ka" %}
[Your Quest Condition](/magic-pig-games/game-modules-4/module-documentation/quests/quest-conditions/create-a-custom-quest-condition/your-quest-condition.md)
{% endcontent-ref %}

{% content-ref url="/pages/d2WiNAoj7wV25G0scx7C" %}
[Your Quest Condition Editor](/magic-pig-games/game-modules-4/module-documentation/quests/quest-conditions/create-a-custom-quest-condition/your-quest-condition-editor.md)
{% endcontent-ref %}

{% content-ref url="/pages/7DOWxDoZ4PDDv2SLY7F0" %}
[Your Quest Condition Drawer](/magic-pig-games/game-modules-4/module-documentation/quests/quest-conditions/create-a-custom-quest-condition/your-quest-condition-drawer.md)
{% endcontent-ref %}

## Anatomy of a Quest Condition Inspector

Each Quest Condition may have a different inspector. I've created custom Inspectors for each of the Quest Conditions that ship with Game Modules, however custom Inspectors are not required -- they're just a convenience and look prettier.

We will be looking at the `BlackboardValueNumber` condition.

<figure><img src="/files/44bCVQY9NFbgGvgGLq2y" alt=""><figcaption></figcaption></figure>

This is a "`BlackBoardValueNumber`" `QuestCondition`, which I've named "Gold is 100 or More". The top portion is the custom Inspector, while the bottom portion is the default Inspector. Both accomplish the same thing, and have the same fields exposed.

{% hint style="info" %}
If you create custom Quest Conditions, you can create custom Inspectors, or not -- entirely up to you. If you do choose to create custom Inspectors, you can follow the same pattern explained here.
{% endhint %}

There are three scripts that make up a fully formed Quest Condition which can be viewed in the Editor with a custom Inspector. See full details about creating your own on the pages nested in this section.

### Class which inherits from QuestCondition

The `BlackboardValueNumber` class inherits from `QuestCondition`. This is the class which performs the actual comparison evaluation. The derived class has the opportunity to override a number of methods on the base class, and are required to have their own version of `ConditionMet()`.

```csharp
// Each derived class is required to have this method
public abstract bool ConditionMet(BlackboardNote blackboardNote);

// These can be overridden
public virtual bool ConditionMet<T>(QuestStep questStep, T obj)
public virtual void SaveCurrentValue(GameQuest gameQuest, QuestStep questStep)
public virtual float TrueValue()
public virtual void CompleteQuest()
```

### Editor Class

The `BlackboardValueNumberEditor` class inherits from `QuestConditionEditor`, and is the script which tells Unity to draw a custom Inspector when the `BlackboardValueNumber` object is being viewed.

It overrides the `CreateDrawer()` method, and nothing else. While it does not seem like much, it is required for displaying the custom Inspector.

```csharp
protected override QuestConditionDrawer CreateDrawer()
{
    questConditionDrawer = ScriptableObject.CreateInstance<BlackboardValueNumberDrawer>();
    return questConditionDrawer;
}
```

### Drawer Class

Finally the `BlackboardValueNumberDrawer` class inherits from `QuestConditionDrawer`. This is the class which does the actual drawing of the custom Inspector.

This is using the static class `InfinityPBR.InfinityEditor`, which you can also use to make your own custom Inspectors.

<pre class="language-csharp"><code class="lang-csharp">public override bool CanHandle(QuestCondition questCondition) 
<strong>    => questCondition is BlackboardValueNumber;
</strong>        
protected override void ShowSpecificData(QuestCondition questCondition) 
    => ShowData(questCondition as BlackboardValueNumber);
{
<strong>    // Draw Stuff....
</strong>}
</code></pre>


---

# 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://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/quests/quest-conditions/create-a-custom-quest-condition.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.
