For a point of reference, a normal inventory system would have a dictionary/table with a list of items and a number or "code" for the item's and then when a player picks up an item It could go to a folder or another table to store what's in the back pack. However, what would the best way to do it via how many grids you have left, kind of like that game Tetris where you have to rotate the objects and organize it in a way that you can fit more?
-- For those who like to be rude and say this isn't a request site, this is Indeed a request site, for help, not for code. Did I ask for any script in my question? No, I did not. However feel free to leave a piece of a script to help EXPLAIN the best method of achieving this goal. --
This is an interesting question.
I have never attempted a grid inventory system, however, I would approach it as such:
Have a two-dimensional inventory array. Each index would hold either nil
, or a reference to an item (table with the item's properties, essentially) that that space occupies. One such property would be the FormFactor of the item. If you have an L-shaped (three vertical on the left, then one on the lower-right), it would be in a 2x3 array, represented in 1s and 0s:
1, 0
1, 0
1, 1
And on top of this, another property I would have is a top-left position. This would help with many methods you would need to manipulate this system.
You'd want to methods to:
-Determine if a cell is occupied
-Place item reference into a single cell
-Get inventory cell locations where an object would be located if top-left placed at location X. You can use this method to:
+Detect if an item can be placed in the inventory via boundaries
+Place item references into the necessary cells
+Clear an item's cells from the Inventory
And possibly more.