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);
}
}
}
Thank you in advance.