#PS_MDT não funcio o hook do ox_inventory

1 messages · Page 1 of 1 (latest)

obtuse drum
#

Estava verificando a questão de registro de armas no mdt e notei que simplesmente o hook não está funcionando, fiz alguns prints para debug e percebi que não tenho resposta após o registerHook.

if Config.InventoryForWeaponsImages == "ox_inventory" and Config.RegisterWeaponsAutomatically then
    print("Registering ox_inventory hooks for weapon registration")
    exports.ox_inventory:registerHook('buyItem', function(payload)
        print("BUY HOOK TRIGGERED")
        if not string.find(payload.itemName, "WEAPON_") then return true end
        print("Weapon okay")
        CreateThread(function()
            local owner = QBCore.Functions.GetPlayer(payload.source).PlayerData.citizenid
            if not owner or not payload.metadata.serial then return end
            local imageurl = ("https://cfx-nui-ox_inventory/web/images/%s.png"):format(payload.itemName)
            local notes = "Purchased from shop"
            local weapClass = "Class" --@TODO retrieve class better
            print ("Creating weapon info with serial: " .. payload.metadata.serial
            .. " imageurl: " .. imageurl
            .. " notes: " .. notes
            .. " owner: " .. owner
            .. " weapClass: " .. weapClass
            .. " itemName: " .. payload.itemName)
            local success, result = pcall(function()
                return CreateWeaponInfo(payload.metadata.serial, imageurl, notes, owner, weapClass, payload.itemName)
            end)


            if not success then
                print("Error in creating weapon info in MDT: " .. result)
            end
        end)
        return true
    end, {
        typeFilter = { ['player'] = true }
    })
    -- This is for other shop resources that use the AddItem method. 
    -- Only registers weapons with serial numbers, must specify a slot in ox_inventory:AddItem with metadata
    -- metadata = {
    --   registered = true
    -- }
    if Config.RegisterCreatedWeapons then
        exports.ox_inventory:registerHook('createItem', function(payload)
            if not string.find(payload.item.name, "WEAPON_") then return true end
            print("Creating item")
            CreateThread(function()
                local owner = QBCore.Functions.GetPlayer(payload.inventoryId).PlayerData.citizenid
                if not owner or not payload.metadata.serial then return end
                local imageurl = ("https://cfx-nui-ox_inventory/web/images/%s.png"):format(payload.item.name)
                local notes = "Purchased from shop"
                local weapClass = "Class" --@TODO retrieve class better

                local success, result = pcall(function()
                    return CreateWeaponInfo(payload.metadata.serial, imageurl, notes, owner, weapClass, payload.item.name)
                end)

                if not success then
                    print("Error in creating weapon info in MDT: " .. result)
                end
            end)
            return true
        end, {
            typeFilter = { ['player'] = true }
        })
    end
end
#

[ script:ps-mdt] Registering ox_inventory hooks for weapon registration

#

Estou usando o shops nativo ox_inventory