[Release] Inventory System v2.1 (Personal Menu)

On php i’m lost to xD

1 Like

What is the problem you’re having? :smile:

I know how to create the user_inventory table, i know how to put the user_id, quantity, item_id collumn. But i’m lost on the way I have to put index, primary keys (When I try, everytime I got an error message : 1075, etc…etc…)

Hmm… - Unfortunately I’m not at my computer right now, so I can’t tell 100% what’s wrong, but I’ll try to help when I’m home :slight_smile:

1 Like

Same here. Comes down to the data being stored in identifier in the user table is not an integer, it’s actually strings (varchar). Primary keys should be integers, nothing else.

Suggestion: Don’t use the “user” table at all, it’s badly designed anyway. Hook into the event that stores the user information, can’t remember what it’s called, get the user identifier, then store that yourself. Drop the foreign key requirement and the add primary key statement in sql, you should be good.

You made a couple of mistakes when working with the existing database: NEVER use some else’s data as a primary key since you don’t have control over how they handle the data, what they store, and if they change it. Your best bet is to leave the users table alone since changing the table violates that rule.

Second rule you broke: NEVER change anything someone else did, especially if you depend on their work to make yours work. Leave everything they did alone and work around any limitations you find. Big reason: you can break their stuff and now you’re stuck fixing since the essential mode author probably won’t support changing anything he did unless he makes the changes.

It’s good your trying to do foreign keys, but not good when modifying someone else’s table. The essential modes tables are badly designed, you just have to work around that.

2 Likes

I have edit my sql file and my original post because that was not really necessary to add primary key you’re right, thank you :wink:

hi i have this error with the new dump.sql

`Erreur Requête SQL :

CREATE TABLE user_inventory (
user_id varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT ‘’,
item_id int(11) unsigned NOT NULL,
quantity int(11) DEFAULT NULL,
PRIMARY KEY (user_id,item_id),
KEY item_id (item_id),
CONSTRAINT user_inventory_ibfk_2 FOREIGN KEY (item_id) REFERENCES items (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL a répondu: Documentation

#1071 - Specified key was too long; max key length is 767 bytes`

Change user_id varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT ‘’, to user_id varchar(30) CHARACTER SET utf8mb4 NOT NULL DEFAULT ‘’,
works for me

1 Like

thanks bu now i have this error `

Requête SQL :

ALTER TABLE users
ADD PRIMARY KEY (test)
MySQL a répondu: Documentation

#1072 - Key column ‘test’ doesn’t exist in table`

How check if player have item please ?

In SQL files, don’t write ALTER TABLE *****
and ADD PRIMARY KEY (test)

1 Like

Do you think my code would be correct for the inventory adapter?

local blip = AddBlipForCoord(2212.22, 5577.224, 53.82)
  SetBlipSprite(blip, tonumber(496))
  SetBlipDisplay(blip, 3)
  
  BeginTextCommandSetBlipName("STRING");
  AddTextComponentString(tostring("Weed"))
  EndTextCommandSetBlipName(blip)

Citizen.CreateThread(function()
     while true do
         Citizen.Wait(500)
        local playerPos = GetEntityCoords(GetPlayerPed(-1))
 
        local distanceWeedFarm = GetDistanceBetweenCoords(playerPos.x, playerPos.y, playerPos.z, 2212.22, 5577.224, 53.82, true)
 
        if distanceWeedFarm < 20 then
            --recolte de cannabis
            sendnotif(tostring("~b~Appuyez sur ~g~E ~b~pour récolter"))
            if IsControlJustPressed(1,Keys["E"]) then
                sendnotif(tostring("~g~ + 1 ~b~Cannabis"))
				TriggerServerEvent('player:receiveitem',"cannabis",30)
                Citizen.Wait(500)
            end
         end
    end
end)

Thank you for your help

I don’t think ^.^ the guys who made the script use his own essential so nope it’s not correct.

Hi there,

Thanks a lot for sharing that script! I have a few questions. Is there an list of all item ID available somewhere? How can we create our own ID, for instance if I want to create drugs and other stuff. How can I do?

Cheers,

Create a colum in Items called Weed and give it the ID 1, for example.

Oh yeah I didn’t see ‘items’ onto database!
Trying to ad something in the inventory, harder than expected. Whish me luck x)

1 Like

Scapin, nothing appears when you do that, the item list is empty

Is it possible to have a hand on that one please?
I can send you the code I have so far (which is not working)

UPDATE 22/04 :

  • Add sellItem event to earn money and loose an item
  • Add export to get the quantity of object of a player

This update allow me to introduce the recolting/treatment/selling system that I will soon release :wink:

2 Likes

Very nice !!! Good job
Since the first post, I try to make the system of harvest treatment and sale but in vain