• 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!

Task error

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
136
Location
Sweden
Hello.

Im using this script, and get this error, can someone help me fix it?


Lua:
local STORAGE = 18008

local TALKSTATE_PICK = 1
local TALKSTATE_RESET = 2
local TALKSTATE_COMPLETE = 3

local TASKSTATE_COMPLETED = 1
local TASKSTATE_BOSS = 2
local TASKSTATE_FINALIZED = 3

local tasks = {
    ['dragons'] = {storage = 18009, kills = 50, experience = 0, once = false, items = {{2160, 10}}},
    ['giant spiders'] = {storage = 18010, kills = 10, experience = 10000, once = true, items = {}},
    ['dragon lords'] = {storage = 18011, kills = 10, experience = 0, once = true, items = {}},
    ['hydras'] = {storage = 18012, kills = 50, experience = 0, once = false, items = {{2160, 25}}},
    ['grim reapers'] = {storage = 18013, kills = 100, experience = 2000000, once = true, items = {{2160, 30}}},
    ['demons'] = {storage = 18014, kills = 100, experience = 0, once = false, items = {{2160, 40}}},   
    ['undead dragons'] = {storage = 18015, kills = 10, experience = 0, once = true, items = {}}
}

function listTasks()
    local output, list = '', {}

    for k, v in ipairs(tasks) do
        table.insert(list, k)
    end

    for k, v in ipairs(list) do
        if k == 1 then
            output = '{'.. v .. '}'
        elseif k == #list then
            output = output .. ' and {'.. v ..'}'
        else
            output = output ..', {'.. v ..'}'
        end
    end

    return output
end

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, turned = {}

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)

    if talkState[cid] then
        talkState[cid] = nil
    end
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg)
end

function onThink()
    if not turned then
        selfTurn(SOUTH)
        turned = true
    end

    npcHandler:onThink()
end

local shop = ShopModule:new()
npcHandler:addModule(shop)

shop:addBuyableItem({'demon backpack'}, 10518, 1000, 1, 'Demon Backpack')

shop:addSellableItem({'hydra head'}, 11199, 600, 'Hydra Head')
shop:addSellableItem({'cyclops trophy'}, 7398, 500, 'Cyclops Trophy')
shop:addSellableItem({'minotaur trophy'}, 7401, 500, 'Minotaur Trophy')
shop:addSellableItem({'deer trophy'}, 7397, 1000, 'Deer Trophy')
shop:addSellableItem({'lion trophy'}, 7400, 1000, 'Lion Trophy')
shop:addSellableItem({'wolf trophy'}, 7394, 1000, 'Wolf Trophy')
shop:addSellableItem({'behemoth trophy'}, 7396, 20000, 'Behemoth Trophy')
shop:addSellableItem({'demon trophy'}, 7393, 40000, 'Demon Trophy')
shop:addSellableItem({'dragon lord trophy'}, 7399, 10000, 'Dragon Lord Trophy')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, 'task') then
        if getCreatureStorage(cid, STORAGE) == EMPTY_STORAGE then
            local list = listTasks()
            selfSay('You can start one of the following tasks: {Dragons}, {Giant Spiders}, {Dragon Lords}, {Hydras}, {Grim Reapers}, {Demons} and {Undead Dragons}.', cid)
            selfSay('You can also make these: {Juggernauts}, {Hands}, {Dark Torturers} and {Phantasms}. But you can make them only once.', cid)
            selfSay('To start a task, simply type one of highlighted keywords, and remember - you can\'t start more than one task at same time.', cid)
            talkState[cid] = TALKSTATE_PICK
        else
            selfSay('You are currently assigned a task. Would you like to dismiss your current task and begin another one?', cid)
            talkState[cid] = TALKSTATE_RESET
        end
    elseif talkState[cid] == TALKSTATE_RESET then
        if msgcontains(msg, 'yes') then
            doCreatureSetStorage(cid, STORAGE, EMPTY_STORAGE)

            for _, v in ipairs(tasks) do
                doCreatureSetStorage(cid, v.storage, EMPTY_STORAGE)
            end

            selfSay('Your current task has been restarted, now you can choose another one, please say {task} to see list of available tasks.', cid)
        else
            selfSay('No then...', cid)
        end

        talkState[cid] = nil
    elseif talkState[cid] == TALKSTATE_PICK then
        local task = tasks[msg:lower()]

        if task then
            if getCreatureStorage(cid, task.storage) == task.kills + TASKSTATE_FINALIZED then
                selfSay('This task has been already finalized and you can\'t pick it anymore.', cid)
            else
                doCreatureSetStorage(cid, STORAGE, 1)
                doCreatureSetStorage(cid, task.storage, 0)
                selfSay('You just started the {'.. msg:lower():gsub('%a', string.upper, 1) ..'} task. You have to kill '.. task.kills ..' of '.. msg:lower() ..'. Come back and ask about {complete} when you are done.', cid)
            end
        else
            selfSay('It does seem like you don\'t understand me, I told you to pick task from list.', cid)
        end

        talkState[cid] = nil
    elseif msgcontains(msg, 'complete') then
        if getCreatureStorage(cid, STORAGE) == EMPTY_STORAGE then
            selfSay('You aren\'t doing any task at the moment, if you would like to start one - type {task}.', cid)
        else
            selfSay(' I forgot, which task did you just complete?', cid)
            talkState[cid] = TALKSTATE_COMPLETE
        end
    elseif talkState[cid] == TALKSTATE_COMPLETE then
        local task = tasks[msg:lower()]

        if task then
            local kills = getCreatureStorage(cid, task.storage)

            if kills <= task.kills then
                selfSay('You have to kill '.. task.kills ..' '.. msg:lower() ..' in order to complete the {'.. msg:lower() ..'} task, you have killed '.. kills ..' '.. msg:lower():gsub('%a', string.upper, 1) ..'.', cid)
            elseif kills == task.kills + TASKSTATE_COMPLETED then
                local msg = 'Congratulations! You have completed the {'.. msg:lower():gsub('%a', string.upper, 1) ..'} task. You receive {access to magic forcefield}'

                if task.experience > 0 then
                    doPlayerAddExperience(cid, task.experience)
                    msg = msg .. ' and {'.. task.experience ..' experience points}'
                end

                if #task.items > 0 then
                    msg = msg ..' and following items'

                    for k, v in ipairs(task.items) do
                        doPlayerAddItem(cid, v[1], v[2])
                        if k == 1 then
                            msg = msg ..' {'.. getItemInfo(v[1]).name ..'}'
                        else
                            msg = msg ..', {'.. getItemInfo(v[1]).name ..'}'
                        end
                    end
                end

                msg = msg ..' as a reward!'

                doCreatureSetStorage(cid, task.storage, task.kills + TASKSTATE_BOSS)
                doSendMagicEffect(getThingPosition(cid), CONST_ME_GIFT_WRAPS)
                selfSay(msg, cid)

                talkState[cid] = nil

                if not __achv.check(cid, 8) then
                    __achv.set(cid, 8, 1)
                end
            elseif kills == task.kills + TASKSTATE_BOSS then
                selfSay('You have already reported in about that task and received access to magic forcefield, go and kill boss.', cid)
            elseif kills == task.kills + TASKSTATE_FINALIZED then
                selfSay('This task has been already finalized and you can\'t pick it anymore.', cid)
            end
        else
            selfSay('There\'s no task named {'.. msg:lower() ..'}, please remind yourself what task you have started before or type {task} to see list of available tasks.', cid)
        end

        talkState[cid] = nil
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, 'Hello, |PLAYERNAME|! I need someone to fufill a special {task} for me. If you have completed a task, please say {complete}, then the name of the task.')
npcHandler:addModule(FocusModule:new())

Lua:
[9:54:12.369] [Error - NpcScript Interface]
[9:54:12.372] data/npc/scripts/task.lua:onCreatureSay
[9:54:12.374] Description:
[9:54:12.375] data/npc/scripts/task.lua:176: attempt to index global '__achv' (a nil value)
[9:54:12.378] stack traceback:
[9:54:12.380]   data/npc/scripts/task.lua:176: in function 'callback'
[9:54:12.382]   data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[9:54:12.385]   data/npc/scripts/task.lua:59: in function <data/npc/scripts/task.lua:58>
 
data/npc/scripts/task.lua:176: attempt to index global '__achv' (a nil value)

You are missing the __achv functions, either remove them from the script or add them.
 
data/npc/scripts/task.lua:176: attempt to index global '__achv' (a nil value)

You are missing the __achv functions, either remove them from the script or add them.

Hmm alright, now i removed the function.
Shouldnt this work along with that "task" script?
If i get the correct storage.
It just tells me "You don't have any required quests completed to access this portal." even tho i finished dragon lords/giant spiders

Lua:
local config = {
   [1] = {x_storage = 11111, x_storage_value = 1, teleport_pos = {x = 995, y = 1000, z = 6}, boss_name = "the old widow", boss_position = {x = 908, y = 902, z = 7}, boss_chamber_top_left_pos = {x = 898, y = 898, z = 7}, boss_chamber_bottom_right_pos = {x = 910, y = 906, z = 7}},
   [2] = {x_storage = 11111, x_storage_value = 1, teleport_pos = {x = 995, y = 1000, z = 6}, boss_name = "demodras", boss_position = {x = 908, y = 902, z = 7}, boss_chamber_top_left_pos = {x = 898, y = 898, z = 7}, boss_chamber_bottom_right_pos = {x = 910, y = 906, z = 7}},
   [3] = {x_storage = 11111, x_storage_value = 1, teleport_pos = {x = 995, y = 1000, z = 6}, boss_name = "dracola", boss_position = {x = 908, y = 902, z = 7}, boss_chamber_top_left_pos = {x = 898, y = 898, z = 7}, boss_chamber_bottom_right_pos = {x = 910, y = 906, z = 7}}
}

local condition = createConditionObject(CONDITION_INFIGHT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 5000)

function onStepIn(cid, item, position, fromPosition)

   if not isPlayer(cid) then
     return true
   end

   for i = 1, #config do
     if getPlayerStorageValue(cid, config[i].x_storage) == config[i].x_storage_value then
       local count = 0
       local monster = 0
       for t = config[i].boss_chamber_top_left_pos.x, config[i].boss_chamber_bottom_right_pos.x do
         for f = config[i].boss_chamber_top_left_pos.y, config[i].boss_chamber_bottom_right_pos.y do
           for n = config[i].boss_chamber_top_left_pos.z, config[i].boss_chamber_bottom_right_pos.z do
             pos = {x = t, y = f, z = n}
             pid = getTopCreature(pos).uid
             if isPlayer(pid) then
               count = count + 1
             end
             if isMonster(pid) then
               monster = pid
             end
           end
         end
       end
       if count ~= 0 then
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Someone is currently in " .. config[i].boss_name .. "'s chamber. Please wait awhile.")
         doTeleportThing(cid, fromPosition)
         doSendMagicEffect(fromPosition, 10)
         return true
       end
       if monster ~= 0 then
         doRemoveCreature(monster)
       end
       doSendMagicEffect(position, 10)
       doTeleportThing(cid, config[i].teleport_pos)
       doAddCondition(cid, condition)
       local delay = 1000
       for n = 1, 3 do    
         addEvent(doSendMagicEffect, delay, config[i].boss_position, 10)
         delay = delay + 1000
       end
       addEvent(doCreateMonster, 4000, config[i].boss_name:lower(), config[i].boss_position)
       return true
     end
   end
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have any required quests completed to access this portal.")
   doTeleportThing(cid, fromPosition)
   doSendMagicEffect(fromPosition, 10)
   return true
end
 
Back
Top