• 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+ Error Npc - Check task

bpm91

Advanced OT User
Joined
May 23, 2019
Messages
1,046
Solutions
7
Reaction score
180
Location
Brazil
YouTube
caruniawikibr
npc is not really my strong point, so if I say hi> task> Rotworms>Cancel, without having any task activated, I get this error. how to fix it? Does anyone have a direction?
tfs 1.5 7.72
LUA:
Lua Script Error: [Npc interface]
data/npc/scripts/Robin.lua:onCreatureSay
data/npc/scripts/Robin.lua:135: attempt to index a boolean value
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/Robin.lua:135: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:412: in function 'onCreatureSay'
        data/npc/scripts/Robin.lua:7: in function <data/npc/scripts/Robin.lua:7>

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local difficultys = {"easy", "medium", "hard", "very hard"}
local difficulty = ""
local task = ""

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if (msg:lower() == "yes" and npcHandler.topic[cid] == 3) then
        playerCancelTask(player, difficulty, task)
        npcHandler:say("Ok. Done.", cid)
        npcHandler:releaseFocus(cid)
    end
   
    if (difficulty == "" and task == "" and npcHandler.topic[cid] ~= 0) then
        if (msg:lower() == "reward" or msg:lower() == "cancel" or msg:lower() == "check") then          
            if (getPlayerActualTask(player)) then
                difficulty = getPlayerActualTask(player).diff
                task = getPlayerActualTask(player).task
            else
                npcHandler:say("First choose a task..", cid)
                return true
            end
        end
    end

    if (msg:lower() == "hi") then
        npcHandler:say("Hi, i can give you a task mission.", cid)
        npcHandler:addFocus(cid)
        npcHandler.topic[cid] = 1
        return true
    end  
   
    if (not npcHandler:isFocused(cid)) then return true end
    if (msg:lower() == "task" and npcHandler.topic[cid] == 1) then
        npcHandler:say("Ok, First, choice difficulty: easy, medium, hard and very hard.", cid)
        return true
    end
   
    if (table.contains(difficultys, msg:lower())) then
        difficulty = msg:lower()
        npcHandler:say("Take a look and talk me the name of task.", cid)
        player:showTextDialog(2597, populateBookTask(difficulty), false)
    end      

    if (difficulty ~= "" and KillTaskconfig.tasks[difficulty][msg:lower()]) then
        task = msg:lower()
        npcHandler:say(string.format("Okay, %s. So, what action do you want now? accept, reward, check, cancel.", task), cid)
    end

    if (msg:lower() == "accept" and task ~= "") then
        if (KillTaskconfig.tasks[difficulty][task]) then
            if (player:getStorageValue(KillTaskconfig.storages.haveTask) == 1) then
                npcHandler:say("You already have a task. Status: "..firstToUpper(getPlayerActualTask(player).task)..": "..string.format("%s.", checkStatus(player, getPlayerActualTask(player).diff, getPlayerActualTask(player).task)), cid)
                npcHandler:addFocus(cid)
                return true
            end

            if (getPlayerTaskStatus(player, difficulty, task) == "claimed") then
                npcHandler:say("You already have been done "..task.." task.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end

            npcHandler:say("Done. Return when you complete the task.", cid)
            playerAddTask(player, difficulty, task)
            npcHandler:releaseFocus(cid)
            return true
        end
    end

    if (msg:lower() == "reward") then
        if (KillTaskconfig.tasks[difficulty][task]) then
            if (getPlayerTaskStatus(player, difficulty, task) == "claimed") then
                npcHandler:say("You already have claimed "..task.." task reward.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end

            if (getPlayerTaskStatus(player, difficulty, task) == "done") then
                player:setStorageValue(KillTaskconfig.tasks[difficulty][task].masterStorage, -3)
                player:setStorageValue(KillTaskconfig.storages.haveTask, 0)
                npcHandler:say("Okay, take your reward.", cid)
                sendPlayterTaskReward(player, difficulty, task)
                npcHandler:releaseFocus(cid)
                return true
            else
                npcHandler:say("Return when you really complete the task.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
        end
    end

    if (msg:lower() == "check") then
        if (KillTaskconfig.tasks[difficulty][task]) then
            local val = KillTaskconfig.tasks[difficulty][task]
            if (player:getStorageValue(val.masterStorage) == 0) then
                npcHandler:say("Status: Not accepted.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end          
            if (player:getStorageValue(val.masterStorage) == -2) then
                npcHandler:say("Status: Done.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            npcHandler:say(string.format("Status: Task: %s, %s.", task, checkStatus(player, difficulty, task)), cid)
            npcHandler:releaseFocus(cid)
            return true
        end
    end

    if (msg:lower() == "cancel") then
        if (KillTaskconfig.tasks[difficulty][task]) then
            local val = KillTaskconfig.tasks[difficulty][task]
            if (getPlayerTaskStatus(player, difficulty, task) == "claimed") then
                npcHandler:say("You cant cancel an completed task.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            if (player:getStorageValue(val.masterStorage) == 0) then
                npcHandler:say("You cant cancel a non-accepted task.", cid)
                npcHandler:releaseFocus(cid)
                return true
            end
            npcHandler:say(string.format("Are you sure to cancel task %s?", getPlayerActualTask(player).task), cid)
            npcHandler.topic[cid] = 3
            return true
        end
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Back
Top