Re: Quest states
Posted: Sun Mar 17, 2019 4:09 pm
I'm getting the same errors I was getting when I tried myself. That is, that the variables in the Custom editor have already been declared.
Support and discussion forum for Pixel Crushers products
https://www.pixelcrushers.com:443/phpbb/
https://www.pixelcrushers.com:443/phpbb/viewtopic.php?t=2127
It varies by game. In some, I've seen that the designer doesn't show a "preempted" indicator. Instead, the conversation simply checks if the quest conditions are met. If so, it goes down an entirely different branch ("I was going to ask you to do X, but I see you already did it! Here's a reward."). I may clean up the example above at some point and put it on the Extras page in case others want to use it.nivlekius wrote: ↑Sun Mar 17, 2019 5:03 pmYay! it works! Thank you so much. I can't be the first person who wanted this? As far as I remember (I never have time to actually play games now) most RPGs seem to work this way. Otherwise, you'd finish the quest before turning it back in to the quest giver.
Another suggestion, but a long read, in case you're interested:nivlekius wrote: ↑Sun Mar 17, 2019 5:07 pmI'm definitely going to rework my inventory and item system some though for the next game... right now I have the quest item picked up in my item script so it checks if it's need for a quest when you add it to inventory. Which is a good way to save resources but it seems clunky and I have to add all kinds of arrays in case it's needed for multiple quests etc.
Code: Select all
Variable["apples"] = Variable["apples"] + 1
UpdateTracker()
if (CurrentQuestState("Pick 3 Apples") == "active" and Variable["apples"] >= 3) then
SetQuestState("Pick 3 Apples", "success")
ShowAlert("Got 3 apples! Good job!")
end
Code: Select all
PixelCrushers.MessageSystem.SendMessage(this, "Picked", "Apple");
Code: Select all
using UnityEngine;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
public class QuestMessageListener : MonoBehaviour, IMessageHandler
{
void Start() // Register for quest messages for all quests in database.
{
foreach (var quest in DialogueManager.masterDatabase.items)
{
if (quest.IsItem) continue; // Not a quest; skip it.
var message = quest.LookupValue("Message");
var parameter = quest.LookupValue("Parameter");
if (string.IsNullOrEmpty(message)) continue; // No message; skip it.
MessageSystem.AddListener(this, message, parameter);
}
}
void OnMessage(MessageArgs messageArgs) // Handle quest messages.
{
foreach (var quest in DialogueManager.masterDatabase.items)
{
if (quest.IsItem) continue; // Not a quest; skip it.
var message = quest.LookupValue("Message");
var parameter = quest.LookupValue("Parameter");
if (messageArgs.Matches(message, parameter)) // Message is for this quest.
{
Lua.Run(quest.LookupValue("MessageAction"));
}
}
}
}
Code: Select all
using System.Collections.Generic;
using PixelCrushers.DialogueSystem;
public class CustomQuestLogWindow : StandardUIQuestLogWindow
{
public override void Awake()
{
base.Awake();
QuestLog.StringToState = CustomStringToState;
}
public static QuestState CustomStringToState(string s)
{
// Treat "preempted" the same as "unassigned":
if (s == "preempted") return QuestState.Unassigned;
else return QuestLog.DefaultStringToState(s);
}
protected override void ShowQuests(QuestState questStateMask)
{
currentQuestStateMask = questStateMask;
// If we're viewing active quests, also include preempted ones, which report as unassigned:
var mask = questStateMask;
if (mask == QuestState.Active) mask = mask | QuestState.Unassigned;
noQuestsMessage = GetNoQuestsMessage(questStateMask);
List<QuestInfo> questList = new List<QuestInfo>();
if (useGroups)
{
var records = QuestLog.GetAllGroupsAndQuests(mask, true);
foreach (var record in records)
{
if (!IsQuestVisible(record.questTitle)) continue;
// If it's really unassigned and not preempted, skip it:
if (QuestLog.CurrentQuestState(record.questTitle) == "unassigned") continue;
questList.Add(GetQuestInfo(record.groupName, record.questTitle));
}
}
else
{
string[] titles = QuestLog.GetAllQuests(mask, true, null);
foreach (var title in titles)
{
if (!IsQuestVisible(title)) continue;
// If it's really unassigned and not preempted, skip it:
if (QuestLog.CurrentQuestState(title) == "unassigned") continue;
questList.Add(GetQuestInfo(string.Empty, title));
}
}
quests = questList.ToArray();
OnQuestListUpdated();
}
}