Page 1 of 1

[SOLVED]Achieve Quest Goal before acquiring it

Posted: Fri Nov 27, 2020 9:56 am
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.

Re: [HELP]Achieve Quest Goal before acquiring it

Posted: Fri Nov 27, 2020 11:25 am
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 523 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.