Storing Inventory to MySQL

Hi there,

I have been working on a small multiplayer game and have setup character customising, login system all stored to MySQL but for the life of me I cant work out how to store inventory data to the Database.

Can anyone throw some tips and / or ideas as to how I can do this, the only way I can think of doing it is to make an Hash table or Arraylist of items and store the ID of the items or something along that line.

Also would it be worth storing inventory to a database? The game isnt aiming to be an MMO but is account based so the database side of things is to hopefully eliminate cheating to a certain extent.

Thanks a bunch :slight_smile:

Hi,

why not making a Class, for example

    public class InventoryItem
    {
        //Define some variables for your Items
        public int ItemId;
        public string ItemName;
  
        public InventoryItem(int id)
        {
            //Make MySQL Query and assign your variables, then
            AllItems .Add(this);
        }

        public InventoryItem()
        {
        }
        
        //Also u can make a Static void for loading all Items from Database, create a new InventoryItem() for each and store it in the AllItems list...

        //Save all items in this static List
        public static List<InventoryItem> AllItems =  new List<InventoryItem>();
    }
    
    void CatchupItem(int id)
    {
        InventoryItem item = new InventoryItem(id);
    }

    void ListAllItems()
    {
         Debug.Log("Items in invetory:\n");
         foreach (InventoryItem item in InventoryItem.AllItems)
         {
              Debug.Log(item.ItemName + "\n");
          }
    }

Else i suggest u to use a Server that exchange those Data. I mean u tell that Server who u are (Username Password), the Server checks that and then send all Account related data like the Inventory, etc to the Client.

I have a full inventory system working my main problem is storing and loading the inventory data for each account in my MySQL database.

Say if “Player” has 3 items in his inventory, I cant store GameObjects to the inventory so how would I approach storing them?

How do you have the Client connected to the Database?
Do you know how to write MySQL Querys?
Do you know how to save/load Inventory Items to the Database?
Do you have your Database tables Setup?

If you want me to help then i need to know on which point you get stuck…