Security HUD
System Watchdog
×
Threads Scanned
-- / --
SYS. LOAD --%
AI SHIELD ACTIVE
DMCA Policy
×

📋 DMCA Compliance

This platform and community fully complies with the Digital Millennium Copyright Act (DMCA) and international copyright laws. We take all copyright protection seriously.

🛡️ Copyright Protection

If you believe a posted item belongs to you or violates your copyright, you may file a DMCA takedown request through our official channels. Upon receiving a valid claim, the infringing content will be removed within 24 hours.

What's new
×
Fiveguard

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

Weszz

Silver Elite
Joined
Sep 19, 2021
Messages
15
Reaction score
7
Points
166
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
 
Top