Inventory System (Using a lot of MySQL)
#1

Hey! I was thinking today of doing an inventory system which basically would use a lot of MySQL. Simply i\'d have a table, with rows such as;

- Calculator.

- Phone.


The basic things you would carry in your pockets or in a back pack.


Would it work in a way where I have one table with the main account information such as passwords and a child table with the inventory information and using the tutorial created by Vince but switching the weapon data for the inventory data.
Reply
#2

It\'s a very simple task, providing you have a primary key to identify a player\'s ID in your player accounts table.


ItemID - this should be an auto-incrementing value - similar to your auto-incrementing player ID field, but to uniquely identify item values

ItemPlayerID - a foreign key of the player\'s primary key ID from your players database

ItemModel - the model ID of the item, i.e. 1 for cellphone, 2 for phone, etc...


Once you\'ve set up the database in this way, you can simply execute a query like this to collect the information:

Code:
SELECT * FROM `items` WHERE `ItemPlayerID` = \'%d\'
%d being the player ID primary key.
Reply
#3

Quote:
Originally Posted by Calgon
View Post
It\'s a very simple task, providing you have a primary key to identify a player\'s ID in your player accounts table.


ItemID - this should be an auto-incrementing value - similar to your auto-incrementing player ID field, but to uniquely identify item values

ItemPlayerID - a foreign key of the player\'s primary key ID from your players database

ItemModel - the model ID of the item, i.e. 1 for cellphone, 2 for phone, etc...


Once you\'ve set up the database in this way, you can simply execute a query like this to collect the information:

Code:
SELECT * FROM `items` WHERE `ItemPlayerID` = \'%d\'
%d being the player ID primary key.
Ah cheers for the explanation Calgon!

Quote:
Originally Posted by Y_Less
View Post
Let me say this. ******** has billions of users, and as many page hits daily. They use MySQL. THAT is a lot of MySQL, your SA:MP server is not. Anything you can throw at it, it can handle.
I didn\'t think of it that way to be honest, my server compared to ******** is like a small insect.
Reply
#4

Y_Less has a point, MySQL should be quick enough to deal with anything. I can call MySQL blazing fast because it should be like that, I guess one day they will make something faster and more reliable than that, but still MySQL is the best out there and it can easily deal with a few tables / coloumns you have.
Reply
#5

Please don\'t do that! MySQL relies on indexes, and you can\'t use them efficiently when all you store is binary string.
Reply
#6

Quote:
Originally Posted by [HLF]Southclaw
View Post
I\'m partially hijacking this thread with a question about BLOB data and inventories.


At the moment, my mode stores inventory data in a large binary string which is stored in a file. It\'s nice a fast, 100 writes takes less than a millisecond. I was thinking of updating to MySQL for some web interface stuff with inventories. I\'d prefer to keep that universal binary string format (ItemList if interested) so is there any nice simple way I can store that with SQL? And no, I don\'t want to store the values as delimited integers ("54, 25, 734, 74" etc).
Delimiters in MySQL violate the first normal form. If you need to do that, then your database structure is wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)