[HOWTO] How To: Write Custom Quest Action To Start Dialogue

Announcements, support questions, and discussion for Quest Machine.
Post Reply
User avatar
Tony Li
Posts: 20632
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Write Custom Quest Action To Start Dialogue

Post by Tony Li »

Here's a custom quest action that tells a Quest Giver to open the quest dialogue UI onto the current quest:

StartDialogueQuestAction.cs

Code: Select all

using UnityEngine;
using PixelCrushers;
using PixelCrushers.QuestMachine;

public class StartDialogueQuestAction : QuestAction
{
    public StringField questGiverID;

    public override void Execute()
    {
        base.Execute();
        var go = QuestMachineMessages.FindGameObjectWithID(questGiverID);
        var questGiver = (go != null) ? go.GetComponent<QuestGiver>() : null;
        if (questGiver != null)
        {
            questGiver.StartSpecifiedQuestDialogueWithPlayer(StringField.GetStringValue(quest.id));
        }
        else
        {
            Debug.LogWarning($"Can't locate Quest Giver '{questGiverID}' to start dialogue");
        }
    }
}
Post Reply