SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 03/06/2019, 05:11 PM   #1
austin070
Huge Clucker
 
austin070's Avatar
 
Join Date: Aug 2010
Posts: 374
Reputation: 18
Default Inventory Structure

Hey guys,

I'm working on implementing an inventory system. I was wondering what would be the best way to structure it in my script and in my SQL database. Is this type of thing normally associated with the primary users table or would it be better to link a player inventory table to the users table through primary key?
austin070 is offline   Reply With Quote
Old 03/06/2019, 05:20 PM   #2
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 253
Reputation: 16
Default Re: Inventory Structure

I would recommend to keep things separate.
the primary table only for important stuff like username, password, money, score...
and another one for the inventory.
As for code structure: This really just depends on preference.
And creating a own table for the inventory could have some advantages, but that depends on what you want and how you want to do it.
Plastikmensch is offline   Reply With Quote
Old 03/06/2019, 06:25 PM   #3
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,063
Reputation: 184
Default Re: Inventory Structure

Keep things separate. In fact i would make containers for items and reuse them for things like vehicle storage, boxes and other stuff.
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 03/06/2019, 07:00 PM   #4
austin070
Huge Clucker
 
austin070's Avatar
 
Join Date: Aug 2010
Posts: 374
Reputation: 18
Default Re: Inventory Structure

Quote:
Originally Posted by DRIFT_HUNTER View Post
Keep things separate. In fact i would make containers for items and reuse them for things like vehicle storage, boxes and other stuff.
I've seen this in the form of briefcases. I'm not entirely sure of the best way to code that, however. I went ahead and made a general inventory table, a weapons inventory table, and an ore inventory table. I definitely see how much easier that is than putting all of that information in a single table.
austin070 is offline   Reply With Quote
Old 03/06/2019, 08:01 PM   #5
d3Pedro
Huge Clucker
 
Join Date: Apr 2012
Location: Los Santos
Posts: 249
Reputation: 80
Default Re: Inventory Structure

You can go by making it separate, just like you do vehicles for example, make the same thing with inventory and load it from player username or a player row id.
d3Pedro is offline   Reply With Quote
Old 03/06/2019, 10:12 PM   #6
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,761
Reputation: 837
Default Re: Inventory Structure

Here's how i would do it, so i am making this database schema based on your server has dynamic inventory items and item types.

Table: "ItemTypes"
idINTPRIMARY_KEY (AUTO_INCREMENT)
nameVARCHARsize = 128
descriptionVARCHARsize = 256have a description for your item, could be used in textdraws etc.
sizeINTif you want your items have different size to fit in a bag (example: your bag can carry total 25 items, but a M4 will equip 10 item slots)
amountFLOATthis is for items which has a specific amount to give to player when used (example: a medkit, amount can be set to how much health should be given when item is used)


Table: "Items"
idINTPRIMARY_KEY (AUTO_INCREMENT)
typeIdINT (FOREIGN_KEY)a foreign key to "ItemTypes" table column "id"this will be the item's type ddefinition
userIdINT (FOREIGN_KEY)a foreign key to "Users" table column "id" (this will be NULL if no user is carrying the item or the id of user who has the item in their bagpack)
xFLOATif the item is on the ground (i.e. userId = NULL)
yFLOATif the item is on the ground (i.e. userId = NULL)
zFLOATif the item is on the ground (i.e. userId = NULL)
rxFLOATif the item is on the ground (i.e. userId = NULL)
ryFLOATif the item is on the ground (i.e. userId = NULL)
rzFLOATif the item is on the ground (i.e. userId = NULL)
interiorIdINTif the item is on the ground (i.e. userId = NULL)
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 05/06/2019, 02:01 PM   #7
austin070
Huge Clucker
 
austin070's Avatar
 
Join Date: Aug 2010
Posts: 374
Reputation: 18
Default Re: Inventory Structure

Quote:
Originally Posted by Gammix View Post
Here's how i would do it, so i am making this database schema based on your server has dynamic inventory items and item types.

Table: "ItemTypes"
idINTPRIMARY_KEY (AUTO_INCREMENT)
nameVARCHARsize = 128
descriptionVARCHARsize = 256have a description for your item, could be used in textdraws etc.
sizeINTif you want your items have different size to fit in a bag (example: your bag can carry total 25 items, but a M4 will equip 10 item slots)
amountFLOATthis is for items which has a specific amount to give to player when used (example: a medkit, amount can be set to how much health should be given when item is used)


Table: "Items"
idINTPRIMARY_KEY (AUTO_INCREMENT)
typeIdINT (FOREIGN_KEY)a foreign key to "ItemTypes" table column "id"this will be the item's type ddefinition
userIdINT (FOREIGN_KEY)a foreign key to "Users" table column "id" (this will be NULL if no user is carrying the item or the id of user who has the item in their bagpack)
xFLOATif the item is on the ground (i.e. userId = NULL)
yFLOATif the item is on the ground (i.e. userId = NULL)
zFLOATif the item is on the ground (i.e. userId = NULL)
rxFLOATif the item is on the ground (i.e. userId = NULL)
ryFLOATif the item is on the ground (i.e. userId = NULL)
rzFLOATif the item is on the ground (i.e. userId = NULL)
interiorIdINTif the item is on the ground (i.e. userId = NULL)
This is very helpful. Thank you for taking the time to write that post.
__________________
Looking for a co-scripter to assist with a scratch-made roleplay gamemode. English fluency required. PM for details.
austin070 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
structure for inventory database PeanutButter Scripting Help 6 13/01/2017 11:22 PM
How many && can you use in a IF structure? Lucky13 Scripting Help 10 29/01/2016 02:12 AM
Need help with control structure Jing_Chan Scripting Help 2 31/08/2014 10:02 PM
Server structure help Opptur Scripting Help 4 08/06/2014 01:10 PM
Inventory issue [Cyanide's inventory.inc] Devix Scripting Help 0 09/10/2012 08:14 PM


All times are GMT. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.