Page 1 of 1
Invemtory Pro - Remove Item
Posted: Tue Aug 27, 2019 6:21 am
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
Re: Invemtory Pro - Remove Item
Posted: Tue Aug 27, 2019 8:50 am
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.
Re: Invemtory Pro - Remove Item
Posted: Tue Aug 27, 2019 10:29 am
by TattooRose
Tony, Thanks for the update.
Re: Invemtory Pro - Remove Item
Posted: Tue Aug 27, 2019 6:04 pm
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.
Re: Invemtory Pro - Remove Item
Posted: Wed Aug 28, 2019 5:03 am
by TattooRose
Thanks for the update. I will pull it into my project and give it a go.
Re: Invemtory Pro - Remove Item
Posted: Wed Aug 28, 2019 6:46 am
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
Re: Invemtory Pro - Remove Item
Posted: Wed Aug 28, 2019 8:09 am
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);
}
}
}
Re: Invemtory Pro - Remove Item
Posted: Wed Aug 28, 2019 10:40 am
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
Re: Invemtory Pro - Remove Item
Posted: Wed Aug 28, 2019 10:43 am
by TattooRose
Nevermind, the update folder was collapsed. I have the file now.
Thanks again,
TattooRose