Hey everyone, I'm working on the code for consumable items right now and have hit a snag. Here's the problem:
Let's say you have a character inventory of 50 slots. For kicks, we'll say every slot is full. When a player uses an item (blue potion, for example) the server has to check to make sure it's actually in the inventory. This means searching through up to 50 slots every time an item is used. Now, multiply that by 100 players and lots of items being used, and you can see the issue: that's a lot of searching that seems fairly wasteful. Although there are ways to improve this search, they take up more memory and get more complex than just storing a list of items.
So there are two things I can do to solve this. Please tell me your thoughts on them.
#1: I make it so that there are slots in the equipped items area for consumables. They can be stacked here, so you'd be able to hold a pretty good amount but only ones in the equipped items area would be usable. Plus, they would count as equipped items so they wouldn't drop when you die. The disadvantage is the limitation to the number of consumables that can be used simultaneously--I would probably have 6-8 slots.
#2: I sort the inventory by type, so that consumables always come first. This is slightly less efficient from a coding standpoint (since inventories are constantly being sorted) but it significantly shortens the search. The advantage here is that you can use more items simultaneously, but the disadvantage is that they always drop when you die.
If you have any other ideas, let me know!