Custom Conditions

If you want to create new effects or conditions, you can create a new script that inherits from ConditionData or EffectData, and override one of the functions.

Conditions

For example, let's create a new condition that checks how many quests have been completed by the player: ConditionQuestCount.cs

using UnityEngine;
using DialogueQuests;

[CreateAssetMenu(fileName = "condition", menuName = "DialogueQuests/Conditions/QuestCount", order = 10)]
public class ConditionQuestCount : ConditionData
{
    public override bool IsMet(NarrativeEvent evt, NarrativeCondition condition, Actor player, Actor triggerer) 
    {
        //Loop and count completed quests
        int count = 0;
        foreach (QuestData quest in QuestData.GetAll())
        {
            if (quest.IsCompleted())
                count++;
        }

        //Use int operator to compare the number of quests to value_int
        return condition.CompareInt(count, condition.value_int);
    }
    
    public override bool ShowValueInt()
    {
        return true;
    }
    
    public override bool ShowOperatorInt()
    {
        return true;
    }
    
    public override string GetLabelValueInt()
    {
        return "Nb Quests";
    }
}

The loop will count all the completed quests, then the compare int will compare the amount of completed quest to the operator and value defined in the scriptable object data file. The other function explains which value should be visible in the unity inspector. In our case, a int value, and the int operator (to select between: less, greater, equal, not equal...). You can also define the labels that will appear in the unity inspector.

Data Files

We will now create the data files for the condition we just created.

In Unity, right click inside a folder (the other conditions are in the Resources folder), and select Create -> DialogueQuests -> Conditions, select your new condition, it should be named what you set in the tag [CreateAssetMenu] in your new script.

You can now add conditions to any NarrativeCondition in your dialogues and events.

Other Values

If you want to see the list of possible values that can be displayed in the inspector for effects, open the ConditionData.cs script and you will see all the available functions that can be overriden.

Last updated