Invemtory Pro - Remove Item

Announcements, support questions, and discussion for Quest Machine.
Post Reply
TattooRose
Posts: 21
Joined: Wed May 15, 2019 7:42 am

Invemtory Pro - Remove Item

Post by TattooRose »

Hi Tony,

I would like to ask how do I remove an item from the Inventory Pro inventory. I am using the Inventory Pro Item Quest Action in my quest and that works fine.

Any help will be appreciated,
TattooRose

My environment is:

Unity Version 2019.2.0f1
Adventure Creator Version 1.68.4
Inventory Pro Version: 2.5.16
Dialogue System Version: 2.1.10
Quest Machine Version: 1.1.12
Invector Third Person Controller Version: 1.3.2
Invector FSM AI Template Version: 1.0.1
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Invemtory Pro - Remove Item

Post by Tony Li »

Hi,

I'm out of the office at the moment, but when I get back I'll add the updated Inventory Pro Support package in the Quest Machine update that's pending on the Asset Store to the Extras page. It adds an Add/Remove dropdown to the item quest action.
TattooRose
Posts: 21
Joined: Wed May 15, 2019 7:42 am

Re: Invemtory Pro - Remove Item

Post by TattooRose »

Tony, Thanks for the update.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Invemtory Pro - Remove Item

Post by Tony Li »

I was thinking of another integration with the Add/Remove dropdown. To remove items with the Inventory Pro integration, import the updated support package from Extras. Then specify a negative amount to remove items. See the demo scene's Lemonade quest for an example. When you turn in the quest, the NPC removes 2 lemons and gives the player gloves.
TattooRose
Posts: 21
Joined: Wed May 15, 2019 7:42 am

Re: Invemtory Pro - Remove Item

Post by TattooRose »

Thanks for the update. I will pull it into my project and give it a go.
TattooRose
Posts: 21
Joined: Wed May 15, 2019 7:42 am

Re: Invemtory Pro - Remove Item

Post by TattooRose »

Hi Tony,

I started a new project and included the following packages in it.
Unity Version 2019.2.0f1
Inventory Pro Version: 2.5.16
Quest Machine Version: 1.1.12

I then ran the third party support package from COMMON and QUEST MACHINE for INVENTORY PRO.

Then I downloaded the updated package from Extras and imported that into the project.

When all was complete I opened the demo quest scene and ran it. I received the quest from the villager and proceeded to
pick up lemons. I collected 4 and returned to the villager. At that point I queried my inventory and discovered that the lemons did not reduce by 2.

I then placed a bread point in the Execute method of InventoryProItemQuestAction and began to walk the code. What I discovered was that the InventoryProUtility RemoveItem method was not being called. Not sure if that was the method you intended to use to remove items.

I then edited the Execute switch case with the following just to see if that would work. Here is the code sample.

case SetCounterValueQuestAction.Operation.SetToValue:
InventoryProUtility.AddItem(StringField.GetStringValue(itemName), operationValue);
break;
case SetCounterValueQuestAction.Operation.ModifyByValue:
var currentAmount = InventoryProUtility.GetItemCount(StringField.GetStringValue(itemName));
if (operationValue >= 0)
{
InventoryProUtility.AddItem(StringField.GetStringValue(itemName), currentAmount + operationValue);
}
else
{
InventoryProUtility.RemoveItem(StringField.GetStringValue(itemName), operationValue);
}

break;
case SetCounterValueQuestAction.Operation.Randomize:
InventoryProUtility.AddItem(StringField.GetStringValue(itemName), Random.Range(0, operationValue + 1));
break;

After the edit I re-ran the demo with the same lemon count and the result was that instead of 4 lemons I ended up with no lemons in my inventory. Not sure what the remove method is doing in Inventory Pro as my value to modify was -2 so I should have had at least 2 lemons left.

This is just what I have experienced so if I am doing something wrong could you please advise me.

Thanks for you quick turn arounds and support.
TattooRose
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Invemtory Pro - Remove Item

Post by Tony Li »

Hi,

That looks like an old version of the script. Please double check that you've imported QM_InventoryProSupport_2019-08-27.unitypackage last.

In fact, to be on the safe side, delete this folder before importing the package: Assets / Pixel Crushers / Quest Machine / Third Party Support / Inventory Pro Support.

The up-to-date version of the script should look like this:

InventoryProItemQuestAction.cs

Code: Select all

// Copyright © Pixel Crushers. All rights reserved.

using UnityEngine;
using Devdog.General;
using Devdog.InventoryPro;

namespace PixelCrushers.QuestMachine
{

    /// <summary>
    /// Adds or removes items.
    /// </summary>
    public class InventoryProItemQuestAction : QuestAction
    {

        #region Serialized Fields

        [Tooltip("Character collection name (e.g., 'Character') of player whose stat to set. Leave blank for default player.")]
        [SerializeField]
        private StringField m_player = new StringField();

        [SerializeField]
        private StringField m_itemName = new StringField();

        [Tooltip("Set an absolute amount or modify the current amount?")]
        [SerializeField]
        private SetCounterValueQuestAction.Operation m_operation;

        [Tooltip("New amount.")]
        [SerializeField]
        private QuestNumber m_amount = new QuestNumber(1);

        #endregion

        #region Public Properties

        private StringField player
        {
            get { return m_player; }
            set { m_player = value; }
        }

        public StringField itemName
        {
            get { return m_itemName; }
            set { m_itemName = value; }
        }

        public SetCounterValueQuestAction.Operation operation
        {
            get { return m_operation; }
            set { m_operation = value; }
        }

        public QuestNumber amount
        {
            get { return m_amount; }
            set { m_amount = value; }
        }

        #endregion

        public override string GetEditorName()
        {
            if (StringField.IsNullOrEmpty(itemName)) return "Inventory Pro Item Quest Action";
            return "Inventory Pro " + itemName + " " + operation + " " + amount.GetEditorName(quest);
        }

        public override void Execute()
        {
            base.Execute();
            var operationValue = amount.GetValue(quest);
            var itemNameValue = StringField.GetStringValue(itemName);
            if (QuestMachine.debug) Debug.Log("Quest Machine: InventoryProItemQuestAction: " + itemName + " " + operation + " " + operationValue + ".", quest);
            switch (m_operation)
            {
                case SetCounterValueQuestAction.Operation.ModifyByValue:
                    AddRemoveAmount(itemNameValue, operationValue);
                    break;
                case SetCounterValueQuestAction.Operation.SetToValue:
                    SetAmount(itemNameValue, operationValue);
                    break;
                case SetCounterValueQuestAction.Operation.Randomize:
                    SetAmount(itemNameValue, Random.Range(0, operationValue + 1));
                    break;
            }
        }

        private void AddRemoveAmount(string itemNameValue, int operationValue)
        {
            if (operationValue < 0)
            {
                InventoryProUtility.RemoveItem(itemNameValue, -operationValue);
            }
            else
            {
                InventoryProUtility.AddItem(itemNameValue, operationValue);
            }
        }

        private void SetAmount(string itemNameValue, int operationValue)
        {
            var currentAmount = InventoryProUtility.GetItemCount(itemNameValue);
            AddRemoveAmount(itemNameValue, operationValue - (int)currentAmount);
        }
    }

}
TattooRose
Posts: 21
Joined: Wed May 15, 2019 7:42 am

Re: Invemtory Pro - Remove Item

Post by TattooRose »

Hi Tony,

Thanks for the reply.

When I go to Extras I do no see the package QM_InventoryProSupport_2019-08-27.unitypackage.

I followed the link from the previous response. Could you point me in the right direction.

Thanks,
TattooRose
TattooRose
Posts: 21
Joined: Wed May 15, 2019 7:42 am

Re: Invemtory Pro - Remove Item

Post by TattooRose »

Nevermind, the update folder was collapsed. I have the file now.

Thanks again,
TattooRose
Post Reply