How to create a unique item?

Hello everyone,
I would like to create an item that is unique, to give you an example I would like to ensure that for an identity card the item saves the coordinates of the player and that if a player has given it to another the coordinates correspond to the first player. So then what makes the items stackable. Thank you for your answer, have a good evening.

1 Like

Hey :slightly_smiling_face:
What framework are you using ? (ESX or QBcore)
Regarding ESX, I already thought about what would be a way to do it (for a credit card I wanted to work on). The only way I found was to create 1 item for each card (or else) in the ‘items’ database table and link the item to the data (player’s name/age etc… for example) by making a unique ID that you concatenate with the name of the item and that will allow you to create a “abstract relation” between the item and the data you want to be linked to it (that could be stored in another table).

A Little example might be better to understand my thinking :

Items table :

  • fields : name - label - weight
  • data : IDcard45685 - Id card - 1

ID table :

  • fields : id - name - age - sexe - height
  • data : 45685 - john - 30 - male - 196

Script algo :

IdCard = item.GetItemName()
IdNumber = IdCard.sub("IDcard")
result = Query("SELECT * from IDTable WHERE id ="..idNumber)

--Here is your data that are related to the card 
print(result)

I think I understood your approach, but in this case the item will not be unique because by giving the card to another player the coordinates will change to take those of the new playerv … i think

im use ESX framework…
thanks

No the opposite, I came up with the idea after looking the issue from all possible angles. It’s pretty simple to see in my example above, each player have an entry in the ‘IDTable’ that is linked to a specific card by the suffix in the item’s name(second part of the item name).
With my approach you need to create 1 item per IDcard. You have 10 players = 10 Items, each item will avec a different suffix (IDcard45685, IDcard54768, IDcard549304).

If player A datas are linked to the card IDcard45685 when player B steal (for example) player’s A ID card the car name still will be IDcard45685 and so the data linked to it still will be the one of player A.

Kind of how a vehicle is identified by the plate number? Unless of course the server has a way to buy new plates or apply a fake plate. You’d just have to create a unique ID for whatever item. And make certain no script can ever modify that ID.

This means that it would take 1 item per person, so if I have 100 players there will be 100 items?

Unfortunatly, yes. That’s why I gave up regarding my creditcard system for now, as this is in my opinion the only way to do it with ESX at the moment.
That being said, most of the servers don’t have 100 players at the same time and if the server doesn’t have that much item already, MYSQL should be able to handle it (to be sure some testing should be done, but I don’t think it would have a major performances impact).

ok I see, I think this is possible in another way: Do like the clothes in the inventory example when you buy a piece of clothing this becomes an item that is not managed by MYSQL, I think that that would be the solution but i don’t know how to do it

It’s only my opinion, I still spent quite some time to think about it though (and I work with ESX pretty often).

Regarding the clothes I’m not familiar with it (I never made a script around that or look at the clothing system). But if the clothes you are talking are persistant (meaning you still have same or else), they are stored in the database somewhere.
I was wondering, when you say “Clothing becomes an item” what do you mean by that ?

The cloth becomes an object in the sense that the garment becomes a unique item, when you buy a garment it becomes an item

My question wasn’t really well put together.
What is was wondering is :
You keep mentionning the word “item” but in my head I don’t really get what you are talking about (specifically).

For me (if i’m not mistaking) there is :

  1. ‘Entities’ (ped, cars etc…), ‘Props’ (coffee cup, phone etc…) and ‘Weapons’ ; that are part of the game engine.

  2. Items (burger, weed, id card) that are only existing in a framwork’s context (ESX,QBcore,VRP).

Clothes to me are just textures that are applied to a ped’s model, you can then register thoses clothes in the databse in order to applie them back to the player’s ped model when he connects back to the server, but that doesn’t make them ‘Items’ in the framwork sense of it (which in my opinion would be the only one in that case) and that doesn’t make them ‘Props’ either (If i’m not mistaking).

That’s why I think we cannot draw a parallel between the way ‘Items’ and ‘Clothes’ are managed by the framework (or even by the game). In the end the ‘Item’ (for ESX at least) will end up in the ‘users’ table, ‘Inventory’ field and only have a pair key/value (name/quantity) which doesn’t allow us to attach any more datas to him (unless by doing what I was talking about earlier)

Furthermore, when I was working on finding a solution a few weeks ago another idea poped into my head (that I didn’t mentionned earlier); adding the creditcard item inside the ‘Inventory’ field in the ‘users’ table but not through ESX (through a roundabout way), but this wasn’t an idea I kept in mind because the friend I was trying to help by creating a creditcard system wanted the cards to be in the player’s inventory (as an ESX item) and with this way of doing things the creditcards would’ve needed her own NUI/menu, so I let this approach on the side.
But our talk about ‘Items’ made me wanna check if this other idea would work, and not even this sketchy approach would work. I just did some tests and the Inventory of the player get’s overwrite when he connects if any ‘Item’ that isn’t registered in the ‘Items’ table is found it get’s removed.
Which proved that the point I was making earlier was right, that the only way to do it at the moment would be by creating 1 ‘Item’ par card (if you want the cards to be usable as any ESX ‘Items’, linked to a player and be stored and displayed by the inventory of your choice)

Is there any way we can discuss this topic further?

He maybe mean metadata inventory look it up I think you will understand

You have the link? since I couldn’t find it

For example ox inventory for esx