404_ox_restricted_items

[FREE] 404_ox_restricted_items - Item Restriction System

Resource Description

404_ox_restricted_items is a simple and efficient item restriction system designed for servers using ox_inventory. This system prevents players from dropping, transferring, or giving specific items that you define in the configuration, effectively protecting important items from being improperly handled.

Key Features:

  • Prevents players from dropping restricted items

  • Blocks transfer of restricted items to other inventories

  • Stops players from giving restricted items to other players

  • Allows movement of restricted items within the same inventory

  • Supports custom notification messages

  • Built-in debug mode

  • Multi-language support (English, Chinese, Spanish, French)

Download Link

Download from GitHub

Installation Instructions

  1. Download the resource and extract to your server resources folder

  2. Configure the items you want to restrict in the config file

  3. Add ensure 404_ox_restricted_items to your server.cfg

  4. Restart your server

Resource Information

Code is accessible Yes
Subscription-based No
Lines (approximately) 89 lines
Requirements ox_inventory
Support Yes

Note: ox_lib is optional and only required if you want to use the notification features. The script uses ox_lib:notify for displaying messages to players when they attempt to move restricted items. If you don’t have ox_lib installed, you’ll need to modify the Notify function in config.lua to use your preferred notification system.

4 Likes

Let me think about it. My English is not good. This is a machine translation.:blush:

Do you have a case that works on ox_inventory ESX OLD?

Yes, it works as long as you’re using the latest ox_inventory. :kissing_heart:

If you encounter any errors or compatibility issues, feel free to post them here and I’ll do my best to help you fix them.

Hello, i updated your script if you wanna restrict weapons like items (with ox_inventory)

local function Initialize()
    DebugPrint('Initializing item restriction system')
    

    local function IsRestrictedItem(itemName)
        return Config.RestrictedItems[itemName] == true
    end

    local function IsWeapon(itemName)
        -- Vérifie si l'item est une arme en vérifiant si son nom commence par "WEAPON_"
        return string.match(string.upper(itemName), "^WEAPON_") ~= nil
    end

    local itemFilter = {
        swapItems = function(payload)
            if not payload then return true end
            if not payload.fromSlot then return true end
            if not payload.fromSlot.name then return true end

            local itemName = payload.fromSlot.name
            local toInventory = payload.toInventory
            local fromInventory = payload.fromInventory
            local toType = payload.toType
            local locale = GetLocale()

            if Config.Debug then
                DebugPrint('Received item swap request')
                DebugPrint(string.format('Item: %s', itemName))
                DebugPrint(string.format('From: %s', fromInventory))
                DebugPrint(string.format('To: %s', toInventory or toType or 'unknown'))
            end


            if IsRestrictedItem(itemName) or IsWeapon(itemName) then
                DebugPrint(string.format(locale.debug.item_check, itemName))
                
                if IsWeapon(itemName) then
                    DebugPrint('Item detected as weapon: ' .. itemName)
                end

                if Config.Debug then
                    DebugPrint('Detailed information:')
                    DebugPrint('fromInventory type: ' .. type(fromInventory))
                    DebugPrint('toInventory type: ' .. type(toInventory or 'nil'))
                    if toInventory then DebugPrint('toInventory: ' .. tostring(toInventory)) end
                    if toType then DebugPrint('toType: ' .. tostring(toType)) end
                end
                

                if toInventory and fromInventory and toInventory == fromInventory then
                    DebugPrint('Allowing movement within the same inventory')
                    return true
                end
                

                if toType == 'drop' then
                    Notify(fromInventory, locale.messages.discard)
                    return false

                elseif toType == 'player' then  
                    Notify(fromInventory, locale.messages.give)
                    return false

                elseif toInventory and toInventory ~= fromInventory then
                    Notify(fromInventory, locale.messages.transfer)
                    return false
                end
            end

            return true
        end,

        createItem = function(payload)
            return true
        end
    }


    exports.ox_inventory:registerHook('swapItems', itemFilter.swapItems)
    exports.ox_inventory:registerHook('createItem', itemFilter.createItem)
    
    DebugPrint('Item restriction system initialized')
end


AddEventHandler('onServerResourceStart', function(resourceName)
    if resourceName == GetCurrentResourceName() then
        Initialize()
    end
end)