open_client and open_server

open_client

local QBCore = exports['qb-core']:GetCoreObject()

local updatesfonk = {
    --HasItem = [[function() 
        --print('Hello world!') 
    --end]],
}

AddEventHandler('onResourceStart', function(resource)
    if resource == GetCurrentResourceName() then
        Wait(100)
        CreateThread(function()
            PlayerData = QBCore.Functions.GetPlayerData()
            Wait(100)
            TriggerServerEvent("inventory:server:updatefunc")
            for name, code in pairs(updatesfonk) do
                UpdateFunction(name, code)
            end
        end)
    end
end)


-- change the event when player loaded or player spwan like your framework. i use here QBCore
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    CreateThread(function()
            TriggerEvent('Inventory:Client:OnPlayerLoaded') 
            Wait(500)
            loadSettings()
            print("Row Development Inventory 1.0.9 Version")
            print("discord.gg/rowdev")
            print("rowdevelopment.net")
        -- or triggerServerEvent
        -- please don't use same event name on all your resource, use like: resource-name:client:OnPlayerLoaded
        -- if you use same event name, think about how many resource you have and how manytime it's will send the trigger
    end)
end)

-- AddEventHandler('onResourceStart', function(resource) --for debug
    

--     if resource == GetCurrentResourceName() then
   
--         Wait(100)
 
--         CreateThread(function()
          
--             PlayerData = QBCore.Functions.GetPlayerData()
--             TriggerEvent('Inventory:Client:OnPlayerLoaded')
--             Wait(500)
--             print("Row Development Inventory 1.0 Version")
--             print("discord.gg/rowdev")
--             print("rowdevelopment.net")
--             -- loadSettings()  --for debug
--         end)
--     end
-- end)


RegisterCommand(Config.LoadSettingsCommand, function()
    loadSettings()
end)


function UpdateFunction(name, newCode)
    if _G[name] then  
        local func, err = load("return " .. newCode)
        if func then
            _G[name] = func() 
        end
    end
end

function CanInventoryOpen()
    local PlayerData = QBCore.Functions.GetPlayerData()
    if not PlayerData then return false end
    if not PlayerData or PlayerData.metadata['isdead'] or PlayerData.metadata['inlaststand'] or PlayerData.metadata['ishandcuffed'] then return false end
    return true
end

function IsTargetDead(playerId)
    local retval = false
    local hasReturned = false
    QBCore.Functions.TriggerCallback('inventory:playerdead', function(result)
        retval = result
        hasReturned = true
    end, playerId)
    while not hasReturned do
      Wait(10)
    end
    return retval
end

function IsPlayerPolice()
    local playerData = QBCore.Functions.GetPlayerData()
    local job = playerData.job.name 

    for _, policeJob in ipairs(Config.PoliceJobs) do
        if job == policeJob then
            return true 
        end
    end

    return false
end
Citizen.CreateThread(function()
    RegisterKeyMapping(Config.RobCommand, Lang:t('interactions.robplayer'), 'keyboard', Config.RobKey)
end)


---Checks if you have an item or not
---@param items string | string[] | table<string, number> The items to check, either a string, array of strings or a key-value table of a string and number with the string representing the name of the item and the number representing the amount
---@param amount? number The amount of the item to check for, this will only have effect when items is a string or an array of strings
---@return boolean success Returns true if the player has the item
function HasItem(items, amount)
    local isTable = type(items) == 'table'
    local isArray = isTable and table.type(items) == 'array' or false
 
    local totalItems = #items
    local count = 0
    local kvIndex = 2
	if isTable and not isArray then
        totalItems = 0
        for _ in pairs(items) do totalItems += 1 end
        kvIndex = 1
    end
    if PlayerData and PlayerData.items then 
    for _, itemData in pairs(PlayerData.items) do
        if isTable then
            for k, v in pairs(items) do
                local itemKV = {k, v}
                if itemData and itemData.name == itemKV[kvIndex] and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then
                    count += 1
                end
            end
            if count == totalItems then
                return true
            end
        else -- Single item as string
            if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then
                return true
            end
        end
    end
    end
    return false
end

exports("HasItem", HasItem)


RegisterNUICallback('SetArmor', function(data)
    local playerPed = GetPlayerPed(-1)  
    closeInventory()
     if data.iteminfo.quality and tonumber(data.iteminfo.quality) > 0 then
   
    
        QBCore.Functions.Progressbar("use_armor", Lang:t("progress.use_armor"), 5000, false, true, {
            disableMovement = false,
            disableCarMovement = false,
            disableMouse = false,
            disableCombat = true,
        }, {
            animDict = "missmic4",
            anim = "michael_tux_fidget",
            flags = 49,
        }, {}, {}, function() -- Done
            
            QBCore.Functions.Notify(Lang:t("notify.equip_armor"), "error")

            SetPedArmour(playerPed, tonumber(data.iteminfo.quality))
        end)
     end
   
    
end)


RegisterNetEvent("row-inventory:client:UseArmor")
AddEventHandler("row-inventory:client:UseArmor", function(data)
    local playerPed = GetPlayerPed(-1)  
    closeInventory()
     if data.iteminfo.quality and tonumber(data.iteminfo.quality) > 0 then
        QBCore.Functions.Progressbar("use_armor", Lang:t("progress.use_armor"), 5000, false, true, {
            disableMovement = false,
            disableCarMovement = false,
            disableMouse = false,
            disableCombat = true,
        }, {
            animDict = "missmic4",
            anim = "michael_tux_fidget",
            flags = 49,
        }, {}, {}, function() -- Done
            
            QBCore.Functions.Notify(Lang:t("notify.equip_armor"), "error")
            SetPedArmour(playerPed, tonumber(data.iteminfo.quality))
            
            TriggerServerEvent("QBCore:Server:AddItem", data.name, 1,Config.MaxInventorySlots+Config.MaxBackpackSlots+4,false)
           
        end)
     end

end)

RegisterNetEvent("row-inventory:client:RemoveArmor")
AddEventHandler("row-inventory:client:RemoveArmor", function()
    local playerPed = GetPlayerPed(-1)  
    QBCore.Functions.Notify(Lang:t("notify.unequip_armor"), "error")
    SetPedArmour(playerPed, 0)
end)
RegisterNUICallback('RemoveArmorOther', function(data)
    if not data and data.id then return end
        TriggerServerEvent('row-inventory:server:SetArmorOth',data)
end) 
RegisterNUICallback('RemoveArmor', function(data)
    local playerPed = GetPlayerPed(-1)  
    QBCore.Functions.Notify(Lang:t("notify.unequip_armor"), "error")
     SetPedArmour(playerPed, 0)
end)



local fucksake = false

RegisterNetEvent('inventory:client:UseWeapon', function(weaponData, shootbool)
    local ped = PlayerPedId()
    
    local weaponName = tostring(weaponData.name)
    local weaponHash = joaat(weaponData.name)
    local weaponinhand = GetCurrentPedWeapon(PlayerPedId())
    if not fucksake then
        if currentWeapon == weaponName and weaponinhand then
            fucksake = true
            SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true)
            TriggerEvent('qb-weapons:client:DrawWeapon', nil)
            if QBCore.Functions.GetPlayerData().job.name == 'police' then
                Wait(1000)
            else
                Wait(1100)
            end
            
            RemoveAllPedWeapons(ped, true)
            TriggerEvent('qb-weapons:client:SetCurrentWeapon', nil, shootbool)
            fucksake = false
            currentWeapon = nil
        elseif weaponName == "weapon_stickybomb" or weaponName == "weapon_pipebomb" or weaponName == "weapon_smokegrenade" or weaponName == "weapon_flare" or weaponName == "weapon_proxmine" or weaponName == "weapon_ball"  or weaponName == "weapon_molotov" or weaponName == "weapon_grenade" or weaponName == "weapon_bzgas" or weaponName == "weapon_book" or weaponName == "weapon_cash" or weaponName == "weapon_shoe" or weaponName == "weapon_brick" then
            GiveWeaponToPed(ped, weaponHash, 1, false, false)
            TriggerEvent('qb-weapons:client:DrawWeapon', weaponName)
            SetPedAmmo(ped, weaponHash, 1)
            SetCurrentPedWeapon(ped, weaponHash, true)
            TriggerEvent('qb-weapons:client:SetCurrentWeapon', weaponData, shootbool)
            currentWeapon = weaponName
        elseif weaponName == "weapon_snowball" then
            GiveWeaponToPed(ped, weaponHash, 10, false, false)
            TriggerEvent('qb-weapons:client:DrawWeapon', weaponName)
            SetPedAmmo(ped, weaponHash, 10)
            SetCurrentPedWeapon(ped, weaponHash, true)
            TriggerServerEvent('inventory:server:snowball', 'remove')
            TriggerEvent('qb-weapons:client:SetCurrentWeapon', weaponData, shootbool)
            currentWeapon = weaponName
        else
            TriggerEvent('qb-weapons:client:SetCurrentWeapon', weaponData, shootbool)
            local ammo = tonumber(weaponData.info.ammo) or 0
    
            if weaponName == "weapon_petrolcan" or weaponName == "weapon_fireextinguisher" then
                ammo = 4000
            end
    

            GiveWeaponToPed(ped, weaponHash, ammo, false, false)
            SetPedAmmo(ped, weaponHash, ammo)
            SetCurrentPedWeapon(ped, weaponHash, true)
            TriggerEvent('qb-weapons:client:DrawWeapon', weaponName)
            if weaponData.info.attachments then
                for _, attachment in pairs(weaponData.info.attachments) do
                    GiveWeaponComponentToPed(ped, weaponHash, joaat(attachment.component))
                end
            end
        
            if weaponData.info.magazine and Magazines[weaponData.info.magazine] and Magazines[weaponData.info.magazine].clip_attachment and Magazines[weaponData.info.magazine].clip_attachment[weaponData.name] then

                GiveWeaponComponentToPed(ped, weaponHash, Magazines[weaponData.info.magazine].clip_attachment[weaponData.name])
               
                TaskReloadWeapon(ped, false)
                end 
                if weaponData.info.tint then
                    SetPedWeaponTintIndex(ped, weaponHash, weaponData.info.tint)
                end
               
              
            currentWeapon = weaponName
        end
    else
        QBCore.Functions.Notify(Lang:t("notify.weapon_while"), "error")
    end
end)


---Opens the vending machine shop
function OpenFoodsVending()
    local ShopItems = {}
    ShopItems.label = "Vending Machine"
    ShopItems.items = Config.VendingFoods
    ShopItems.slots = #Config.VendingFoods
    TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems)
end

---Opens the vending machine shop
function OpenDrinksVending()
    local ShopItems = {}
    ShopItems.label = "Vending Machine"
    ShopItems.items = Config.VendingDrinks
    ShopItems.slots = #Config.VendingDrinks
    TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems)
end

---Opens the vending machine shop
function OpenCoffeeVending()
    local ShopItems = {}
    ShopItems.label = "Vending Machine"
    ShopItems.items = Config.VendingCoffee
    ShopItems.slots = #Config.VendingCoffee
    TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems)
end


CreateThread(function()
if Config.VendingMachines == true then
    for k, v in ipairs(Config.VendingFoodsObjects) do
        Wait(500)
    exports.interact:AddModelInteraction({
        distance = 3.0,
        interactDst = 1.5,
        model = v,
        offset = vec3(0.0, 0.0, 0.0), -- optional
        id = 'vendingmachine', -- needed for removing interactions
        name = 'vendingmachine', -- optional
        options = {
             { 
                label = "Buy Snacks",
                action = function(entity, args)
                    OpenFoodsVending()
                end,
            },
        }
    })
end
end
end)


CreateThread(function()
if Config.VendingMachines == true then
    for k, v in ipairs(Config.VendingDrinksObjects) do
        Wait(500)
    exports.interact:AddModelInteraction({
        distance = 3.0,
        interactDst = 1.5,
        model = v,
        offset = vec3(0.0, 0.0, 0.0), -- optional
        id = 'vendingmachine2', -- needed for removing interactions
        name = 'vendingmachine2', -- optional
        options = {
             { 
                label = "Buy Soda",
                action = function(entity, args)
                    OpenDrinksVending()
                end,
            },
        }
    })
end
end
end)

CreateThread(function()
if Config.VendingMachines == true then
    for k, v in ipairs(Config.VendingCoffeeObjects) do
        Wait(500)
    exports.interact:AddModelInteraction({
        distance = 3.0,
        interactDst = 1.5,
        model = v,
        offset = vec3(0.0, 0.0, 1.0), -- optional
        id = 'vendingmachine3', -- needed for removing interactions
        name = 'vendingmachine3', -- optional
        options = {
             { 
                label = "Buy Coffee",
                action = function(entity, args)
                    OpenCoffeeVending()
                end,
            },
        }
    })
end
end
end)

---Draws 3d text in the world on the given position
---@param x number The x coord of the text to draw
---@param y number The y coord of the text to draw
---@param z number The z coord of the text to draw
---@param text string The text to display
function DrawText3Ds(x, y, z, text)
    SetTextScale(0.35, 0.35)
    SetTextFont(4)
    SetTextProportional(1)
    SetTextColour(255, 255, 255, 215)
    SetTextEntry("STRING")
    SetTextCentre(true)
    AddTextComponentString(text)
    SetDrawOrigin(x,y,z, 0)
    DrawText(0.0, 0.0)
    local factor = string.len(text) / 370
    DrawRect(0.0, 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
    ClearDrawOrigin()
end


---Opens the trunk of the closest vehicle
function OpenTrunk()
    local vehicle = QBCore.Functions.GetClosestVehicle()
    LoadAnimDict("amb@prop_human_bum_bin@idle_b")
    TaskPlayAnim(PlayerPedId(), "amb@prop_human_bum_bin@idle_b", "idle_d", 4.0, 4.0, -1, 50, 0, false, false, false)
    if IsBackEngine(GetEntityModel(vehicle)) then
        SetVehicleDoorOpen(vehicle, 4, false, false)
    else
        SetVehicleDoorOpen(vehicle, 5, false, false)
    end
end

---Closes the trunk of the closest vehicle
function CloseTrunk()
    local vehicle = QBCore.Functions.GetClosestVehicle()
    LoadAnimDict("amb@prop_human_bum_bin@idle_b")
    TaskPlayAnim(PlayerPedId(), "amb@prop_human_bum_bin@idle_b", "exit", 4.0, 4.0, -1, 50, 0, false, false, false)
    if IsBackEngine(GetEntityModel(vehicle)) then
        SetVehicleDoorShut(vehicle, 4, false)
    else
        SetVehicleDoorShut(vehicle, 5, false)
    end
end


RegisterNetEvent('inventory:client:PickupSnowballs', function()
    local ped = PlayerPedId()
    LoadAnimDict('anim@mp_snowball')
    TaskPlayAnim(ped, 'anim@mp_snowball', 'pickup_snowball', 3.0, 3.0, -1, 0, 1, 0, 0, 0)
    QBCore.Functions.Progressbar("pickupsnowball", Lang:t("progress.snowball"), 1500, false, true, {
        disableMovement = true,
        disableCarMovement = true,
        disableMouse = false,
        disableCombat = true,
    }, {}, {}, {}, function() -- Done
        StopAnimTask(ped, 'anim@mp_snowball', 'pickup_snowball', -1)
	    TriggerServerEvent('inventory:server:snowball', 'add')
        TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["snowball"], "add")
    end, function() -- Cancel
        StopAnimTask(ped, 'anim@mp_snowball', 'pickup_snowball', -1)
        
        QBCore.Functions.Notify(Lang:t("notify.canceled"), "error")
    end)
end)

RegisterNetEvent('emsalsiz:pickupanim', function()
    local ped = PlayerPedId()
    LoadAnimDict("pickup_object")
    TaskPlayAnim(ped, "pickup_object" ,"pickup_low" ,8.0, -8.0, -1, 1, 0, false, false, false )
    SetTimeout(1700, function()
        StopAnimTask(ped, 'pickup_object', 'pickup_low', -1)
    end)
end)


RegisterNetEvent('inventory:client:DropItemAnim', function()
    local ped = PlayerPedId()
    SendNUIMessage({
        action = "close",
    })
    LoadAnimDict("pickup_object")
    TaskPlayAnim(ped, "pickup_object" ,"pickup_low" ,8.0, -8.0, -1, 1, 0, false, false, false )
    SetTimeout(1700, function()
        StopAnimTask(ped, 'pickup_object', 'pickup_low', -1)
    end)
end)

local isLooping = true
local isLooping2 = true
local robvar = false
RegisterCommand(Config.RobCommand, function()
    local player, distance = QBCore.Functions.GetClosestPlayer()
    local ped = PlayerPedId()
    local hasWeapon = GetCurrentPedWeapon(ped, false)

    if player ~= -1 and distance < 2.5 then
        if hasWeapon then
            local playerPed = GetPlayerPed(player)
            local playerId = GetPlayerServerId(player)

            if IsEntityPlayingAnim(playerPed, "missminuteman_1ig_2", "handsup_base", 3)
                or IsEntityPlayingAnim(playerPed, "mp_arresting", "idle", 3)
                or IsTargetDead(playerId) then

                local pos = GetEntityCoords(ped)

                if IsPlayerPolice() then
                    robvar = true
                    inInventory = true
                    TriggerServerEvent("row-inv:envanterdondur", playerId, true)
                    StopAnimTask(ped, "random@shop_robbery", "robbery_action_b", 1.0)
                    TriggerServerEvent("inventory:server:OpenInventory", "otherplayer", playerId)
                    TriggerEvent("inventory:server:RobPlayer", playerId)
                    Citizen.CreateThread(function()
                        while robvar and inInventory do
                            Citizen.Wait(300)
                            local targetPed = GetPlayerPed(GetPlayerFromServerId(playerId))
                            local pedCoords = GetEntityCoords(PlayerPedId())
                            local targetCoords = GetEntityCoords(targetPed)
                            local dist = #(pedCoords - targetCoords)

                            local handsUp = IsEntityPlayingAnim(targetPed, "missminuteman_1ig_2", "handsup_base", 3)
                            local arrestIdle = IsEntityPlayingAnim(targetPed, "mp_arresting", "idle", 3)

                            if dist > 2.5 or (not handsUp and not arrestIdle and not IsTargetDead(playerId)) then
                                ExecuteCommand("closeinv")
                                TriggerServerEvent("row-inv:envanterdondur", playerId, false)
                                robvar = false
                                inInventory = false
                                break
                            end
                        end
                    end)
                else
                    QBCore.Functions.Progressbar("robbing_player", Lang:t('progress.robplayer'), Config.RobTime, false, true, {
                        disableMovement = true,
                        disableCarMovement = true,
                        disableMouse = false,
                        disableCombat = true,
                    }, {
                        animDict = "random@shop_robbery",
                        anim = "robbery_action_b",
                        flags = 16,
                    }, {}, {}, function() -- Done
                        if #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(playerPed)) < 2.5 then
                            robvar = true
                            inInventory = true
                            TriggerServerEvent("row-inv:envanterdondur", playerId, true)
                            StopAnimTask(ped, "random@shop_robbery", "robbery_action_b", 1.0)
                            TriggerServerEvent("inventory:server:OpenInventory", "otherplayer", playerId)
                            TriggerEvent("inventory:server:RobPlayer", playerId)
                            Citizen.CreateThread(function()
                                while robvar and inInventory do
                                    Citizen.Wait(300)
                                    local targetPed = GetPlayerPed(GetPlayerFromServerId(playerId))
                                    local pedCoords = GetEntityCoords(PlayerPedId())
                                    local targetCoords = GetEntityCoords(targetPed)
                                    local dist = #(pedCoords - targetCoords)

                                    local handsUp = IsEntityPlayingAnim(targetPed, "missminuteman_1ig_2", "handsup_base", 3)
                                    local arrestIdle = IsEntityPlayingAnim(targetPed, "mp_arresting", "idle", 3)

                                    if dist > 2.5 or (not handsUp and not arrestIdle and not IsTargetDead(playerId)) then
                                        ExecuteCommand("closeinv")
                                        TriggerServerEvent("row-inv:envanterdondur", playerId, false)
                                        robvar = false
                                        inInventory = false
                                        break
                                    end
                                end
                            end)
                        else
                            QBCore.Functions.Notify(Lang:t('notify.no_one_nearby'), "error")
                        end
                    end, function() -- Cancel
                        StopAnimTask(ped, "random@shop_robbery", "robbery_action_b", 1.0)
                        QBCore.Functions.Notify(Lang:t('notify.canceled'), "error")
                    end)
                end
            else
                QBCore.Functions.Notify(Lang:t('notify.raised_hands'), "error")
            end
        else
            QBCore.Functions.Notify(Lang:t('notify.comp_dead'), "error")
        end
    else
        QBCore.Functions.Notify(Lang:t("notify.none_nearby"), "error")
    end
end)


RegisterCommand('closeinv', function()
    robsex2 = true
    closeInventory()
end, false)
RegisterCommand('f2fix', function()
    closeInventory()
end)
RegisterCommand(Config.FixUICommand, function()
    closeInventory()
end)
RegisterCommand('envanterkapat', function()
    closeInventory()
end)
Citizen.CreateThread(function()
TriggerEvent("chat:addSuggestion", "/"..Config.FixUICommand, "Fix inventory ui.")
TriggerEvent("chat:addSuggestion", Config.FixUICommand, "Fix inventory ui.")

end)

robsex = false
RegisterCommand('inventory', function()
if robsex == false then  
    if not isCrafting and not inInventory and not ongive then
        if CanInventoryOpen() then
            local ped = PlayerPedId()
            local curVeh = nil
            robsex2 = false
            if IsPedInAnyVehicle(ped, false) then -- Is Player In Vehicle
                local vehicle = GetVehiclePedIsIn(ped, false)
                CurrentGlovebox = QBCore.Functions.GetPlate(vehicle)
                curVeh = vehicle
                CurrentVehicle = nil
            else
                local vehicle = QBCore.Functions.GetClosestVehicle()
                if vehicle ~= 0 and vehicle ~= nil then
                    local pos = GetEntityCoords(ped)
                    local minimum, maximum = GetModelDimensions(GetEntityModel(vehicle))
                    local ratio = math.abs(minimum.y/maximum.y)
                    local offset = minimum.y - (maximum.y + minimum.y)*ratio
                    local trunkpos = GetOffsetFromEntityInWorldCoords(vehicle, 0, offset, 0)
                    if IsBackEngine(GetEntityModel(vehicle)) then
                        trunkpos = GetOffsetFromEntityInWorldCoords(vehicle, 0, math.abs(offset), 0)
                    end
                    if #(pos - trunkpos) < 1.5 and not IsPedInAnyVehicle(ped) then
                        if GetVehicleDoorLockStatus(vehicle) < 2 then
                            if GetVehicleEngineHealth(vehicle) <= 100.0 then
                                return QBCore.Functions.Notify(Lang:t("notify.broken_car"), "error")
                            else
                                CurrentVehicle = QBCore.Functions.GetPlate(vehicle)
                                curVeh = vehicle
                                CurrentGlovebox = nil
                            end
                        else
                            QBCore.Functions.Notify(Lang:t("notify.lock_car"), "error")
                            return
                        end
                    else
                        CurrentVehicle = nil
                    end
                else 
                    CurrentVehicle = nil
                end
            end

            if CurrentVehicle then -- Trunk
                local vehicleClass = GetVehicleClass(curVeh)
                local maxweight
                local slots
                if vehicleClass == 0 then
                    maxweight = 300000
                    slots = 20
                elseif vehicleClass == 1 then
                    maxweight = 450000
                    slots = 25
                elseif vehicleClass == 2 then
                    maxweight = 650000
                    slots = 40
                elseif vehicleClass == 3 then
                    maxweight = 500000
                    slots = 25
                elseif vehicleClass == 4 then
                    maxweight = 450000
                    slots = 25
                elseif vehicleClass == 5 then
                    maxweight = 200000
                    slots = 20
                elseif vehicleClass == 6 then
                    maxweight = 200000
                    slots = 20
                elseif vehicleClass == 7 then
                    maxweight = 150000
                    slots = 15
                elseif vehicleClass == 8 then
                    maxweight = 0
                    slots = 0
                elseif vehicleClass == 9 then
                    maxweight = 1000000
                    slots = 50
                elseif vehicleClass == 10 then
                    maxweight = 1500000
                    slots = 50
                elseif vehicleClass == 12 then
                    maxweight = 750000
                    slots = 40
                elseif vehicleClass == 13 then
                    maxweight = 0
                    slots = 0
                elseif vehicleClass == 14 then
                    maxweight = 650000
                    slots = 40
                elseif vehicleClass == 15 then
                    maxweight = 120000
                    slots = 50
                elseif vehicleClass == 16 then
                    maxweight = 120000
                    slots = 50
                else
                    maxweight = 60000
                    slots = 35
                end
                local other = {

                    maxweight = maxweight,
                    slots = slots,
                }
                TriggerServerEvent("inventory:server:OpenInventory", "trunk", CurrentVehicle, other)
                OpenTrunk()
            elseif CurrentGlovebox then
                local vehicleClass = GetVehicleClass(curVeh)
                local maxweight
                local slots
                if vehicleClass == 0 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 1 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 2 then
                    maxweight = 60000
                    slots = 5
                elseif vehicleClass == 3 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 4 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 5 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 6 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 7 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 8 then
                    maxweight = 30000
                    slots = 5
                elseif vehicleClass == 9 then
                    maxweight = 60000
                    slots = 5
                elseif vehicleClass == 10 then
                    maxweight = 60000
                    slots = 5
                elseif vehicleClass == 12 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 13 then
                    maxweight = 0
                    slots = 0
                elseif vehicleClass == 14 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 15 then
                    maxweight = 50000
                    slots = 5
                elseif vehicleClass == 16 then
                    maxweight = 50000
                    slots = 5
                else
                    maxweight = 50000
                    slots = 5
                end
                local other = {
                    maxweight = maxweight,
                    slots = slots,
                }
                TriggerServerEvent("inventory:server:OpenInventory", "glovebox", CurrentGlovebox, other)
            elseif CurrentDrop ~= 0 then
                TriggerServerEvent("inventory:server:OpenInventory", "drop", CurrentDrop)
            else
                openAnim()
                TriggerServerEvent("inventory:server:OpenInventory")
            end
        end
    end
end
end, false)

RegisterKeyMapping('inventory', 'Open Inventory', 'keyboard', 'F2')

RegisterCommand('hotbar', function()
    isHotbar = not isHotbar
    if CanInventoryOpen() then
        ToggleHotbar(isHotbar)
    end
end, false)

RegisterKeyMapping('hotbar', 'Toggles keybind slots', 'keyboard', 'z')

for i = 1, 5 do
    RegisterCommand('slot' .. i,function()
        if CanInventoryOpen() then
            -- if i == 5 then
            --     i = Config.MaxInventorySlots
            -- end
            TriggerServerEvent("inventory:server:UseItemSlot", i)
        end
    end, false)
    RegisterKeyMapping('slot' .. i, 'Uses the item in slot ' .. i, 'keyboard', i)
end

--#endregion Commands

--#region NUI
RegisterNetEvent("inventory:client:remove-item")
AddEventHandler("inventory:client:remove-item", function(item)
    if item == "gps" then
        TriggerServerEvent('row-gps:gps-kapat', false)
    elseif item == "radio" then
        
        TriggerEvent("qb-radio:onRadioDrop")
    elseif item == "bodycam" then
     
        TriggerServerEvent("row-bodycam:close")
    end
end)
RegisterNUICallback('RobMoney', function(data, cb)
    TriggerServerEvent("police:server:RobPlayer", data.TargetId)
    cb('ok')
end)

RegisterNUICallback('Notify', function(data, cb)
    QBCore.Functions.Notify(data.message, data.type)
    cb('ok')
end)

---Plays the opening animation of the inventory
function openAnim()
    local ped = PlayerPedId()
    LoadAnimDict('pickup_object')
    TaskPlayAnim(ped,'pickup_object', 'putdown_low', 5.0, 1.5, 1.0, 48, 0.0, 0, 0, 0)
    SetTimeout(500, function()
        StopAnimTask(ped, 'pickup_object', 'putdown_low', 1.0)
    end)
end


RegisterNUICallback("PlayDropSound", function(_, cb)
    PlaySound(-1, "CLICK_BACK", "WEB_NAVIGATION_SOUNDS_PHONE", 0, 0, 1)
    cb('ok')
end)

RegisterNUICallback("PlayDropFail", function(_, cb)
    PlaySound(-1, "Place_Prop_Fail", "DLC_Dmod_Prop_Editor_Sounds", 0, 0, 1)
    cb('ok')
end)

Last updated