Jump to content

Attempt to compare number with nil


silvatv

Recommended Posts

function AirNewSCR_EnviarServidor(thePlayer, commandName, key)
    if key then
        if existsKey(key) then
            local keyInfo = getKeyInfos(key)
            local vipType = keyInfo[1]["vipType"]
            local days = keyInfo[1]["days"]
            local expires = os.time()
            dbExec(database, "DELETE FROM keys WHERE key = ?", key)
            outputChatBox(prefix .. "VIP " .. vipType .. " ativado com sucesso.", thePlayer, 255, 255, 255, true)
            local moneyAchieved = money[vipType]
            if tonumber(days) > 0 then ----- Erro
                if isVIP(getAccountID(getPlayerAccount(thePlayer)), vipType) then
                    local vipInfo = getVIPInfos(getAccountID(getPlayerAccount(thePlayer)), vipType)
                    if not vipInfo[1]["expires"] == "Permanente" then
                        expires = tonumber(vipInfo[1]["expires"]) + (tonumber(days) * 24 * 60 * 60)
                        dbExec(database, "UPDATE vips SET expires = ? WHERE accountId = ? AND vipType = ?", expires, getAccountID(getPlayerAccount(thePlayer)), vipType)
                        outputChatBox(prefix .. "O teu VIP expira dia: " .. os.date("%c", expires), thePlayer, 255, 255, 255, true)
...

Link to comment

Sure, I'll help you fix your code. I noticed a couple of issues in your code. Here's the corrected version:

local prefix = "[Server] "
local database = -- your database connection here
local money = {
    -- your vipType to money mapping here
}

function AirNewSCR_EnviarServidor(thePlayer, commandName, key)
    if key then
        if existsKey(key) then
            local keyInfo = getKeyInfos(key)
            local vipType = keyInfo[1]["vipType"]
            local days = tonumber(keyInfo[1]["days"]) or 0 -- Initialize days to 0 if the value is not numeric
            local expires = os.time()
            dbExec(database, "DELETE FROM keys WHERE key = ?", key)
            outputChatBox(prefix .. "VIP " .. vipType .. " ativado com sucesso.", thePlayer, 255, 255, 255, true)

            local moneyAchieved = money[vipType]

            if days > 0 then
                if isVIP(getAccountID(getPlayerAccount(thePlayer)), vipType) then
                    local vipInfo = getVIPInfos(getAccountID(getPlayerAccount(thePlayer)), vipType)
                    if vipInfo[1]["expires"] ~= "Permanente" then
                        expires = tonumber(vipInfo[1]["expires"]) + (days * 24 * 60 * 60)
                    end
                else
                    local accountId = getAccountID(getPlayerAccount(thePlayer))
                    dbExec(database, "INSERT INTO vips (accountId, vipType, expires) VALUES (?, ?, ?)", accountId, vipType, expires)
                end
                outputChatBox(prefix .. "O teu VIP expira dia: " .. os.date("%c", expires), thePlayer, 255, 255, 255, true)
            end
        end
    end
end

 

Changes made:

  1. Added prefix and database variables as placeholders. Please replace them with appropriate values.
  2. Checked if days is numeric by using tonumber, and initialized it to 0 if it's not.
  3. Replaced if not vipInfo[1]["expires"] == "Permanente" then with if vipInfo[1]["expires"] ~= "Permanente" then.
  4. Added an else block for when the player is not already VIP, to insert the new VIP entry into the database.

Please make sure to replace prefix, database, and money variables with the correct values for your script. Additionally, ensure that the functions existsKey, getKeyInfos, isVIP, and getVIPInfos are defined correctly in your script.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...