16.10.2017, 22:27
Thats a bit too much to explain in a single post, i can only give some general tips.
Dont create separate tables for player inventories, vehicle inventories, etc, but instead do a single table with all inventories, and link vehicles and players to their inventory id in a different table. Makes save/load routines much easier in the script.
In the inventory table you might either serialize the data of all items to get a single binary object or string, or create a second table with columns like (inventory_id, item_slot, item_id, condition), that is then joined to get the full item list for each inventory.
First version is small and simple, second version is much more structured and easier to administrate.
Do not create a huge table with one column for each item. Thats bad database design, and requires big changes in the script and database whenever you decide to add a new item type.
For the ingame handling: Ive yet used vectors for that via the vector plugin. Two vectors for each inventory, one for the item ids, one for the conditions. Also store the database id of the inventory of course.
like
You might also use arrays instead of vectors, but obviously this would be a huge waste of memory. Vectors are the eco-way, its not that hard to learn how to use them properly.
Thats basically the way I took to create an incredibly versatile inventory system, it has some more layers though to handle extra information for certain types of items (https://www.youtube.com/watch?v=Av61YO9Yb3o)
Dont create separate tables for player inventories, vehicle inventories, etc, but instead do a single table with all inventories, and link vehicles and players to their inventory id in a different table. Makes save/load routines much easier in the script.
In the inventory table you might either serialize the data of all items to get a single binary object or string, or create a second table with columns like (inventory_id, item_slot, item_id, condition), that is then joined to get the full item list for each inventory.
First version is small and simple, second version is much more structured and easier to administrate.
Do not create a huge table with one column for each item. Thats bad database design, and requires big changes in the script and database whenever you decide to add a new item type.
For the ingame handling: Ive yet used vectors for that via the vector plugin. Two vectors for each inventory, one for the item ids, one for the conditions. Also store the database id of the inventory of course.
like
Код:
enum Inventory { inventory_id, item_id_vector, item_condition_vector } new playerInventories[MAX_PLAYERS][Inventory]; new vehicleInventories[MAX_VEHICLES][Inventory];
Thats basically the way I took to create an incredibly versatile inventory system, it has some more layers though to handle extra information for certain types of items (https://www.youtube.com/watch?v=Av61YO9Yb3o)