Ox_inventory

I have a quick question I would like to create an ammo box that would give me the ammo inside.

Example I buy a box of ammo which contains 30 ammo inside. When I open the box the box disappears from my inventory but I receive the 30 ammo.

Is it possible ? if so can you show me an example or tell me which path to follow to achieve this. Thanks in advance.

You can register the item in a external script or in the inventory itself there is a module/client/item file where the client events for an item can be set.

1 Like

You can create a container which gives you a certain amount of rounds when the ammo box is used. There are a few free resources that already do this for you, but reading the provided documentation should help you roll your own solution.

1 Like

You must define what the item does when it is used, on the server side, in the same ox_inventory script it brings a file that is /modules/items/server.lua

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)

All this and more is in the documentation

1 Like

try this in ox_inventory/modules/items/server.lua

Item('ammobox', function(event, item, inventory, data, slot)
    if event == 'usedItem' then
        Inventory.AddItem(inventory, 'ammo-9', 30)
    end
end)
2 Likes

Thanks perfect ! :slight_smile:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.