Multiplayer Ingame shop

How can I make it where I create an account and I unlock a ingame item? I already have a login system with php and javascript but I don’t know how to give the account a item. For example lets say there was a weapon you unlock when you complete a objective. When you get it, it assigns to your account and when you close the game, it will still stay on your account.

Without going too OTT, each player in your game will have an account, that account information will be stored as a record in a table (say “accounts”), as you’ll want to set and retrieve data on the record as fast/appropriately as possible it’s best to look into normalization for storing the data.

Accounts will have nothing more than AccountID, PlayerName, Password, Email, SecurityQuestion, SecurityAnswer, State and possibly a couple more. Once you know the player has been able to login this information after this point should no longer required so it’d be pointless retrieving it every time you query the record.

Only if you have more than one character per account implement a second table called CharAccounts, this table will have basic character information such as CharacterName, CharacterLevel, CharacterClass, etc… again information you’ll probably only be accessing initially for them to load their character and access the game. These characters need to be associated to the account so have AccountID stored with them so you know they belong to a certain player, the PlayerName can be associated to the CharacterName through normalization and will save you having unnecessary copies of the players data with each character.

So now you create a third table (or second if you only have one character), in this table you could have their inventory, when each character is created this will be populated based on the characters class. This table will have item ID’s for each item in the game and stored in a manner you can retrieve in your game, splitting strings, JSON, etc… Assuming the player created a Warrior character we equip him with a level 1 sword and basic armor, for each item will have an ID already set up in game (and possibly in the DB if required), so we can store his inventory as “Sw02:1;Ar02:1” where the ID is followed by : then its quantity. This string will tell us when the player logs in to his game we equip him with one Sw02 (level 1 sword) and one Ar02 (basic armor).

Whenever the player makes any changes to his inventory, you’ll need to build a string to send to the server of his new inventory, say he sells the basic armor and buys sturdy armor, you’ll send the request to UPDATE this CharacterID with our new inventory of “Sw02:1;Ar03:1;”. This is just one of many ways you could set it the inventory table (you could require one for his stats), comrades, friends, etc. depending on what you’re making. You could create a table just of items and have CharacterID, ItemID, ItemQuantity, and return all that are associated to that character as you could characters associated to a player, it depends on what you’ll find best for your needs. You could rewrite “Sw01:1;Ar01:1;” “Sw01;Ar01”; to know only one of these items are present even though no quantity has been specified, keeping the DB streamlined and as responsive as possible is what you need to aim to do.

Without knowing more about what you’re exactly trying to create first have a look at normalization and work out how you want to set your DB up to make it most efficient. Make sure you understand one-to-one and one-to-many, and many-to-many doesn’t exist in the design.

Hopefully this will give you some food for thought.