Jump to content

[Question] Tables and inventory (Not DayZ)


Recommended Posts

Hi, tell me, please, how to do the right thing. I have an inventory system. The first table with all possible items, like this one:

--ITEMS DEFENITION
local ITEMS = {
{id, name, type, weaponID, ...}
}


Each item has different keys in the table, depending on its type.

The players inventory table contains only a link to the item, amount, slot.

So, each player can have several identical objects and they stack. But my idea is that each item has a quality, and if two items have a quality of 100%, and one 36%, then it should become independent, as in the example:
Water (Quality 100%; Amount 2)
Water (Quality 36%; Amount 1)

In addition to quality, the subject may have other characteristics, such as modifications to weapons (silencer, sight), etc.

How to create this correctly? What structure for the table to use? I need some kind of algorithm or something.

Thank, sorry for my English?

Edited by manif14102
Link to comment
  • Moderators
5 hours ago, manif14102 said:

How to create this correctly? What structure for the table to use? I need some kind of algorithm or something.

Nope, just the way you are doing it in your example. A flat structure, because each complexity in the structure will make it more complicated to save.

 

You can later add a next layer on top of your table, to improve searching performance, if you so desire.

 

Finding your item? Do it how a human would do, check every item in the list until you find the right one and stop searching.

 

  • Like 1
  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...