Unable to read stock quantity

fukada

New member
I didn't want to ask a question because it would cause trouble, but I would like to ask.
very sorry.

To use a limit on the quantity of items, we distributed them into categories.
Collection and distribution, limits are working.

I am using an item to run a script, but other actions such as magic and special skills work.

Recovery items are the only ones that don't count correctly in your inventory.
Inventory is "false".

There is no stock in "(main)Default" of "itemcollections", and it is distributed to each item.
"Recovery" items are in stock and can be placed in "HotBar" etc.

Are you checking the number of items in stock using "(main)Default"?
It's empty, are there any settings?スクリーンショット 2024-03-22 094931.pngスクリーンショット 2024-03-22 094952.pngスクリーンショット 2024-03-22 095003.pngスクリーンショット 2024-03-22 095620.pngスクリーンショット 2024-03-22 105152.png
 
Last edited:
I didn't want to ask a question because it would cause trouble, but I would like to ask.
very sorry.
Please do ask questions when you are stuck, I'm here to help however I can.

Are you checking the number of items in stock using "(main)Default"?
That is correct.

Code:
inventory.MainItemCollection
Gets the main item collection, in your case that's "(main)Default". So it will only search for the healing item there. And of course it does not exist in that collection because it is empty.
Instead you should search either the "Recovery" ItemCollection only or the entier Inventory depeneding on your choice.

So you could do:
Code:
inventory.HasItem(......)



OR



var itemCollection = inventory.GetItemCollection("Recovery");


itemCollection.HasItem(.......);


If I understand correctly you are using the item action to heal from the Demo scene. Note that all scripts that is part of the Demo is very specific to it and may not apply to more generic use cases.

If you haven't done so aleready I would highly recommend you dupplicate that ItemAction script to make your own (Make sure to add it in your own folders and not the Opsive folder) then change the code as much as you need

I hope that helps :)
 
I'm sorry for taking up your time.
I'm happy to receive your advice.

I would like to change it to search from everything in the inventory.
"inventory.HasItem(......)"
In the inventory script, there is no HasItem, which results in an error.

>var itemCollection = inventory.GetItemCollection("Recovery");
>itemCollection.HasItem(.......);
The above script counted successfully.

Next, I duplicated the "ItemAction" script and moved it to my own folder.
Is it okay to name the file "ItemAction"?
If changed, many scripts will require renaming.
Also, I don't know where "ItemAction" is called first, so I can't switch to the newly created "ItemAction".

I will continue to try to find a solution myself.
I would be happy if you could give me some advice.
 
Last edited:
You are right the IInventory interface was missing the HasItem functions. I'll add them in the next update.
You could case the inventory to the Inventory type if you want as a workaround for now
Code:
var myInventory = (Inventory)inventory;

//now you can call HasItem
myInventory.HasItem(......)

As for the scripts. You should call it the way that makes the most sense. ItemAction is too generic. Think what does the script do. In this case it's Healing right?

So how about calling it HealingItemAction.cs ?

As for how that item action for healing is called in the demo scene. I explain all that in detail in this video and docs:

I hope that helps!
 
Top