Welcome to the forum, Guest

To access forum content and all of our services, you must register or log in to the forum. Joining the forum and all content on the forum is completely free.

The world's largest FiveM Forum and GTA 5 Forum address

Hello dear member,
We work 24/7 to provide the most valuable content that will be of use to you,
you can share content and support the entire FiveM & GTA 5 community.

Question What am i doin wrong? adding Give to QB Inventory

Weszz

Bronze Elite
Joined
Sep 19, 2021
Messages
12
Reaction score
2
Points
51
Location
NL
So, what am i doin wrong here.

The visual thing is worked out.

But what am i doin wrong here.
I've got this in the .js script:
$("#item-use").droppable({
hoverClass: "button-hover",
drop: function(event, ui) {
setTimeout(function() {
IsDragging = false;
}, 300);
fromData = ui.draggable.data("item");
fromInventory = ui.draggable.parent().attr("data-inventory");
if (fromData.useable) {
if (fromData.shouldClose) {
Inventory.Close();
}
$.post(
" ",
JSON.stringify({
inventory: fromInventory,
item: fromData,
})
);
}
},
});
This in the qb-inventory -> server -> main.lua
RegisterServerEvent("inventory:server:GiveItem")
AddEventHandler('inventory:server:GiveItem', function(target, inventory, item, amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local OtherPlayer = QBCore.Functions.GetPlayer(tonumber(target))
local dist = #(GetEntityCoords(GetPlayerPed(src))-GetEntityCoords(GetPlayerPed(target)))
if dist < 3 then
if amount <= item.amount then
if amount == 0 then
amount = item.amount -- If 0 gives all of an item the player has
end
if OtherPlayer.Functions.AddItem(item.name, amount, false, item.info) then
TriggerClientEvent('inventory:client:ItemBox',target, QBCore.Shared.Items[item.name], "add", amount)
TriggerClientEvent('QBCore:Notify', target, "You Received " .. amount .. ' ' .. item.label .. "!")
TriggerClientEvent("inventory:client:UpdatePlayerInventory", target, true)
Player.Functions.RemoveItem(item.name, amount, item.slot)
TriggerClientEvent('inventory:client:ItemBox',src, QBCore.Shared.Items[item.name], "remove", amount)
TriggerClientEvent('QBCore:Notify', src, "You gave " .. OtherPlayer.PlayerData.charinfo.firstname.." "..OtherPlayer.PlayerData.charinfo.lastname.. " " .. amount .. " " .. item.label .."!")
TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, true)
else
TriggerClientEvent('QBCore:Notify', src, "The other players inventory is full!", "error")
TriggerClientEvent('QBCore:Notify', target, "Your inventory is full!", "error")
TriggerClientEvent("inventory:client:UpdatePlayerInventory", src, false)
TriggerClientEvent("inventory:client:UpdatePlayerInventory", target, false)
end
else
TriggerClientEvent('QBCore:Notify', src, "You do not have enough items to transfer")
end
else
TriggerClientEvent('QBCore:Notify', src, "You are too far away to give items!")
end
end)
and this in the qb-inventory -> client -> main.lua
RegisterNUICallback("GiveItem", function(data, cb)
local player, distance = QBCore.Functions.GetClosestPlayer(GetEntityCoords(PlayerPedId()))
if player ~= -1 and distance < 3 then
if (data.inventory == 'player') then
local playerId = GetPlayerServerId(player)
SetCurrentPedWeapon(PlayerPedId(),'WEAPON_UNARMED',true)
TriggerServerEvent("inventory:server:GiveItem", playerId, data.inventory, data.item, data.amount)
else
QBCore.Functions.Notify("You do not own this item!", "error")
end
else
QBCore.Functions.Notify("No one nearby!", "error")
end
end)

I am using the new qbcore with oxmysql
 

Login or register to get more out of the forum!

Login or register to get more out of the forum!

Register

Creating an account on the forum is completely free.

Register now
Log in

If you have an account, please login

Log in

Theme editor

Theme customizations

Graphic Backgrounds

Granite Backgrounds