Playmaker action for equipping an item from inventory?

lunzren

New member
Hi, I'm trying to make a weapon shop for my game with playmaker and I need an action that equips an item from the player's inventory. If anyone could help I'd really appreciate it.
 
Equipping items simply mean moving them from the Main item collection to the Equipment item collection.
I belive there should be an action for moving items, or an action for triggering an ItemAction. If not there should be a action to remove and an action to add items. So you could remove the item from the default collection and add it to the equipment collection.

Note that in the next update coming early next month, the Shop Component will have a field you can use to set where the bought item should be added. That might allow you to do what you want without any additional work
 
Thanks I tried doing the add and remove item solution with a pistol but the remove item action isn't working. :(
 
Ah I think I remember someone mentioning a problem with the remove function which I should have fixed a few weeks ago.
Can you download the integration with play maker again just to make sure you have the latest?
If it still doesn't work I'll look into in more detail.
 
I'm sorry... Turns out I updated the Behaviour Designer task but forgot to fix it in the PlayMaker task.

Here is the function to change in the "RemoveItem.cs" script within the integration:
Code:
/// <summary>
/// Removes the item.
/// </summary>
public void DoRemoveItem()
{
    if (m_Inventory == null) { Fsm.Event(m_FailEvent); return; }
    ItemInfo? itemInfoToRemove;
    ItemInfo itemInfoRemoved;
    
    var itemCollection = m_Inventory.GetItemCollection(m_ItemCollectionPurpose);
    if (itemCollection != null) {
        
        itemInfoToRemove = itemCollection.GetItemInfo(m_ItemDefinition);
        if (itemInfoToRemove == null) {
            Fsm.Event(m_FailEvent);
            return;
        }
        
        itemInfoRemoved = itemCollection.RemoveItem((m_Amount.Value, itemInfoToRemove.Value));
      
    } else {
        itemInfoToRemove = m_Inventory.GetItemInfo(m_ItemDefinition);
        if (itemInfoToRemove == null) {
            Fsm.Event(m_FailEvent);
            return;
        }
    
        itemInfoRemoved = m_Inventory.RemoveItem((m_Amount.Value, itemInfoToRemove.Value));
    }
    if (itemInfoRemoved.Amount != 0) {
        Fsm.Event(m_SuccessEvent);
    } else {
        Fsm.Event(m_FailEvent);
    }
}

For equipping and unequipping another task you could have used is the "UseItemFromInventory". That allows you to use Item Actions from a task. So if you have already an ItemAction for Equipping and Unequiping items in the UI than you could use the same ItemAction in this task.

It is preferable to move items between item collections rather than remove and add such that your item can keep its unique ID and all its unique runtime attribute values.

I'll update the PlayMaker integration as soon as possible with the change shown above.
 
Yesssss! Thanks, it works great! :D

Also thanks for integrating with playmaker it was fun learning and putting this together! :)
 
I had a question about a different action if you don't mind me asking.

In the "Has taken damage" action is there a way I can store the attacker as a variable once it updates with a game object? I want to use it in the give currency action.

And the reason I want to do it like that is because I don't want it set to only give currency to one object. Sorry if it's confusing ?
 
Last edited:
I assume you are refering to a task within the character controller play maker integration correct?
I'm not as familiar with those since I work mainly on the Ultimate Inventory System.
But looking at the code I saw there was a public "Attacker" field:
Code:
[Tooltip("Detects when the agent has taken damage.")]
    [ActionCategory("Ultimate Character Controller")]
    public class HasTakenDamage : FsmStateAction
    {
        [Tooltip("A reference to the character. If null it will be retrieved from the current GameObject.")]
        public FsmOwnerDefault m_TargetGameObject;
        [Tooltip("The GameObject that caused the damage.")]
        public FsmGameObject m_Attacker;
        [Tooltip("Event sent when the target has taken damage.")]
        public FsmEvent m_DamagedEvent;
        [Tooltip("Event sent when the target has not taken damage.")]
        public FsmEvent m_NotDamagedEvent;
        [Tooltip("Should the status be checked every frame?")]
        public bool m_EveryFrame;
So I assume that's what you a looking for?

So when the "DamagedEvent" happens you could get that "Attacker" gameobject and from there you can give it currency.
I'm not very familiar with PlayerMaker so I'm not sure how easy that is to do, but I would assume it is possible.
I hope that helps :)
 
Top