Page 1 of 1

Adding quests in scripts

Posted: Sun Apr 17, 2016 5:34 am
by mandi
Hello Tony,
I want to make a dynamic quest, where the player has to kill certain number of monsters (the number is not arbitrary, may vary depending on the spawner). I use events to track the number of spawned and killed monsters. Now, I want to feed this info to the quest I generate at runtime. The problem is the quest does not appear as tracked, although it is set as such - I don't even know whether it was generated (where to check this?).

My code looks like this:

Code: Select all

void SetKillQuest()
	{
		QuestLog.AddQuest (mKillQuestName, mKillQuestDesc);
		QuestLog.SetQuestState (mKillQuestName, PixelCrushers.DialogueSystem.QuestState.Active);
		QuestLog.SetQuestTracking (mKillQuestName, true);
	}

	void UpdateKillQuest()
	{
		mKillQuestDesc = "Kill " + (DialogueLua.GetVariable ("NoEnemiesToKill").AsInt - DialogueLua.GetVariable ("NoEnemiesKilled").AsInt) + " enemies.";
		QuestLog.SetQuestDescription (mKillQuestName, QuestState.Active, mKillQuestDesc);

		if (DialogueLua.GetVariable("NoEnemiesKilled").AsInt >= DialogueLua.GetVariable("NoEnemiesToKill").AsInt )
			QuestLog.SetQuestState (mKillQuestName, PixelCrushers.DialogueSystem.QuestState.Success);
	}


Re: Adding quests in scripts

Posted: Sun Apr 17, 2016 10:57 am
by Tony Li
Hi,

Quests have two fields related to tracking:
  • Trackable: Specifies tracking is allowed to be turned on or off. If Trackable is false, then this quest cannot be tracked.
  • Track: Specifies whether to currently track the quest in the quest tracker HUD. (Trackable must also be true in this case.)
In version 1.6.1.1 and earlier, the QuestLog.SetQuestTracking() method does not set Trackable. It only sets Track. I realized recently that, while there is a method to check the value of Trackable (QuestLog.IsQuestTrackingAvailable), there was no equivalent method to set Trackable. I've already added this in the patch available on the Pixel Crushers customer download site.

If you don't want to import the patch, you can add this line to your code:

Code: Select all

void SetKillQuest()
{
      QuestLog.AddQuest (mKillQuestName, mKillQuestDesc);
      QuestLog.SetQuestState (mKillQuestName, PixelCrushers.DialogueSystem.QuestState.Active);
      
      DialogueLua.SetQuestField (mKillQuestName, "Trackable", true); //<-- ADD THIS.
      
      QuestLog.SetQuestTracking (mKillQuestName, true);
} 
If you have a quest log window, you can open it to see if the quest is listed in the Active quests section. If Trackable is not true, it won't have a Track toggle button.

You can also check the internal values of the quest by using a Lua Console. For example, if your quest is called "Kill 3 Orcs", enter this in the Console:

Code: Select all

return Quest["Kill_3_Orcs"]
I like to put counters in quest entries so they appear in the HUD underneath the main quest header. It's just personal preference. If you'd like to do the same, you can add code like this:

Code: Select all

void SetKillQuest()
{
      QuestLog.AddQuest (mKillQuestName, mKillQuestDesc);
      QuestLog.SetQuestState (mKillQuestName, PixelCrushers.DialogueSystem.QuestState.Active);
      QuestLog.SetQuestTracking (mKillQuestName, true);
      
      // ADD THIS:
      DialogueLua.SetVariable("NoEnemiesToKill", 3);
      DialogueLua.SetVariable("NoEnemiesKilled", 0);
      QuestLog.AddQuestEntry(mKillQuestName, "Kill [lua(Variable['NoEnemiesToKill']-Variable['NoEnemiesKilled'])] enemies.");
      QuestLog.SetQuestEntryState(mKillQuestName, 1, QuestState.Active);
}

void UpdateKillQuest()
{
       // ADD THIS to tell the quest tracker HUD to update its display:
       DialogueManager.SendUpdateTracker();

       if (DialogueLua.GetVariable("NoEnemiesKilled").AsInt >= DialogueLua.GetVariable("NoEnemiesToKill").AsInt)
           QuestLog.SetQuestState(mKillQuestName, PixelCrushers.DialogueSystem.QuestState.Success);
} 

Re: Adding quests in scripts

Posted: Sun Apr 17, 2016 11:13 am
by mandi
Tony,
splendid explanation, as usual.
Thanks!

Re: Adding quests in scripts

Posted: Wed Apr 20, 2016 6:37 am
by mandi
I've done what you described, but still can't see my quest as trackable. I've tried to appy patch - is there a new method in there for setting the quest trackable?
Best

Re: Adding quests in scripts

Posted: Wed Apr 20, 2016 10:15 am
by Tony Li
Hi Artur,

The code in my previous post should work.

Please add a Lua Console to your scene. Set the Width and Height to 512.

After your script creates the quest, press ~+L to open the console, and then enter:

Code: Select all

return Quest["Your_Quest_Name"]
where "Your_Quest_Name" is the name of your quest, with underscores ( _ ) instead of blank spaces.

Post a screenshot of the output. I'd like to check whether the "Trackable" and "Track" fields are both being created and set.

Re: Adding quests in scripts

Posted: Fri Apr 22, 2016 4:50 am
by mandi
Tony,
sorry for the delay, I will check that soon and let you know.
Best!

Re: Adding quests in scripts

Posted: Sat Apr 23, 2016 7:17 am
by mandi
Tony,
I was finally able to check it. It works. Just my quest tracker got somehow disabled and I couldn't see any quest being tracked, only in that scene.
Best!

Re: Adding quests in scripts

Posted: Sat Apr 23, 2016 10:17 am
by Tony Li
Just making sure - it's all working correctly now?

Re: Adding quests in scripts

Posted: Sat Apr 23, 2016 10:38 am
by mandi
Tony,
yes, it does. Sorry for the confusion.
Best!

Re: Adding quests in scripts

Posted: Sat Apr 23, 2016 10:40 am
by Tony Li
Great! I'm just glad to hear it's working. :-)