Store items
#1

Hi everyone,
I'm making a system to save different kind of items like skin, weapons and wearable items.
I've a table on my database that contains all items info(model id, amount, name, the function..)

When I start the server, this information are copied in an array called items, that is similar on structure of my table.
So, on opening of trading dialog, the script searches inside the array any item that belonging to current business.
The inventory is an array that store only the item id and amount, the other information are keep from items array.

account_items is the inventory table




Is that a good way to store items? How to improve if this isn't?

Thanks in advanced.
Reply
#2

You should make separate tables for every different thing (table for weapons, table for wearables, table for inventory).
Reply
#3

On items table I've a field call "Function", that contains a char, for example W for weapons or F for food..
So, when I have to use an object I know what I've to do.

My doubt is if save all this data in an array, currently I've created 300 rows of items, because I saved all skin id related to shop (Victim, sub urban ..)
Reply
#4

Quote:
Originally Posted by pollo97
Посмотреть сообщение
On items table I've a field call "Function", that contains a char, for example W for weapons or F for food..
So, when I have to use an object I know what I've to do.

My doubt is if save all this data in an array, currently I've created 300 rows of items, because I saved all skin id related to shop (Victim, sub urban ..)
Are you sure you have not mistaken rows for columns?

This is a good tutorial for setting up tables.

https://sampforum.blast.hk/showthread.php?tid=420363
Reply
#5

Hmm, I've always found it rather redundant to store everything in memory. I'd only store things in memory that are accessed very frequently. For anything else I'd go straight to the database. A roundtrip to the database is a bit more expensive but you're not bound by the limits of Pawn.

Specifically this:
Quote:

the script searches inside the array any item that belonging to current business

should probably be done with a query rather than in code.
Reply
#6

Vince said it. And i would like to add to the type, instead of character you can use SMALL_INT to compare item type.
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
Hmm, I've always found it rather redundant to store everything in memory. I'd only store things in memory that are accessed very frequently. For anything else I'd go straight to the database. A roundtrip to the database is a bit more expensive but you're not bound by the limits of Pawn.

Specifically this:

should probably be done with a query rather than in code.
I understood.. but if I search on database every time that one open a trade dialog it doesn't lag?

Another question. I save the clothes like any other item. So, I've 150 row of skin with different id in items table.
I've done this, because, first of all, to saving player inventory on database I must have the object id of item table and the account id, and also because the skin are buyable in different stores, so they have different store id.

I think there is a better way to do this.. but currently I don't know..
Reply
#8

Quote:
Originally Posted by pollo97
Посмотреть сообщение
I understood.. but if I search on database every time that one open a trade dialog it doesn't lag?
As long as you use threaded queries. There may be a very slight delay before the dialog opens but it shouldn't be noticeable. The average query executes in under 50 milliseconds. For reference: the blink of an eye takes about 250 milliseconds.

Quote:
Originally Posted by pollo97
Посмотреть сообщение
Another question. I save the clothes like any other item. So, I've 150 row of skin with different id in items table.
I've done this, because, first of all, to saving player inventory on database I must have the object id of item table and the account id, and also because the skin are buyable in different stores, so they have different store id.

I think there is a better way to do this.. but currently I don't know..
I find it very hard to decipher what you're telling here. Do you have a screenshot of your complete datamodel, preferably with all fields expanded?
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
As long as you use threaded queries. There may be a very slight delay before the dialog opens but it shouldn't be noticeable. The average query executes in under 50 milliseconds. For reference: the blink of an eye takes about 250 milliseconds.
So, I've to use tquery instead query?

Quote:
Originally Posted by Vince
Посмотреть сообщение
I find it very hard to decipher what you're telling here. Do you have a screenshot of your complete datamodel, preferably with all fields expanded?
Sorry for my bad english..

Here some images.

Here tables relation:
http://i.imgur.com/gH3E7SS.png

Table items:
http://i.imgur.com/ipSzU6G.png
http://i.imgur.com/RZlwGmD.png
Reply
#10

Why 2 tables of items? That sucks.

Use owner and ownertype field.

Example:

#define ITEM_OWNER_TYPE_GROUND 1
#define ITEM_OWNER_TYPE_PLAYER 2
#define ITEM_OWNER_TYPE_VEHICLE 3

Item[itemid][item_owner_type] = ITEM_OWNER_TYPE_PLAYER;
Item[itemid][item_owner] = player DB id;
Reply
#11

Quote:
Originally Posted by raydx
Посмотреть сообщение
Why 2 tables of items? That sucks.

Use owner and ownertype field.

Example:

#define ITEM_OWNER_TYPE_GROUND 1
#define ITEM_OWNER_TYPE_PLAYER 2
#define ITEM_OWNER_TYPE_VEHICLE 3

Item[itemid][item_owner_type] = ITEM_OWNER_TYPE_PLAYER;
Item[itemid][item_owner] = player DB id;
I've got only a table of items. Watch the screenshot in the previous post
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)