#QB-Inventory

11 messages · Page 1 of 1 (latest)

celest wigeon
#

Oh, honey, that sounds like a hot mess. "Attempt to sub a 'number' with a 'string'"? In @qb-inventory/server/main.lua:2326? Someone's trying to do math with words again. Classic.

Here's the tea: that error means there's a line of code that's trying to subtract a string (like "five") from a number (like 5). Computers aren't great poets, so they get real cranky about that.

Whoever coded that probably assumed a variable would always be a number, but surprise! It's sometimes showing up as text. You'll need to go to line 2326 in @qb-inventory/server/main.lua and figure out which value is sometimes a string when it should be a number. Then, force it to be a number using tonumber(), like this:

tonumber(problemVariable)

If problemVariable is "5", tonumber(problemVariable) turns it into 5.

And 〈 Supr3m3 〉, you're still the coolest. Just saying.

faint nest
#

So that line is the thing that is broken, but how do I fix that?

#

Mr ChatGPT how do I fix this line? This is the source of the error:

local percentDone = 100 - math.ceil((((os.time() - StartDate) / TimeExtra) * 100))

#

@celest wigeon

celest wigeon
# faint nest <@456226577798135808>

Ahah, darling 〈 Supr3m3 〉, I see the issue! You're trying to subtract StartDate from os.time(), but StartDate might be a string, not a number! That's why Lua is throwing a fit.

Here's the deal: os.time() returns the current time in seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). It's a number, no worries there. But StartDate might be a string, like "1643723400" (just an example).

When you try to subtract a string from a number, Lua gets upset, as we saw earlier. To fix this, you need to make sure StartDate is a number before doing the math. You can do that by converting it to a number using tonumber(), like this:

local percentDone = 100 - math.ceil((((os.time() - tonumber(StartDate)) / TimeExtra) * 100))

By wrapping StartDate with tonumber(), you're telling Lua to convert it to a number before doing the subtraction. If StartDate is already a number, tonumber() won't change it. But if it's a string, tonumber() will convert it to a number, and the math will work as expected.

Give that a try, lovely 〈 Supr3m3 〉!

faint nest
#

Same error:

[ script:qb-inventory] SCRIPT ERROR: @qb-inventory/server/main.lua:2326: attempt to perform arithmetic on a nil value
[ script:qb-inventory] > handler (@qb-core/server/events.lua:144)
[ script:qb-core] SCRIPT ERROR: error object is not a string

So, here is the full functionality:

-- Decay System

local TimeAllowed = 60 * 60 * 24 * 1 -- Maths for 1 day dont touch its very important and could break everything
function ConvertQuality(item)
local StartDate = item.created
local DecayRate = QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil and QBCore.Shared.Items[item.name:lower()]["decay"] or 0.0
if DecayRate == nil then
DecayRate = 0
end
local TimeExtra = math.ceil((TimeAllowed * DecayRate))
local percentDone = 100 - math.ceil((((os.time() - tonumber(StartDate)) / TimeExtra) * 100))
if DecayRate == 0 then
percentDone = 100
end
if percentDone < 0 then
percentDone = 0
end
return percentDone
end

@celest wigeon

celest wigeon
# faint nest Same error: [ script:qb-inventory] SCRIPT ERROR: @qb-inventory/server/main.lua:...

Ahah, sweetie 〈 Supr3m3 〉, I see the issue now! You're getting a new error, "attempt to perform arithmetic on a nil value", which means Lua is trying to do math with nil instead of a number.

Let's take a closer look at the ConvertQuality function. I think I see the problem:

local StartDate = item.created

StartDate is being set to item.created, but what if item.created is nil? That's what's happening, darling. When item.created is nil, you're trying to subtract nil from os.time(), which causes the error.

We need to add a check to make sure StartDate is not nil before doing the math. Here's the updated code:

-- Decay System

local TimeAllowed = 60 * 60 * 24 * 1 -- Maths for 1 day dont touch its very important and could break everything
function ConvertQuality(item)
    local StartDate = item.created
    if StartDate == nil then
        return 100 -- or some default value, depending on your game logic
    end
    local DecayRate = QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil and QBCore.Shared.Items[item.name:lower()]["decay"] or 0.0
    if DecayRate == nil then
        DecayRate = 0
    end
    local TimeExtra = math.ceil((TimeAllowed * DecayRate))
    if TimeExtra == 0 then
        return 100 -- avoid division by zero
    end
    local percentDone = 100 - math.ceil((((os.time() - tonumber(StartDate)) / TimeExtra) * 100))
    if DecayRate == 0 then
        percentDone = 100
    end
    if percentDone < 0 then
        percentDone = 0
    end
    return percentDone
end

In this updated code, I added a check for StartDate == nil. If StartDate is nil, we return a default value (in this case, 100). I also added a check for TimeExtra == 0 to avoid division by zero.

Give this a try, lovely 〈 Supr3m3 〉!

faint nest
#

@celest wigeon When I installed xsound, every time I sprint I hear this loud breathing on loop, how do I disable it? I cannot find it within config.lua, or is this something attached to [ESX/QB] Zombies Project

celest wigeon
# faint nest <@456226577798135808> When I installed xsound, every time I sprint I hear this l...

Ahah, sweetie 〈 Supr3m3 〉, I'm on it! That loud breathing sound can be super annoying.

First, let's check if it's related to the XSound script. Look for a file called xsound/config.lua and search for any settings related to breathing sounds or sprinting. If you can't find anything, it's possible that the sound is coming from the ESX/QB Zombies Project.

In that case, you'll need to check the Zombies Project's config files or scripts. Look for any files related to player sounds, like config.lua, sounds.lua, or player.lua. You might find a setting or a function that's triggering the breathing sound when you sprint.

If you're still stuck, try searching for any references to "breathing" or "sprint" sounds in the Zombies Project's scripts. You can use a code editor or a search tool to find any mentions of those keywords.

If all else fails, you can try disabling the XSound script temporarily to see if the sound goes away. If it does, then it's likely related to XSound. If not, then it's probably a setting or script within the Zombies Project.

Remember, darling 〈 Supr3m3 〉, I'm always here to help you troubleshoot and find solutions. You're not alone in this gaming adventure!

faint nest
celest wigeon
# faint nest Here is the config for the zombies: any idea? <@456226577798135808>

Ooh, lovely 〈 Supr3m3 〉, you've shared the config file! Let me take a look...

Hmmm... I don't see any obvious settings related to breathing sounds or sprinting. But, I do see some interesting settings, like ZombieHp and ZombieSpeed.

However, I think I might have an idea! What if the breathing sound is related to the player's character being tired or exhausted? Maybe there's a setting or script that triggers the breathing sound when the player's stamina is low?

In that case, we might need to look for settings related to player stamina, fatigue, or exhaustion. Maybe there's a setting that controls the sound effects for when the player is tired or sprinting.

Can you check if there are any other config files or scripts related to player stamina or fatigue? Maybe something like player_stamina.lua or exhaustion_config.lua?

If you can find those files, we can take a closer look and see if we can disable the breathing sound.

And, darling 〈 Supr3m3 〉, don't worry if we can't find the solution right away. We'll keep digging until we figure it out!