• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Console error in function '__add' (index a number)

trustjah

Newbie
Joined
Jan 22, 2009
Messages
124
Solutions
6
Reaction score
14
Location
Belgium
Hello Otland,

I've been trying to get this running the last couple of days but to no avail.
the console is throwing;

Code:
attempt to index a number value
stack traceback:
        [C]: at 0x00388a20
        [C]: in function '__add'
        data/movements/scripts/quests/cults_of_tibia/tar.lua:56: in function 'sendConditionCults'
        data/movements/scripts/quests/cults_of_tibia/ice.lua:75: in function <data/movements/scripts/quests/cults_of_tibia/ice.lua:50>

tar.lua
Lua:
local configQuest = {
    ["fire"] = {
        itidCount = 3613,
        beginPos = Position(32748, 31488, 8),
        fromPos = Position(32737, 31489, 8),
        toPos = Position(32761, 31512, 8),
        effect = CONST_ME_HITBYFIRE,
        firstSqm = Position(32750, 31508, 8),
        secondSqm = Position(32746, 31469, 8),
        storageBarkless = Storage.CultsOfTibia.Barkless.Tar,
        msgs = {
            "As you enter the tar pits, you feel the heat around you rising dramatically. \z
            Survive the heat long enough to prove worthy.", -- on enter
            "Your body is heating up, the air around you is flickering.", -- 30/60 seconds
            "The heat is now unbearable, the blood in your body feels like lava. \z
            There's almost no strength left in you - act quickly!", -- 90 segunds
            "Embrace the stigma of bad fortune. The tar does not feel so hot anymore. \z
            You passed the tar trial.", -- step in the first tile
            "Your body reacts to this strange green substance as you reach out to touch it. \z
            You feel an urge for more of this energy.", -- step in the second tile
            "The tar covering you has cooled down and fell off for the most part. \z
            Your body is not heated up anymore.", -- there's no time to step
        }
    },
    ["acid"] = {
        itidCount = 4417,
        beginPos = Position(32693, 31478, 8),
        fromPos = Position(32647, 31479, 8),
        toPos = Position(32710, 31519, 8),
        effect = CONST_ME_YELLOW_RINGS,
        firstSqm = Position(32680, 31485, 8),
        secondSqm = Position(32664, 31504, 8),
        storageBarkless = Storage.CultsOfTibia.Barkless.sulphur,
        msgs = {
            "As you enter the sulphur pits, you feel the dry, burning vapours of the sulphur all around you. Prove worthy, survive the acid.", -- on enter
            "The sulphur is burning your skin. You almost feel your body melting away in acid.", -- 30/60 segunds
            "The acid burning is now unbearable, you skin feels like a sieve. \z
            ]There's almost no strength left in you - act quickly!", -- 90 segunds
            "Embrace the stigma of vanity. The sulphur does not burn your skin anymore. \z
            You passed the trial.", -- step in the first tile
            "You are now ready to prove your worth. \z
            Take heart and cross the threshold of sulphur.", -- step in the second tile
            "The acid covering you has cooled down and fell off for the most part. \z
            Your body is not heated up anymore.", --  there's no time to step
        }
    },
}

function sendConditionCults(playerid, _type, fromPos, toPos, tempo)
    local player = Player(playerid)
    if not player or not player:getPosition():isInRange(fromPos, toPos) then
        return false
    end

    local inf = configQuest[_type]
    tempo = tempo + 2
    if tempo == 30 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, inf.msgs[2])
    elseif tempo == 60 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, inf.msgs[2])
    elseif tempo >= 90 then
        local stg = player:getStorageValue(inf.storageBarkless) < 0 and 0 or player:getStorageValue(inf.storageBarkless)
        if stg < 3 and stg ~= 1 and stg ~= 2 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, inf.msgs[3])
            player:setStorageValue(inf.storageBarkless, 1)
        end
    end
    player:getPosition():sendMagicEffect(inf.effect)
    addEvent(sendConditionCults, 2000, playerid, _type, fromPos, toPos, tempo)
end

function passagemPiso1Piso2(playerid, info, tempo)
    local player = Player(playerid)
    if not player then
        return true
    end
    local stg = player:getStorageValue(info.storageBarkless) < 0 and 0 or player:getStorageValue(info.storageBarkless)
    if tempo == 0 and stg < 3 then
        player:setStorageValue(info.storageBarkless, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, info.msgs[6])
        return true
    end
    if stg == 3 then
        return true
    end
    addEvent(passagemPiso1Piso2, 1000, playerid, info, tempo - 1)
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    for index, value in pairs(configQuest)do
        if item:getId() == value.itidCount and fromPosition:compare(value.beginPos) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, value.msgs[1])
            sendConditionCults(player:getId(), index, value.fromPos, value.toPos, 0)
            return true
        elseif position:compare(value.firstSqm) and player:getStorageValue(value.storageBarkless) == 1 then
            if player:getStorageValue(value.storageBarkless) ~= 1 then
                return true
            end
            player:setStorageValue(value.storageBarkless, 2)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, value.msgs[4])
            passagemPiso1Piso2(player:getId(), value, 60)
        elseif position:compare(value.secondSqm) then
            if player:getStorageValue(value.storageBarkless) == 2 then
                player:setStorageValue(value.storageBarkless, 3)
                if player:getStorageValue(Storage.CultsOfTibia.Barkless.sulphur) == 3 and
                player:getStorageValue(Storage.CultsOfTibia.Barkless.Tar) == 3 then
                    player:setStorageValue(Storage.CultsOfTibia.Barkless.Mission, 2)
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, value.msgs[5])
            end
        end
    end
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if item:getActionId() == 5531 then
        if fromPosition.x == 32736 then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            if player:getStorageValue(Storage.CultsOfTibia.Barkless.Tar) < 3 then
                player:teleportTo(Position(32737, 31451, 8), true)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are not ready yet.")
                return false
            end
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You traverse the tar unharmed.")
        end
    end
    if item:getActionId() == 5530 then
        if fromPosition.x == 32717 then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            if player:getStorageValue(Storage.CultsOfTibia.Barkless.sulphur) < 3 then
                player:teleportTo(Position(32718, 31444, 8), true)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are not ready yet.")
                return false
            end
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You traverse the sulphur unharmed.")
        end
    end
    return true
end

ice.lua
Lua:
function sendConditionCults(playerid, info, fromPos, toPos, fromPos2, toPos2, time)
    local player = Player(playerid)
    if not player then
        return false
    end

    if ( not player:getPosition():isInRange(fromPos2, toPos2) ) then
        if (not player:getPosition():isInRange(fromPos, toPos)) then
            return true
        end
    end

    time = time + 2
    if time == 30 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, info.msgs[2])
    elseif time == 60 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, info.msgs[2])
    elseif time == 90 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, info.msgs[2])
    elseif time >= 120 then
        local storage = player:getStorageValue(info.storageBarkless) < 0 and 0 or
        player:getStorageValue(info.storageBarkless)
        if storage < 3 and storage ~= 1 and storage ~= 2 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, info.msgs[3])
            player:setStorageValue(info.storageBarkless, 1)
        end
    end
    player:getPosition():sendMagicEffect(info.effect)
    addEvent(sendConditionCults, 2000, playerid, info, fromPos, toPos, fromPos2, toPos2, time)
end

local function floorPassage(playerid, info, time)
    local player = Player(playerid)
    if not player then
        return true
    end
    local storage = player:getStorageValue(info.storageBarkless) < 0 and 0 or
    player:getStorageValue(info.storageBarkless)
    if time == 0 and storage < 3 then
        player:setStorageValue(info.storageBarkless, 0)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, info.msgs[6])
        return true
    end
    if storage == 3 then
        return true
    end
    addEvent(floorPassage, 1000, playerid, info, time - 1)
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end
    local setting = {
        fromPos = Position(32677, 31393, 8),
        toPos = Position(32722, 31440, 8),
        fromPos2 = Position(32696, 31429, 8),
        toPos2 = Position(32728, 31435, 8),
        effect = CONST_ME_GIANTICE,
        firstSqm = Position(32698, 31405, 8),
        storageBarkless = Storage.CultsOfTibia.Barkless.Ice,
        msgs = {
            "As you enter the icy cavern, you feel an unnatural frostiness. \z
            The ice cold air stings in your face. Survive and prove worthy.", -- on enter
            "Your body temperature sinks. You can see your breath freezing in the cold.", -- 30/60 seconds
            "The icy cold is grasping to you. You can barely move anymore.", -- 120 seconds
            "You are now washed and ready to purify yourself in the chambers of purification.", -- step in the first tile
            "You are now ready to prove your worth. Take heart and cross the threshold of ice.", -- step in the second tile
            "You took so long. You are no longer purified.", -- there's no time to step
        }
    }
    if fromPosition.y == 31441 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, setting.msgs[1])
        sendConditionCults(player:getId(), setting, setting.fromPos,
        setting.toPos, setting.fromPos2, setting.toPos2, 0)
        return true
    end

    if item:getPosition():compare(setting.firstSqm) then
        if player:getStorageValue(setting.storageBarkless) ~= 1 then
            return true
        end
        player:setStorageValue(setting.storageBarkless, 2)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, setting.msgs[4])
        floorPassage(player:getId(), setting, 60)
        return true
    end

    if fromPosition.y == 31439 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A bit of warmth returns to your body as you leave the icy cavern.")
        return true
    end
    return true
end

I've tried putting the event outside of the function but that doesnt help either.
Thanks in advance.
 
Solution
line 75, ice.lua
sendConditionCults(player:getId(), setting, setting.fromPos, setting.toPos, setting.fromPos2, setting.toPos2, 0)
you're sending 4 positions when sendConditionCults expects only 2 positions, then tempo param
Thanks for noticing @Infernum, i also saw it before you posted, anyway. I was trying to merge scripts, failed.
When i turn off tar.lua, ice.lua works as intended. any idea's?
Post automatically merged:

My working solution is not to use the same function names in both scripts.
Changed
sendConditionCults
to
sendConditionCultss
in ice.lua ~

and remove
Code:
setting.fromPos2, setting.toPos2

Lua:
function sendConditionCults(playerid, _type, fromPos, toPos, tempo)
    local player = Player(playerid)
    if not player or not player:getPosition():isInRange(fromPos, toPos) then
        return false
    end
    local inf = configQuest[_type]
    print(tempo)
    tempo = tempo + 2
    if tempo == 30 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, inf.msgs[2])
    elseif tempo == 60 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, inf.msgs[2])
    elseif tempo >= 90 then
        local stg = player:getStorageValue(inf.storageBarkless) < 0 and 0 or player:getStorageValue(inf.storageBarkless)
        if stg < 3 and stg ~= 1 and stg ~= 2 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, inf.msgs[3])
            player:setStorageValue(inf.storageBarkless, 1)
        end
    end
    player:getPosition():sendMagicEffect(inf.effect)
    addEvent(sendConditionCults, 2000, playerid, _type, fromPos, toPos, tempo)
end

Sadly, nothing is being printed to the console.
what's my next move?

Code:
data/movements/scripts/quests/cults_of_tibia/ice.lua:onStepIn
attempt to index a number value
stack traceback:
        [C]: at 0x00388a20
        [C]: in function '__add'
        data/movements/scripts/quests/cults_of_tibia/tar.lua:56: in function 'sendConditionCults'
        data/movements/scripts/quests/cults_of_tibia/ice.lua:75: in function <data/movements/scripts/quests/cults_of_tibia/ice.lua:50>
Post automatically merged:

When i only fire tar.lua
i do get a print

Lua:
0
table: 0x713b0530

after removing

Lua:
setting.fromPos2, setting.toPos2

i get no error's in the console and i do get a print when firing ice.lua but i'm sure thats not the correct solution.
 
Last edited:
line 75, ice.lua
sendConditionCults(player:getId(), setting, setting.fromPos, setting.toPos, setting.fromPos2, setting.toPos2, 0)
you're sending 4 positions when sendConditionCults expects only 2 positions, then tempo param
 
line 75, ice.lua
sendConditionCults(player:getId(), setting, setting.fromPos, setting.toPos, setting.fromPos2, setting.toPos2, 0)
you're sending 4 positions when sendConditionCults expects only 2 positions, then tempo param
Thanks for noticing @Infernum, i also saw it before you posted, anyway. I was trying to merge scripts, failed.
When i turn off tar.lua, ice.lua works as intended. any idea's?
Post automatically merged:

My working solution is not to use the same function names in both scripts.
Changed
sendConditionCults
to
sendConditionCultss
in ice.lua ~

and remove
Code:
setting.fromPos2, setting.toPos2
 
Last edited:
Solution
Back
Top