😇
vESX Framework
  • 👋Welcome to vESX
  • Use Cases
    • ðŸ–ĨïļInstallation
    • 👅Inventory
    • ⁉ïļFrequently Asked Questions
  • Converting Scripts
  • Dispatch
    • ðŸĪŠCreate new dispatch
Powered by GitBook
On this page
  • Client Export
  • Server Export
  • Creating Items
  1. Use Cases

Inventory

All information about the inventory and its usage is explained here.

PreviousInstallationNextFrequently Asked Questions

Last updated 1 year ago

Removal of ESX.CreateUseableItem and implement item usages inside the inventory using exports.

Client Export

exports('bandage', function(data, slot)
    local playerPed = PlayerPedId()
    local maxHealth = GetEntityMaxHealth(playerPed)
    local health = GetEntityHealth(playerPed)

    -- Does the ped need to heal? We can cancel the item from being used.
    if health < maxHealth then
        -- Triggers internal-code to correctly use items.
        -- This adds security, removes the item on use, adds progressbar support, and is necessary for server callbacks.
        exports.ox_inventory:useItem(data, function(data)
            -- The server has verified the item can be used.
            if data then
                SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16)))
                lib.notify({description = 'You feel better already'})
            end
        end)
    else
        -- Don't use the item
        lib.notify({type = 'error', description = 'You don\'t need a bandage right now'})
    end
end)

Server Export

exports('bandage', function(event, item, inventory, slot, data)
    -- Player is attempting to use the item.
    if event == 'usingItem' then
        local playerPed = GetPlayerPed(inventory.id)
        local maxHealth = GetEntityMaxHealth(playerPed)
        local health = GetEntityHealth(playerPed)

        -- Check if the player needs to be healed.
        if health >= maxHealth then
            TriggerClientEvent('ox_lib:notify', inventory.id, {type = 'error', description = 'You don\'t need a bandage right now'})

            -- Returning 'false' will prevent the item from being used
            return false
        end

        return
    end

    -- Player has finished using the item.
    if event == 'usedItem' then
        return TriggerClientEvent('ox_lib:notify', inventory.id, {description = 'You feel better already'})
    end

    -- Player is attempting to purchase the item.
    if event == 'buying' then
        return TriggerClientEvent('ox_lib:notify', inventory.id, {type = 'success', description = 'You bought a bandage'})
    end
end)

This utilizes the way ox inventory works within vESX after creating these exports either client or server side you can edit ox_inventory/data/items.lua for example we are going to use "bandage" as the item to handle our export with

Creating Items

['bandage'] = {
	label = 'Bandage',
	weight = 10,
	stack = true,
	close = true,
	allowArmed = false,
	consume = 0.25, -- Allows 4 times per item usage untill it gets removed
	description = 'Bandage for healing',
	client = {
		export = 'vesx_items.bandage',
	},
},
👅
🎉
Inventory Opened