HEX
HexscriptsVersion 4.0Inventory

Configurations

Here you will get all configurations & open source files that are included within this script.

Config Files

Config = {}

Config.Debug = false -- Set to true to enable debug messages in the console
Config.Locale = 'automatic' -- automatic, en, de, es, fr, it, nl, pl, pt, tr, ar
Config.Framework = 'automatic' -- automatic, esx, qbcore, standalone

-- if you need a bridge for ox_inventory, set this to "ox_inventory" it will use the ammo system from ox_inventory, if you need more please open a ticket on discord.
--[[
    ox_inventory: it will use the ammo system from ox_inventory, if you need more please open a ticket on discord.
    chezza: if you are using chezza's inventory, set this to "chezza" and it will migrate the inventory data from chezza's inventory to the new inventory when the player first opens their inventory, after that it will work like normal and save the data in the new format. Please note that this is a one time migration and after the inventory has been migrated.
]]
Config.Bridge = false

Config.Weights = {
    -- ['phone'] = 5, -- Example of how to set a custom weight for an item, this would set the weight of the phone item to 5
    -- ['WEAPON_PISTOL'] = 2, -- Example of how to set a custom weight for a weapon, this would set the weight of the pistol to 2
}

Config.DontCloseUI = { 'clip' } -- These items won't close the Inventory after usage
Config.DontOpenTrunkGloveboxWithPlates = { 'HEXRP' } -- These Numberplates won't have a Glovebox/Trunk

Config.UseBlur = false -- Set to false to disable the blur effect when opening the inventory
Config.UseCloseAnimation = false -- Set to true to enable a closing animation when closing the inventory
Config.UseInventoryAudio = true -- Set to false to disable inventory sounds
Config.RightClick = true -- Use right click instead of all left click control

Config.DatabaseSave = { 
    type = 'timeout', -- timeout or close
    ms = 1000 * 60 -- Time in ms for the timeout, only needed if you choose timeout as type
}

Config.Drops = {
    deleteAfter = 600, -- Time in seconds after which the drop will be deleted
    deleteAfterIfPlaced = 43200, -- Time in seconds after which the drop will be deleted if it has been placed on the ground via the "Place" option
    save = true, -- Whether to save drops into the database so they dont disappear after Restarts
    openDistance = 2.0, -- Distance within which players can open the drop
    marker = {
        type = 2,
        scale = vector3(0.3, 0.3, 0.3),
        color = {
            red = 255,
            green = 0,
            blue = 0,
            alpha = 100
        },
        bobUpAndDown = false,
        faceCamera = true,
        rotate = false,
        zOffset = 0.5
    }
}

Config.PlaceObjects = {
    ['money'] = {
        [0] = 'prop_anim_cash_note', -- From 0 - 49 the Money Prop will be this
        [50] = 'sf_prop_sf_cash_pile_01', -- From 50 - 499 the Money Prop will be this
        [500] = 'prop_anim_cash_pile_02',
        [5000] = 'ex_prop_exec_cashpile',
        [50000] = 'hei_prop_heist_trevor_case'
    },

    ['phone'] = 'prop_amb_phone', -- Normal Props without different count Variations
    ['WEAPON_PISTOL'] = 'w_pi_pistol',
    ['water'] = 'prop_ld_flow_bottle'
}

Config.PlaceColorHover = { -- Hover Color for placed Items
    red = 255,
    green = 0,
    blue = 0,
    alpha = 100
}

Config.GiveMarker = { -- Settings for the Marker used for our custom give System
    type = 0,
    scale = vector3(0.2, 0.2, 0.2),
    color = {
        red = 255,
        green = 0,
        blue = 0,
        alpha = 100
    },
    bobUpAndDown = true,
    faceCamera = true,
    rotate = true,
    zOffset = 1.10
}

Config.ServerName = 'HEXSCRIPTS' -- Your Server Name for the main UI
Config.ServerImgs = 'img/icons/' -- Path to the folder where the item icons are stored. (Can also be a CDN URL)

Config.Commands = {
    ['openinv'] = { -- This command allows admins to open other players inventorys and give/remove stuff
        enabled = true,
        commandName = 'openinv',
        permissions = {
            'admin'
        }
    },

    ['bypassWeightLimit'] = { -- This commands let admins bypass the maximum weight
        enabled = true,
        commandName = 'bypassweight',
        permissions = {
            'admin'
        }
    }
}

Config.KeyBinds = {
    ['openInventory'] = { -- Main Keybind
        commandName = 'openInventory',
        description = 'Open Inventory', 
        key = 'I'
    },

    ['openInventoryTrunk'] = { -- Keybind for Trunk
        commandName = 'openInventoryTrunk',
        description = 'Open Inventory Trunk', 
        key = 'L' -- or false to disable keybind
    }
}

Config.DebugPrintOpenTrunk = true -- Set to true to enable a print when opening a Trunk to see the Vehicles Model in F8

Config.TrunkCustomDistance = { -- For larger Vehicles, for example the Tug Boat has 12.5 radius to access its trunk
    [joaat('tug')] = 12.5,
}

-- Default weights for vehicle trunks based on their class
Config.TrunkWeights = {
    [0] = 30, -- Compact
    [1] = 40, -- Sedan
    [2] = 75, -- SUVs
    [3] = 40, -- Coupes
    [4] = 40, -- Muscle
    [5] = 25, -- Sports Classics
    [6] = 40, -- Sports
    [7] = 5, -- Super
    [8] = 0, -- Motorcycles
    [9] = 70, -- Off-road
    [10] = 50, -- Industrial
    [11] = 50, -- Utility
    [12] = 50, -- Vans
    [13] = 0, -- Cycles
    [14] = 10, -- Boats
    [15] = 0, -- Helicopters
    [16] = 10, -- Planes
    [17] = 40, -- Service
    [18] = 35, -- Emergency
    [19] = 0, -- Military
    [20] = 35, -- Commercial
    [21] = 0, -- Trains
    [22] = 0, -- Open Wheel
}

-- Default weights for vehicle gloveboxes based on their class
Config.GloveWeights = {
    [0] = 30, -- Compact
    [1] = 40, -- Sedan
    [2] = 75, -- SUVs
    [3] = 40, -- Coupes
    [4] = 40, -- Muscle
    [5] = 25, -- Sports Classics
    [6] = 40, -- Sports
    [7] = 5, -- Super
    [8] = 0, -- Motorcycles
    [9] = 70, -- Off-road
    [10] = 50, -- Industrial
    [11] = 50, -- Utility
    [12] = 50, -- Vans
    [13] = 0, -- Cycles
    [14] = 10, -- Boats
    [15] = 0, -- Helicopters
    [16] = 10, -- Planes
    [17] = 40, -- Service
    [18] = 35, -- Emergency
    [19] = 0, -- Military
    [20] = 35, -- Commercial
    [21] = 0, -- Trains
    [22] = 0, -- Open Wheel
}

-- Custom weights for specific vehicle models, these override the default weights based on vehicle type
Config.TrunkModels = {
    [joaat('asea')] = 50
}

-- Custom weights for specific glove models, these override the default weights based on vehicle type
Config.GloveModels = {
    [joaat('asea')] = 50
}

Open Source Files

if Config.Framework ~= 'esx' then return end

local ESX = nil

function loadFramework()
    local status, ESXLOAD = pcall(function()
        return exports['es_extended']:getSharedObject()
    end)

    ESX = ESXLOAD

    if not status then
        while not ESX do
            TriggerEvent("esx:getSharedObject", function(object) ESX = object end)
            Citizen.Wait(50)
        end
    end

    while ESX.GetPlayerData().job == nil do
        Citizen.Wait(50)
    end

    while not ESX.IsPlayerLoaded() do
        Citizen.Wait(50)
    end

    ESX.PlayerData = ESX.GetPlayerData()
end

function GetItemLabel(itemName)
	for k, v in ipairs(ESX.PlayerData.inventory) do
		if v.name == itemName then
            return v.label
		end
	end

    return itemName
end

function GetWeaponLabel(weaponName)
    return ESX.GetWeaponLabel(weaponName)
end

function GetAccountLabel(accountName)
    for k, v in pairs(ESX.PlayerData.accounts) do
        if v.name == accountName then
            return v.label
        end
    end

    return accountName
end

RegisterNetEvent('esx:setAccountMoney', function(account)
    for k, v in ipairs(ESX.PlayerData.accounts) do
        if v.name == account.name then
            ESX.PlayerData.accounts[k].money = account.money
            break
        end
    end
end)

RegisterNetEvent('esx:addInventoryItem', function(item, count)
	for k, v in ipairs(ESX.PlayerData.inventory) do
		if v.name == item then
			ESX.PlayerData.inventory[k].count = count
			break
		end
	end
end)

RegisterNetEvent('esx:removeInventoryItem', function(item, count)
	for k, v in ipairs(ESX.PlayerData.inventory) do
		if v.name == item then
			ESX.PlayerData.inventory[k].count = count
			break
		end
	end
end)

function GetItemCount(name)
    for k, v in pairs(ESX.PlayerData.inventory) do
        if v.name == name then
            return v.count
        end
    end

    return 0
end

RegisterNetEvent('esx:setMaxWeight', function(maxWeight)
    ESX.PlayerData.maxWeight = maxWeight
end)

function GetPlayerItems()
    local inventory = {}

    for k, v in pairs(ESX.PlayerData.inventory) do
        if v.count > 0 then
            inventory[#inventory + 1] = {
                name = v.name,
                label = v.label,
                count = v.count,
                type = 'item',
                use = v.usable,
                remove = true,
                place = Config.PlaceObjects[v.name] ~= nil
            }
        end
    end

    return inventory
end

function GetWeaponData(weaponName)
    for k, v in pairs(ESX.GetWeaponList()) do
        if v.name == weaponName then
            return v
        end
    end

    return nil
end

function GetComponentWeaponData(weaponName, componentName)
    local weaponData = GetWeaponData(weaponName)

    if weaponData and weaponData.components then
        for k, v in pairs(weaponData.components) do
            if v.name == componentName then
                return v
            end
        end
    end

    return nil
end

function GetPlayerWeapons()
    local ped = PlayerPedId()
    local weapons = {}

    for k, v in pairs(ESX.GetWeaponList()) do
        local weaponHash = joaat(v.name)

        if HasPedGotWeapon(ped, weaponHash, false) and v.name ~= 'WEAPON_UNARMED' then
            local comps = {}

            if v.tints then
                local weaponTint = GetPedWeaponTintIndex(ped, weaponHash)

                if weaponTint > 0 then
                    local tintLabel = v.tints[weaponTint]
                    comps[#comps + 1] = { tint = true, label = tintLabel }
                end
            end

            if v.components and #v.components > 0 then
                for k1, v1 in pairs(v.components) do
                    if v1 and not v1.name:find('_default') then
                        if HasPedGotWeaponComponent(ped, weaponHash, v1.hash) then
                            comps[#comps + 1] = { tint = false, label = v1.label }
                        end
                    end
                end
            end

            weapons[#weapons + 1] = {
                name = v.name,
                label = v.label,
                count = GetAmmoInPedWeapon(ped, weaponHash),
                type = 'weapon',
                use = false,
                remove = true,
                comps = comps,
                place = Config.PlaceObjects[v.name] ~= nil
            }
        end
    end

    return weapons
end

function GetPlayerAccounts()
    local accounts = {}

    for k, v in pairs(ESX.PlayerData.accounts) do
        if v.name ~= 'bank' and v.money > 0 then
            accounts[#accounts + 1] = {
                name = v.name,
                label = v.label,
                count = v.money,
                type = 'account',
                use = false,
                remove = true,
                place = Config.PlaceObjects[v.name] ~= nil
            }
        end
    end

    return accounts
end

function GetPlayerWeight()
    local weight = 0
    local maxWeight = ESX.PlayerData.maxWeight

    for k, v in pairs(ESX.PlayerData.inventory) do
        weight = weight + (v.weight * v.count)
    end

    return weight, maxWeight
end

function UseItem(itemName)
    TriggerServerEvent('esx:useItem', itemName)
end

function GiveInventoryItem(serverId, type, itemName, count)
    TriggerServerEvent("esx:giveInventoryItem", serverId, type, itemName, count)
end