Custom Quest Actions

Announcements, support questions, and discussion for Quest Machine.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Custom Quest Actions

Post by GorkaGames »

Hi,

I'm coding my own Quest Actions and Conditions to communicate with my scripts. I've done 4 so far and work great.
But one thing that I want to do also on those Quest Action is to write into the Dialogue Text, Journal and HUD, so I can do it populating data from the code.
How do I call them from the Quest Action? I don't find how to do it and what classes to use it (there are son many :)

Thanks,
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Can you give me an example of data and how you want it to appear in the UIs?
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Yes sure,

What I want is the following:

In Active State Node I use my own Custom Quest Action, for instance to communicate with my chest and send "Active" state so the chest shows up in scene with the HUD activated and the trigger activated so the player can open it.

What I want it's try to avoid to write on every node as less as possible, so I'd love to have on this custom Quest Action access to the HUD and Journal and show for example: "Now go to find the chest". What I want is to be able to write this from my custom Quest Action script instead than from the Quest Machine Node Editor (I don't want to fill all info manually in the active state for Hud, Journal, Notifications, etc... as it's quite time consuming for long quests....

Same for my own Custom Quest Condition, where I'd love to have on this custom Quest Condition access to the HUD and Journal and show for example: "Chest Opened!... "

I have tried to access from code to Hud and Journal and I don't find how to do it...
Thanks
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

That's not the way Quest Machine is designed. You can do this for alerts, but not for the HUD or Journal.

When Quest Machine updates the HUD or Journal, it collects all of the UI content for the current state. And that's all it shows.

You could make a subclass of UnityUIQuestHUD and override the RefreshNow() or AddContent() method to add more to the UIs, but it would be complicated.

It might be better if I make it easier to fill in UI content. What features would make it easier for you to fill in the UI content?
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Ok, and is there any chance to update the UI content from code? Just in the state where the action and Condition Chest script is located?
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

GorkaGames wrote: Tue Feb 19, 2019 11:48 am Ok, and is there any chance to update the UI content from code? Just in the state where the action and Condition Chest script is located?
Yes. You can do that. You will need to find the right instance of the quest. If it's on the player and you have a reference to the player's QuestJournal, use QuestJournal.FindQuest(). For example:

Code: Select all

var quest = questJournal.FindQuest("Chest Quest");
This will return a Quest object.

If you need to add UI content to a specific node, call Quest.GetNode():

Code: Select all

var node = quest.GetNode("Find Chest");
Then use QuestNode.GetStateInfo() to get the info for a state such as "active":

Code: Select all

var stateInfo = node.GetStateInfo(QuestNodeState.Active);
Then use QuestStateInfo.GetContentList() to get the content list for a specific category:

Code: Select all

var hudContentList = stateInfo.GetContentList(QuestContentCategory.HUD);
Then you can add new QuestContent:

Code: Select all

var content = BodyTextQuestContent.CreateInstance<BodyTextQuestContent>();
content.bodyText = new StringField("Now go find the chest.);
hudContentList.Add(content);
Finally, tell the UIs to refresh so they use the new content:

Code: Select all

QuestMachineMessages.RefreshUIs(this);
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

This looks great and I'm going to check it out right now.
But for being 100% automatic and not relaying on quest and node's names, is there a way to know on which Quest and Node am I located when I write the code from the Action or Condition Quest Script?

I mean if the Action or Condition Quest Script is called from Quest (x) and Node (x), I guess the Action or Condition Quest Script can know witch Quest and Node is the actual...
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Yes. Every QuestAction has quest and questNode properties.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

This is great, testing now.

Is it any way to access the also the counters? Actual and Max values?
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Yes, use Quest.GetCounter(). Example:

Code: Select all

var carrotsCounter = quest.GetCounter("carrots");
Post Reply