What's new

Ares

VAG
Head Admin
Joined
May 6, 2021
Messages
547
Reaction score
77,106
Points
411
Location
root
Website
vag.gg
Greetings to all Vag forum users, I saw that the "give items to qb to esx inventory" part has not been shared on the forum before. I found it from a different place and tried to fix it by making small additions and I wanted to share with you if there are error solutions you want to see in this kind of guide titles, don't forget to leave a comment below, I hope you like it. Good forum to you all.

---------------------------------------------------------------- ----------ESX--------------------------------------- -----------------

-js

JavaScript:
JS partial
$("#item-give").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");
        amount = $("#item-amount").val();
        if(fromData.count > 0) {
            $.post("http://qb-inventory/GiveItem", JSON.stringify({
                inventory: fromInventory,
                item: fromData,
                amount: parseInt(amount),
            }));
            Inventory.Close();
        }
    }
});


-server.lua

Code:
#ServerPart
RegisterServerEvent("inventory:server:GiveItem")
AddEventHandler('inventory:server:GiveItem', function(name, inventory, item, amount)
    local src = source
    local Player = ESX.GetPlayerFromId(src)
    local OtherPlayer = ESX.GetPlayerFromId(tonumber(name))
--   local Target = OtherPlayer.get("firstName")..' '..OtherPlayer.get("lastName")
  --  local YourName = Player.get("firstName")..' '..Player.get("lastName")
    local totalWeight = ESX.GetTotalWeight(OtherPlayer.inventory)
    local itemInfo = ESX.GetItems()[item.name:lower()]

    if amount ~= 0 then

        if (totalWeight + (itemInfo["weight"] * amount)) <= ESX.GetConfig().MaxWeight then
            if Player.removeInventoryItem(item.name, amount, item.slot, item.info) and OtherPlayer.addInventoryItem(item.name, amount,false, item.info) then
               -- TriggerClientEvent('QBCore:Notify', src, "Şu İtemi Verdin : "..item.label..' Verilen : '..Target)
                TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'success', text = "Şu İtemi Verdin : "..item.label..' '})

                TriggerClientEvent("inventory:client:ItemBox",src, ESX.GetItems()[item.name],'remove',amount)
                --TriggerClientEvent('QBCore:Notify', name, "Şu İtemi Aldın : "..item.label..' Veren : '..YourName)
                TriggerClientEvent('mythic_notify:client:SendAlert', name, { type = 'success', text = "Şu İtemi Aldın : "..item.label..''})

                --TriggerClientEvent("inventory:client:ItemBox",OtherPlayer.source, ESX.GetItems()[item.name],'add',amount)
            end
        else
            TriggerClientEvent('mythic_notify:client:SendAlert', Player.source, { type = 'error', text = 'Karşıdaki kişi maksimum kiloda'})
            TriggerClientEvent('mythic_notify:client:SendAlert', OtherPlayer.source, { type = 'error', text = 'Maksimum ağırlığa ulaştınız item eklenmedi'})
        end
    end
end)

-client.lua

Code:
Client Part
RegisterNUICallback("GiveItem", function(data, cb)
    local player, distance = ESX.Game.GetClosestPlayer()
    if player ~= -1 and distance < 2.5 then
        local playerPed = GetPlayerPed(player)
        local playerId = GetPlayerServerId(player)
        local plyCoords = GetEntityCoords(playerPed)
        local pos = GetEntityCoords(GetPlayerPed(-1))
        local dist = GetDistanceBetweenCoords(pos.x, pos.y, pos.z, plyCoords.x, plyCoords.y, plyCoords.z, true)
        if dist < 2.5 then
            SetCurrentPedWeapon(PlayerPedId(),'WEAPON_UNARMED',true)
            TriggerServerEvent("inventory:server:GiveItem", playerId, data.inventory, data.item, data.amount)
            print(data.amount)
        else
            exports['mythic_notify']:SendAlert('error', 'Yakın Değilsin!', 5500, { ['background-color'] = '#ff0000', ['color'] = '#000000' })
        end
    else
         exports['mythic_notify']:SendAlert('error', 'Yakında kiimse yok!', 5500, { ['background-color'] = '#ff0000', ['color'] = '#000000' })
    end
end)


-html

Code:
HTML Part
<div class="inv-options">
      <div class="inv-options-list">
            <input type="number" id="item-amount" class="inv-option-item" min=0 value="1" oninput="validity.valid||(value='');"></input>
                  <div class="inv-option-item" id="item-use"><p>Use</p></div>
                  <div class="inv-option-item" id="item-give"><p>Give</p></div>
       </div>
 </div>
 
Last edited:

Tuxbox

Gold Elite
Joined
Sep 7, 2021
Messages
59
Reaction score
277
Points
311
Location
Germany
First of all, thank you for sharing, I'll test it and post my experiences here
 

JKA

Silver Elite
Joined
Mar 9, 2021
Messages
44
Reaction score
22
Points
221
First of all, thank you for sharing, I'll test it and post my experiences here
When you finish and all good can you send me your script please?
 

JKA

Silver Elite
Joined
Mar 9, 2021
Messages
44
Reaction score
22
Points
221
Greetings to all Vag forum users, I saw that the "give items to qb to esx inventory" part has not been shared on the forum before. I found it from a different place and tried to fix it by making small additions and I wanted to share with you if there are error solutions you want to see in this kind of guide titles, don't forget to leave a comment below, I hope you like it. Good forum to you all.

---------------------------------------------------------------- ----------ESX--------------------------------------- -----------------

-js

JavaScript:
JS partial
$("#item-give").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");
        amount = $("#item-amount").val();
        if(fromData.count > 0) {
            $.post("http://qb-inventory/GiveItem", JSON.stringify({
                inventory: fromInventory,
                item: fromData,
                amount: parseInt(amount),
            }));
            Inventory.Close();
        }
    }
});


-server.lua

Code:
#ServerPart
RegisterServerEvent("inventory:server:GiveItem")
AddEventHandler('inventory:server:GiveItem', function(name, inventory, item, amount)
    local src = source
    local Player = ESX.GetPlayerFromId(src)
    local OtherPlayer = ESX.GetPlayerFromId(tonumber(name))
--   local Target = OtherPlayer.get("firstName")..' '..OtherPlayer.get("lastName")
  --  local YourName = Player.get("firstName")..' '..Player.get("lastName")
    local totalWeight = ESX.GetTotalWeight(OtherPlayer.inventory)
    local itemInfo = ESX.GetItems()[item.name:lower()]

    if amount ~= 0 then

        if (totalWeight + (itemInfo["weight"] * amount)) <= ESX.GetConfig().MaxWeight then
            if Player.removeInventoryItem(item.name, amount, item.slot, item.info) and OtherPlayer.addInventoryItem(item.name, amount,false, item.info) then
               -- TriggerClientEvent('QBCore:Notify', src, "Şu İtemi Verdin : "..item.label..' Verilen : '..Target)
                TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'success', text = "Şu İtemi Verdin : "..item.label..' '})

                TriggerClientEvent("inventory:client:ItemBox",src, ESX.GetItems()[item.name],'remove',amount)
                --TriggerClientEvent('QBCore:Notify', name, "Şu İtemi Aldın : "..item.label..' Veren : '..YourName)
                TriggerClientEvent('mythic_notify:client:SendAlert', name, { type = 'success', text = "Şu İtemi Aldın : "..item.label..''})

                --TriggerClientEvent("inventory:client:ItemBox",OtherPlayer.source, ESX.GetItems()[item.name],'add',amount)
            end
        else
            TriggerClientEvent('mythic_notify:client:SendAlert', Player.source, { type = 'error', text = 'Karşıdaki kişi maksimum kiloda'})
            TriggerClientEvent('mythic_notify:client:SendAlert', OtherPlayer.source, { type = 'error', text = 'Maksimum ağırlığa ulaştınız item eklenmedi'})
        end
    end
end)

-client.lua

Code:
Client Part
RegisterNUICallback("GiveItem", function(data, cb)
    local player, distance = ESX.Game.GetClosestPlayer()
    if player ~= -1 and distance < 2.5 then
        local playerPed = GetPlayerPed(player)
        local playerId = GetPlayerServerId(player)
        local plyCoords = GetEntityCoords(playerPed)
        local pos = GetEntityCoords(GetPlayerPed(-1))
        local dist = GetDistanceBetweenCoords(pos.x, pos.y, pos.z, plyCoords.x, plyCoords.y, plyCoords.z, true)
        if dist < 2.5 then
            SetCurrentPedWeapon(PlayerPedId(),'WEAPON_UNARMED',true)
            TriggerServerEvent("inventory:server:GiveItem", playerId, data.inventory, data.item, data.amount)
            print(data.amount)
        else
            exports['mythic_notify']:SendAlert('error', 'Yakın Değilsin!', 5500, { ['background-color'] = '#ff0000', ['color'] = '#000000' })
        end
    else
         exports['mythic_notify']:SendAlert('error', 'Yakında kiimse yok!', 5500, { ['background-color'] = '#ff0000', ['color'] = '#000000' })
    end
end)


-html

Code:
HTML Part
<div class="inv-options">
      <div class="inv-options-list">
            <input type="number" id="item-amount" class="inv-option-item" min=0 value="1" oninput="validity.valid||(value='');"></input>
                  <div class="inv-option-item" id="item-use"><p>Use</p></div>
                  <div class="inv-option-item" id="item-give"><p>Give</p></div>
       </div>
 </div>


all is work but I can't give I just can drag the item to give and them I can't use this button
 

Suryawijaya

Gold Elite
Joined
Mar 16, 2021
Messages
73
Reaction score
39
Points
166
can u edit with a id player and add the box for give like choose a player with id
 

Blamntt

Bronze Elite
Joined
Mar 2, 2022
Messages
9
Reaction score
2
Points
146
Location
Darkcosmic2021
there is a slight error, you can literally duplicate the items, (users can put to give 99 having only 1 item and the server gives the 99 to the user, could you help me?
 

REFUZIION

Member
Joined
Oct 13, 2022
Messages
1
Reaction score
0
Points
146
Location
Netherlands
Late reaction but just implement a if statement comparing the inventory amount with the amount the user puts in. If the amount the user entered is HIGHER then the amount of items. Then return false.

if (!inputAmount > inventoryAmount)
-- dont transfer goods

OR put the code inside an if with the following attributes.

if(inputAmount <= inventoryAmount)
--transfer goods
 
Top