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

i have the same error …

Nobody has the solution i think

1 Like

PRIMARY KEYit’s really necessary for identifier ?

I edit my post for this problem (I think)

Yes it is for create foreign key in user_inventory :wink:

varchar(255) and int(11) everywere but always the same bug.
#1071 - Specified key was too long; max key length is 767 bytes rip

Code to reset player items on death:

in server file:

RegisterServerEvent("item:Reset")
AddEventHandler("item:Reset", function()
    playerId = tonumber(source)
    TriggerEvent('es:getPlayerFromId', playerId, function(user)
        local player = user.identifier
        local executed_query = MySQL:executeQuery("SELECT * FROM user_inventory JOIN items ON `user_inventory`.`item_id` = `items`.`id` WHERE user_id = '@username'", { ['@username'] = player })
        local result = MySQL:getResults(executed_query, { 'quantity', 'libelle', 'item_id' }, "item_id")
        if (result) then
            for _, v in ipairs(result) do
				MySQL:executeQuery("UPDATE user_inventory SET `quantity` = @qty WHERE `user_id` = '@username' AND `item_id` = @id", { ['@username'] = player, ['@qty'] = 0, ['@id'] = tonumber(v.item_id) })
            end
        end
    end)
end)

in client file:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)      
        if IsEntityDead(PlayerPedId()) then
            RegisterNetEvent("item:Reset")
            TriggerServerEvent("item:Reset")
        end
    end
end)
2 Likes

Oooooh thank you, I’ll integrate this :heart_eyes:

i have the same problem :confused:

varchar(255) and int(11) everywere but always the same bug.

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

I have a problem I can not join my database to give with the server

Better with

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)      
        if IsEntityDead(PlayerPedId()) then
            RegisterNetEvent("item:Reset")
            TriggerServerEvent("item:Reset")
        end
    end
end)

There is an extra “end” that serves no purpose

1 Like

Oops, i’ll fix it in my file, thx.

1 Like

Not work db mysql :

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_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`identifier`),
  CONSTRAINT `user_inventory_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

pliz fix it thx :slight_smile:

guys look the topic !!!

@Vodkhard fix it in the file or add it ont frist topic

Error Code: 1068. Multiple primary key defined ?

I fix this, if your user line is in Primary key, delete the primary key, and when you will execute this SQL file, it will be good.

@MO_SnipZo

1 Like

Screens ? It is possible ?

I have exactly the same error

You can delete this message :slight_smile: