[SOLVED]Achieve Quest Goal before acquiring it

Announcements, support questions, and discussion for Quest Machine.
Post Reply
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

[SOLVED]Achieve Quest Goal before acquiring it

Post by mschoenhals »

Hi,
I have a quest where the player must find 5 gold bars. I'd like the quest to check the inventory to see if the player has the 5 gold bars already, and if so, set the quest to success and remove the gold bars.

Currently, the player needs to get the quest first and then acquire the bars. I'm using Dialogue Manager and my own custom inventory system. To remove items from inventory, I use:

Code: Select all

namespace PixelCrushers.QuestMachine
{

    /// This is a starter template for custom quest actions. To use it,
    /// make a copy, rename it, and remove the line marked above.
    /// Then fill in your code where indicated below.
    public class RemoveItem : QuestAction // Rename this class.
    {
        [SerializeField] InventoryItem item;

        GameObject player;

        public override void Execute()
        {
            base.Execute();

            var playerInventory = GameObject.FindWithTag("Player").GetComponent<Inventory>();

            if(playerInventory.HasItem(item))
            {
                string itemID = item.GetItemID();  // don't need this except for debugging
                //Debug.Log("remove item ID is " + itemID);
                //remove the item
                int itemSlot = playerInventory.FindItem(item);  //var itemSlot = playerInventory.FindSlot(item) - 2;  // TODO why -2???
                //Debug.Log("item slot of " + item + " is equal to " + itemSlot);
                playerInventory.RemoveFromSlot(itemSlot, 1);
                //playerInventory.RemoveFromSlot(0, 1);
            }
        }
}
How would I set this up in Quest Machine?

Thank you in advance.
Last edited by mschoenhals on Sat Dec 12, 2020 5:47 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP]Achieve Quest Goal before acquiring it

Post by Tony Li »

Hi,

At what point do you want to check if the player has 5 gold bars?

You could check it at the beginning of the Dialogue System conversation. Here's an example:

goldBarsQuest.png
goldBarsQuest.png (19.12 KiB) Viewed 520 times

In the <WaitingToStart> group's Conditions, check if the quest state is "unassigned". If so, it will check its 2 child nodes.

In the first child node's Conditions, check if the player has fewer than 5 gold bars. If so, offer the quest.

In the second child node's Conditions, check if the player has 5 or more bars. If so, give the quest to the player, then immediately set it to success. In the success actions, remove the bars.
Post Reply