• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Open Tibia attempt to index local 'value' (a nil value) (1 Viewer)

zexus

Newcomer
Joined
Mar 8, 2021
Messages
8
Reaction score
0
Why my quests is not working?

It is showing this error on console:
error on console:
Code:
[20:0:29.635] [Error - Action Interface]
[20:0:29.635] data/actions/scripts/quests/quests.lua:onUse
[20:0:29.635] Description:
[20:0:29.635] data/actions/scripts/quests/quests.lua:4: attempt to index local 'value' (a nil value)
[20:0:29.635] stack traceback:
[20:0:29.635]     data/actions/scripts/quests/quests.lua:4: in function 'isLevelRequired'
[20:0:29.635]     data/actions/scripts/quests/quests.lua:7: in function <data/actions/scripts/quests/quests.lua:6>

the script is:

data/actions/scripts/quests/quests.lua:

Code:
dofile(getDataDir() .. "actions/scripts/quests/quests_list.lua")

function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(zexus_quest_list[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = zexus_quest_list[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')        
                end
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/mins) ..' minutes to do it again.')
            end
        end
    end
    return true
end



data/actions/scripts/quests/quests_list.lua:
Code:
mins = 60
hours = 60 * 60
days = 24 * 60 * 60

zexus_quest_list = {
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rookx", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours}
}


----------------------------------

i also test this, but its print only the q on console, its not printing zexus_quest_list
why?

Code:
dofile(getDataDir() .. "actions/scripts/quests/quests_list.lua")

function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    print("quest action:")
    print(zexus_quest_list)
    for q, quest in pairs(zexus_quest_list) do
        print(q)
    end
    -- local levelRequired, quest, level = isLevelRequired(zexus_quest_list[item.actionid])
    -- if levelRequired then
    --     if getPlayerLevel(cid) < level then
    --         doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
    --         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    --         return true
    --     end
    -- end
    if quest then
        local storage = 200000 + item.actionid
        local quest = zexus_quest_list[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')        
                end
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/mins) ..' minutes to do it again.')
            end
        end
    end
    return true
end

console:
Code:
quest action:

8003
8005
8000
8002
8004
8001

what is wrong?
 
Last edited:

zexus

Newcomer
Joined
Mar 8, 2021
Messages
8
Reaction score
0
I've fix it in other way with a good guys helping, it can be closed ;)
 
Top