Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export AddItem issue: bad 'for' limit (number expected, got nil) #1223

Closed
Legacy-TacticalGamingInteractive opened this issue Mar 24, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Legacy-TacticalGamingInteractive
Copy link

I've got a script where I'm selling an animal carcass from hunting. Unfortunately its giving me an error during the money part. Please see:

[ script:ox_inventory] SCRIPT ERROR: @ox_inventory/modules/inventory/server.lua:884: bad 'for' limit (number expected, got nil)
[ script:ox_inventory] > ref (@ox_inventory/modules/inventory/server.lua:884)
[ script:ox_inventory] > handler (@nfire_hunting/server/main.lua:65)
[ script:ox_inventory] > <unknown> (@oxmysql/dist/build.js:22252)
[ script:ox_inventory] > processTicksAndRejections (node:internal/process/task_queues:96)
[script:nfire_hunting] SCRIPT ERROR: @nfire_hunting/server/main.lua:65: 
[script:nfire_hunting]  An error occurred while calling export `AddItem` in resource `ox_inventory`:
[script:nfire_hunting] 
[script:nfire_hunting]  ---
[script:nfire_hunting] > <unknown> (@oxmysql/dist/build.js:22252)
[script:nfire_hunting] > processTicksAndRejections (node:internal/process/task_queues:96)

Here is the function:

RegisterNetEvent('nfire_hunting:SellCarcass')
AddEventHandler('nfire_hunting:SellCarcass',function (item)
    local itemData = exports.ox_inventory:Search(source,'slots', item)[1]
    if itemData.count >= 1 then
        local reward = Config.sellPrice[item].max * Config.gradeMultiplier[itemData.metadata.type]
        if Config.degrade and itemData.metadata.durability ~= nil then
            local currentTime = os.time()
            local maxTime = itemData.metadata.durability
            local minTime = maxTime - itemData.metadata.degrade * 60
            if currentTime >= maxTime then
                currentTime = maxTime
            end
            reward =math.floor(map(currentTime, maxTime, minTime, Config.sellPrice[item].min * Config.gradeMultiplier[itemData.metadata.type], Config.sellPrice[item].max * Config.gradeMultiplier[itemData.metadata.type]))
        end
        exports.ox_inventory:RemoveItem(source, item, 1, nil, itemData.slot)
        exports.ox_inventory:AddItem(source, 'money', reward)  -- line 65
    end
end)

In the config

Config.sellPrice = {
    ['carcass_boar'] =      {min = 150,max = 1000}, -- min = 0 durability   max = 100 durability
    ['carcass_hawk'] =      {min = 200,max = 1200},
    ['carcass_cormorant'] = {min = 60,max = 600},
    ['carcass_coyote'] =    {min = 30,max = 300},
    ['carcass_deer'] =      {min = 50,max = 500},
    ['carcass_mtlion'] =    {min = 80,max = 800},
    ['carcass_rabbit'] =    {min = 40,max = 400}
}

Do you know what the error means? I'm at a loss. And the original script dev has archived the script so I'm kinda stuck. Script was made for ox inv 2.7.4. If it matters or not. I've tried looking at the documentation for ox inv but no luck figuring out this error. Thank you for your input.

@Legacy-TacticalGamingInteractive Legacy-TacticalGamingInteractive added the bug Something isn't working label Mar 24, 2023
@thelindat
Copy link
Member

I don't have a clue what the error is referencing because of version differences.
image

@Legacy-TacticalGamingInteractive
Copy link
Author

image

sigh. idk.

@thelindat
Copy link
Member

Not a clue, since any inv will always have slots defined.

@thelindat thelindat closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants