Jump to content

inventory system


Wisin

Recommended Posts

hey, i've started to make a zombie mode and i want to make an inventory system where you can use items/drop etc but i don't know where to start exactly, i mean like how i should save the items etc.

if someone can tell me how i start i will be very greatefull.

Link to comment

For myself I'm doing that using MySQL server for storing items. Could of course be Sqlite, it's a nice solution. Still It's up to you how to organize the read/write from/into database.

When server is running, I find it more easier to keep data in a table, related to the player, like

PLAYERS[player].inventory = { ... } --kind of  

It's basically what you need:

1. A way to store data

2. A way to read/write

3. Any ways to work with data red

Good luck.

Link to comment
For myself I'm doing that using MySQL server for storing items. Could of course be Sqlite, it's a nice solution. Still It's up to you how to organize the read/write from/into database.

When server is running, I find it more easier to keep data in a table, related to the player, like

PLAYERS[player].inventory = { ... } --kind of  

It's basically what you need:

1. A way to store data

2. A way to read/write

3. Any ways to work with data red

Good luck.

my original idea was to use sqlite to save stuff etc but don't get how i can make would be like item 1 description of item 1 amount of item 1 etc.

Link to comment

Item 1 becomes an sub - table in [inventory] one.

  
PLAYERS[player].inventory = { 
    { item1 = { description = "some_description", amount = 52, weight = 12 }, 
    { item2 = { description = "item2_description", amount = 4, weight = 52 }, 
    --.... etc .... 
} 

Don't know if anybody suggest some other way, but I prefer to use table anywhere they can be applied. Such a structured things are easy to deal with.

Link to comment
Item 1 becomes an sub - table in [inventory] one.
  
PLAYERS[player].inventory = { 
    { item1 = { description = "some_description", amount = 52, weight = 12 }, 
    { item2 = { description = "item2_description", amount = 4, weight = 52 }, 
    --.... etc .... 
} 

Don't know if anybody suggest some other way, but I prefer to use table anywhere they can be applied. Such a structured things are easy to deal with.

Tables are good for this kind of stuff. But in this case, your table has too many {'s and it's not necessary to have item1, item2, etc.

  
PLAYERS[player].inventory = { 
    { description = "some description", amount = 52, weight = 12 }, 
    { description = "item2 description", amount = 4, weight = 52 }, 
    --.... etc .... 
} 
PLAYERS[player].inventory[1] -- will be the first item (table) 

Link to comment
Yep, probably, but on the other hand searching for something is bit easier when each item has it's own ID.
if ...[inventory].car_keys then 

instead of

for _, v in ipairs( [inventory] ) do 
    if v.description == "car_keys" then 
        return .... 
  

In my opinion.

Tables with numbers as their indices are faster to process in loops. Besides, you can add new items by using table.insert which I prefer.

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...