I used chatGPT to write this script and it works fine in the playmaker's action. But I found that when adding items with CanCarryMultiple, it adds a new separate item instead of increasing the quantity of the same item in the same slot. What should I do?
using UnityEngine;
using HutongGames.PlayMaker;
using AC;
[ActionCategory("Adventure Creator")]
[UnityEngine.Tooltip("Adjusts the amount of a specific inventory item in Adventure Creator.")]
public class AdjustInventoryAmountAction : FsmStateAction
{
[RequiredField]
[UnityEngine.Tooltip("The ID of the inventory item to adjust.")]
public FsmInt itemID;
[UnityEngine.Tooltip("The amount to adjust. Positive to add, negative to subtract.")]
public FsmInt amountToAdjust;
public override void OnEnter()
{
// Get the current inventory item
InvItem inventoryItem = KickStarter.inventoryManager.GetItem(itemID.Value);
if (inventoryItem != null)
{
if (amountToAdjust.Value > 0)
{
// Increase the item count
KickStarter.runtimeInventory.Add(itemID.Value, amountToAdjust.Value);
}
else if (amountToAdjust.Value < 0)
{
// Decrease the item count
KickStarter.runtimeInventory.Remove(itemID.Value, Mathf.Abs(amountToAdjust.Value));
}
}
else
{
Debug.LogError("Inventory item with ID " + itemID.Value + " not found.");
}
Finish();
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
RuntimeInventory's Add function is legacy code - for greater control, use the PlayerInvCollection's equivalent instead:
Thank you! It works perfectly!