New to this plugin, and I needed some help

Dahrona

Member
So I'm currently making a shopkeeping game, where you'll need to craft an item and sell it to NPCs. Here are the features I need to work on:
1. If you click on an empty item slot, it will show the inventory panel, and click on an item in it to put it in that slot.
2. If you click on an occupied slot, it will ask you to switch the item (open the inventory panel again), retrieve it, or move it to the other slot (I think this one is possible using Item Action)

And here are my problems:
1. Do I need to create 2 inventories? Like, 1 for player and 1 for the shop? Or I just need to create 1 and specify the item to "secondary", and filter it? Because after you put it in shop, it will not appear in the inventory.

2. This question is probably tied to the 1st question. The NPC will pick a random item from every occupied slots, with the 2 slots on the left side will have a slightly higher probability to be picked than 12 slots on the middle and right. I'll need to retrieve the slot data and the item in it. It will disappear on the shop after you successfully sold it to that NPC. Any idea how to do it?

3. Is it possible to make an Item Action when the slot is empty? If possible, how to do it?

4. The item slot design on the "shop shelf" isn't specifically a grid. It goes roughly like this:Screenshot 2022-08-23 083013.png

I'm using the original inventory design template. I've disabled the grid layout property, and I've explicitly specify the navigation, because I need this to work on controller. But when I played the game, it resets to the original navigaton. How do I fix this? Or do I need to create a custom script/design for it? If so, how to do it?

1661218746039.png

I really apreciate every answer to my questions. Thanks.
 
1. Do I need to create 2 inventories? Like, 1 for player and 1 for the shop? Or I just need to create 1 and specify the item to "secondary", and filter it? Because after you put it in shop, it will not appear in the inventory.
That depends on how you want to organize your items. But for your use case, I think what makes the most sense are too Inventories. One for the player and one for the shop.
Then if you want to show the contents for the shop, then use another Inventory UI to show those items.

2. This question is probably tied to the 1st question. The NPC will pick a random item from every occupied slots, with the 2 slots on the left side will have a slightly higher probability to be picked than 12 slots on the middle and right. I'll need to retrieve the slot data and the item in it. It will disappear on the shop after you successfully sold it to that NPC. Any idea how to do it?
I'm not sure what you are trying to achieve. Correct me if I'm wrong. You simply want to loop through all your ItemViewSlots and choose a random one correct with the two on the left having a higher probability?
Essentially you want a weighted probability table. For that you want to make a custom script that takes in a list of (object, priority). Sum the priorities, then choose a random value between 0 and the sum. Loop through the list and add the priorities in a counter. once the priority is count is higher than your random value that's the selected object.
There are other ways to do it, check online: https://stackoverflow.com/questions/46563490/c-sharp-weighted-random-numbers

3. Is it possible to make an Item Action when the slot is empty? If possible, how to do it?
Yes. Simply untick the option to "m_DisableActionOnEmptySlots" on your "ItemViewSlotsContainerItemActionBinding"
And make sure that your ItemAction condition does not return false when the item is null.

4. The item slot design on the "shop shelf" isn't specifically a grid. It goes roughly like this:

I'm using the original inventory design template. I've disabled the grid layout property, and I've explicitly specify the navigation, because I need this to work on controller. But when I played the game, it resets to the original navigaton. How do I fix this? Or do I need to create a custom script/design for it? If so, how to do it?
The Unity navigation is determined by the "Layout Group Navigation". This uses a GridLayout to automatically set the navigation of its children.
Either remove that script or disable it
1661242262928.png

Best of luck!
 
I think what makes the most sense are too Inventories. One for the player and one for the shop.
Then if you want to show the contents for the shop, then use another Inventory UI to show those items.
Thanks, I'll use 2 inventories then. I'll refer to the storage system demo and documentation for it.
Edit: Just realized that the storage system in the demo moves the item from inventory to the storage directly to the lowest empty ItemSlot index. How do I move it directly to a specific slot though?
Correct me if I'm wrong. You simply want to loop through all your ItemViewSlots and choose a random one correct with the two on the left having a higher probability?
Yeah, as simple as that. ItemViewSlot does contains the item data inside it, right? Or is it saved on the inventory database? How can I check if the slot is empty? I might be missing this but can you link me to the documentation page? You know that you can't buy the item if it doesn't exist

Also, thanks for the 3rd and 4th answers, it's now working as intended
 
Last edited:
Thanks, I'll use 2 inventories then. I'll refer to the storage system demo and documentation for it.
Edit: Just realized that the storage system in the demo moves the item from inventory to the storage directly to the lowest empty ItemSlot index. How do I move it directly to a specific slot though?
In the ItemViewSlotContainer you have functions to specify in which slot you wish to put the item in. That's how we make it work for drag and drop, because it knows in which index it should place the item that is dropped.
When adding to an ItemCollection, you cannot specify an index, because there are none (Except for the ItemSlotCollection or custom ItemCollections).

Yeah, as simple as that. ItemViewSlot does contains the item data inside it, right? Or is it saved on the inventory database? How can I check if the slot is empty? I might be missing this but can you link me to the documentation page? You know that you can't buy the item if it doesn't exist
Yes. The itemViewSlot contains an ItemView and the ItemView contains the ItemInfo.

Careful, you might misunderstand the database. That's a static object containing the ItemDefinitions, categories ect... that you make during edit time.
The InventorySystemManager is the component that manages all the items in the game. But unlesss you have the item ID you won't be able to find that item in the manager because there can be many of the same item (except for non-Unique and Immutable items, since they share the same reference).
To check if it is empty do: (code not tested)
Code:
if(itemViewSlot.ItemInfo == ItemInfo.None){
//Its empty.
}

The source code is fully commented, so you can simply open the relevant script and scroll through the getters and functions to see how you can get the data you want.

Note that you seem to be making a shop with ItemActions. That's not the only way you can do it. For example the Shop/ShopMenu component we use in the demo doesn't use ItemActions. We directly listen to the click events and deal with buying/selling directly inside that component
 
When adding to an ItemCollection, you cannot specify an index, because there are none (Except for the ItemSlotCollection or custom ItemCollections).
So... In order to add an item to a specific slot in the inventory, I need to add it to ItemCollection first, and then move it to that slot using the index I got, right?

But unlesss you have the item ID you won't be able to find that item in the manager because there can be many of the same item (except for non-Unique and Immutable items, since they share the same reference).
Just curious, from your viewpoint, do you think that's a problem for my system? Since a slot for the shop is only for an item, it can't be stacked. And there's a chance that the player will have 2 or more sellable items of the same type. (Example: Fire wand on the 1st slot and the 3rd slot). And when the item is in player inventory, it's possible to stack it.

Note that you seem to be making a shop with ItemActions. That's not the only way you can do it. For example the Shop/ShopMenu component we use in the demo doesn't use ItemActions. We directly listen to the click events and deal with buying/selling directly inside that component
I've seen the demo, but that's not the shop system I wanted to build. I'm using "Moonlighter" and "Recettear" as the reference for my shop system. But I'll probably use it when I make another game later, so thanks for the advice

So the flow would go like this:
Open shop shelf panel (shop inventory)> Select a grid on that panel > Open player inventory and select the item there > The item is put on that shelf grid
 
Last edited:
So... In order to add an item to a specific slot in the inventory, I need to add it to ItemCollection first, and then move it to that slot using the index I got, right?
No, you misunderstood.
There is a function directly in the ItemViewSlotContainer that lets you specify the index in which to add the item.
Code:
m_ItemViewSlotContainer.AddItem(itemInfo, slotIndex);
Check the documentation and the source code for more examples:

Just curious, from your viewpoint, do you think that's a problem for my system? Since a slot for the shop is only for an item, it can't be stacked. And there's a chance that the player will have 2 or more sellable items of the same type. (Example: Fire wand on the 1st slot and the 3rd slot). And when the item is in player inventory, it's possible to stack it.
Sorry I don't understand the question.
Unique items are not stackable. non-Unique (aka Common) items are stackable.
 
Top