• 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+ Npc glitches

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,312
Reaction score
135
Hey i got this npc , that is working ok, but sometimes it starts ignoring random player doesnt reply to none text....

Sometime , you got items but he says you doesnt etc..... Maybe someone can see here any error ? please help me out

10.98 tfs 1.4+

the npc"


Lua:
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 voices = {
    {text = 'Hello there, adventurer! Looking for some quests ? I\'m your man!'}
}
npcHandler:addModule(VoiceModule:new(voices))

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

    local min = 0
    local max = 6

    local a
    local function getStorage()
        for i = min, max do
            a = NPCTasks[i]
            if player:getStorageValue(a.Storage) ~= 2 then
                b = a
                local value = a
                return value
            end
        end
    end

    local function getPositiveStorage()
        for i = min, max do
            a = NPCTasks[i]
            if player:getStorageValue(a.Storage) == 2 then
                b = a
                local value = a
                return value
            end
        end
    end

    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'tasks') or msgcontains(msg, 'missions') or
            msgcontains(msg, 'help') then
            npcHandler.topic[cid] = 1
            local value = getStorage()
            local b = value
            if not value then
                npcHandler:say("You already made all my tasks", cid)
                return false
            end
            if player:getVocation():getId() == 0 then
                npcHandler:say("You need a vocation to take my tasks", cid)
                npcHandler:releaseFocus(cid)
                npcHandler:resetNpc(cid)
                return false
            end
            if player:getStorageValue(b.Storage) ~= 2 and npcHandler.topic[cid] ==
                1 then -- ! Doesnt has tasks
                if b.itemsToBring then
                    local c = b.itemsToBring
                    local toSay
                    local amount = #b.itemsToBring
                    local itemList = ""

                    for i = 1, amount, 2 do
                        itemList = itemList .. c[i + 1] .. " " ..
                                       getItemName(c[i]) .. ", "
                    end
                    itemList = string.sub(itemList, 1, -3)
                    toSay = "Can you bring me these items: " .. itemList ..
                                " {yes} or {no} ?"

                    if player:getStorageValue(b.Storage) == 1 then
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay ..
                                " If you already have the items, you should {report} the quest.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler:say(toSay, cid)
                    npcHandler.topic[cid] = 2
                end
                if b.creature then
                    local toSay
                    local c = b.creature
                    local d = b.Quantity
                    local v = #c
                    if v > 0 then
                        toSay = "Can you kill ? " .. d .. " " ..
                                    table.concat(c, ", ") .. "."
                    else
                        toSay = "Can you kill ? 0 creatures."
                    end
                    if player:getStorageValue(b.Storage) == 1 then -- ! Incomplete Quest
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay, cid)
                        return false
                    end
                    if player:getStorageValue(b.Storage) == 3 then
                        npcHandler:say(
                            "Seems that you already finished your mission, you should {report} it.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler.topic[cid] = 2
                    npcHandler:say(toSay, cid)
                    return false
                end
                if b.boss then
                    if player:getStorageValue(b.Storage) == 1 then -- ! Incomplete Quest
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay, cid)
                        return false
                    end
                    if player:getStorageValue(b.Storage) == 3 then
                        npcHandler:say(
                            "Seems that you already finished your mission, you should {report} it.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler:say("You need to kil the " .. b.boss[1] ..
                                       " you accept it? {yes} or {no}", cid)
                    npcHandler.topic[cid] = 2
                    return false
                end
            end
        elseif msgcontains(msg, "report") then
            local value = getStorage()
            local b = value
            if not value then
                npcHandler:say("You already made all my tasks", cid)
                return false
            end
            if player:getStorageValue(b.Storage) == 1 or
                player:getStorageValue(b.Storage) == 3 then
                if b.itemsToBring then
                    local c = b.itemsToBring
                    local amount = 0
                    for _ in pairs(b.itemsToBring) do
                        amount = amount + 1
                    end
                    local has_all_items = true
                    for i = 1, amount, 2 do
                        if player:getItemCount(c[i]) < c[i + 1] then
                            has_all_items = false
                            break
                        end
                    end
                    if has_all_items then
                        for i = 1, amount, 2 do
                            player:removeItem(c[i], c[i + 1])
                        end
                        local rewards = b.reward
                        player:addNpcReward(rewards)
                        player:setStorageValue(b.Storage, 2)
                        npcHandler:say(b.lastMessage, cid)
                        npcHandler.topic[cid] = 0
                        return false
                    else
                        npcHandler:say("You don't have all the items.", cid)
                    end
                end

                if b.creature then
                    local rewards = b.reward
                    if player:getStorageValue(b.Storage) == 3 then
                        player:addNpcReward(rewards)
                        npcHandler:say(b.lastMessage, cid)
                        player:setStorageValue(b.Storage, 2)
                    else
                        npcHandler:say("You cannot fool me, go away!.", cid)
                    end
                end
                if b.boss then
                    local rewards = b.reward
                    if player:getStorageValue(b.Storage) == 3 then
                        player:addNpcReward(rewards)
                        npcHandler:say(b.lastMessage, cid)
                        player:setStorageValue(b.Storage, 2)
                    else
                        npcHandler:say("You cannot fool me, go away!.", cid)
                    end
                end
            else
                npcHandler:say("You don't have any task to report.", cid)
            end
        end
    end

    if msgcontains(msg, "yes") then
        if npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) == 2 or
            npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            3 then
            if b.itemsToBring then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
            if b.creature then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
            if b.boss then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
        elseif npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            2 then
            player:setStorageValue(b.Storage, 1)
            npcHandler:say(b.TakeTaskMessage, cid)
            npcHandler.topic[cid] = 0
        end
        if npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            -1 then
            player:setStorageValue(b.Storage, 1)
            npcHandler.topic[cid] = 0
            npcHandler:say(b.TakeTaskMessage, cid)
            if b.creature or b.boss then
                player:setStorageValue(b.Storage * 2, 0)
            end
        end
    end
end

keywordHandler:addKeyword({'quests'}, StdModule.say, {
    npcHandler = npcHandler,
    text = "I can give you some good rewards in trade of some tasks."
})

npcHandler:setMessage(MESSAGE_GREET,
                      "Hey |PLAYERNAME|, can you help me in some {tasks} ?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
oke so first time i noticed an errror about npc


error :

Lua:
Lua Script Error: [Npc interface]
data/npc/scripts/task9.lua:onCreatureSay
data/npc/scripts/task9.lua:121: attempt to concatenate global 'toSay' (a nil value)
stack traceback:
        [C]: in function '__concat'
        data/npc/scripts/task9.lua:121: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
        data/npc/scripts/task9.lua:9: in function <data/npc/scripts/task9.lua:9>



can someone help me out please ? :)
 
When you declare a local variable in lua, it have the scope limited to the block where they are declared. In your case, you are declaring the local variable two times in different if blocks.
You should declare it at the beginning of the function instead:

Lua:
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 voices = {
    {text = 'Hello there, adventurer! Looking for some quests ? I\'m your man!'}
}
npcHandler:addModule(VoiceModule:new(voices))

local function creatureSayCallback(cid, type, msg)

    local toSay

    if not npcHandler:isFocused(cid) then return false end
    local player = Player(cid)

    local min = 0
    local max = 6

    local a
    local function getStorage()
        for i = min, max do
            a = NPCTasks[i]
            if player:getStorageValue(a.Storage) ~= 2 then
                b = a
                local value = a
                return value
            end
        end
    end

    local function getPositiveStorage()
        for i = min, max do
            a = NPCTasks[i]
            if player:getStorageValue(a.Storage) == 2 then
                b = a
                local value = a
                return value
            end
        end
    end

    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'tasks') or msgcontains(msg, 'missions') or
            msgcontains(msg, 'help') then
            npcHandler.topic[cid] = 1
            local value = getStorage()
            local b = value
            if not value then
                npcHandler:say("You already made all my tasks", cid)
                return false
            end
            if player:getVocation():getId() == 0 then
                npcHandler:say("You need a vocation to take my tasks", cid)
                npcHandler:releaseFocus(cid)
                npcHandler:resetNpc(cid)
                return false
            end
            if player:getStorageValue(b.Storage) ~= 2 and npcHandler.topic[cid] ==
                1 then -- ! Doesnt has tasks
                if b.itemsToBring then
                    local c = b.itemsToBring
                    local amount = #b.itemsToBring
                    local itemList = ""

                    for i = 1, amount, 2 do
                        itemList = itemList .. c[i + 1] .. " " ..
                                       getItemName(c[i]) .. ", "
                    end
                    itemList = string.sub(itemList, 1, -3)
                    toSay = "Can you bring me these items: " .. itemList ..
                                " {yes} or {no} ?"

                    if player:getStorageValue(b.Storage) == 1 then
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay ..
                                " If you already have the items, you should {report} the quest.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler:say(toSay, cid)
                    npcHandler.topic[cid] = 2
                end
                if b.creature then
                    local c = b.creature
                    local d = b.Quantity
                    local v = #c
                    if v > 0 then
                        toSay = "Can you kill ? " .. d .. " " ..
                                    table.concat(c, ", ") .. "."
                    else
                        toSay = "Can you kill ? 0 creatures."
                    end
                    if player:getStorageValue(b.Storage) == 1 then -- ! Incomplete Quest
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay, cid)
                        return false
                    end
                    if player:getStorageValue(b.Storage) == 3 then
                        npcHandler:say(
                            "Seems that you already finished your mission, you should {report} it.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler.topic[cid] = 2
                    npcHandler:say(toSay, cid)
                    return false
                end
                if b.boss then
                    if player:getStorageValue(b.Storage) == 1 then -- ! Incomplete Quest
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay, cid)
                        return false
                    end
                    if player:getStorageValue(b.Storage) == 3 then
                        npcHandler:say(
                            "Seems that you already finished your mission, you should {report} it.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler:say("You need to kil the " .. b.boss[1] ..
                                       " you accept it? {yes} or {no}", cid)
                    npcHandler.topic[cid] = 2
                    return false
                end
            end
        elseif msgcontains(msg, "report") then
            local value = getStorage()
            local b = value
            if not value then
                npcHandler:say("You already made all my tasks", cid)
                return false
            end
            if player:getStorageValue(b.Storage) == 1 or
                player:getStorageValue(b.Storage) == 3 then
                if b.itemsToBring then
                    local c = b.itemsToBring
                    local amount = 0
                    for _ in pairs(b.itemsToBring) do
                        amount = amount + 1
                    end
                    local has_all_items = true
                    for i = 1, amount, 2 do
                        if player:getItemCount(c[i]) < c[i + 1] then
                            has_all_items = false
                            break
                        end
                    end
                    if has_all_items then
                        for i = 1, amount, 2 do
                            player:removeItem(c[i], c[i + 1])
                        end
                        local rewards = b.reward
                        player:addNpcReward(rewards)
                        player:setStorageValue(b.Storage, 2)
                        npcHandler:say(b.lastMessage, cid)
                        npcHandler.topic[cid] = 0
                        return false
                    else
                        npcHandler:say("You don't have all the items.", cid)
                    end
                end

                if b.creature then
                    local rewards = b.reward
                    if player:getStorageValue(b.Storage) == 3 then
                        player:addNpcReward(rewards)
                        npcHandler:say(b.lastMessage, cid)
                        player:setStorageValue(b.Storage, 2)
                    else
                        npcHandler:say("You cannot fool me, go away!.", cid)
                    end
                end
                if b.boss then
                    local rewards = b.reward
                    if player:getStorageValue(b.Storage) == 3 then
                        player:addNpcReward(rewards)
                        npcHandler:say(b.lastMessage, cid)
                        player:setStorageValue(b.Storage, 2)
                    else
                        npcHandler:say("You cannot fool me, go away!.", cid)
                    end
                end
            else
                npcHandler:say("You don't have any task to report.", cid)
            end
        end
    end

    if msgcontains(msg, "yes") then
        if npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) == 2 or
            npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            3 then
            if b.itemsToBring then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
            if b.creature then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
            if b.boss then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
        elseif npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            2 then
            player:setStorageValue(b.Storage, 1)
            npcHandler:say(b.TakeTaskMessage, cid)
            npcHandler.topic[cid] = 0
        end
        if npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            -1 then
            player:setStorageValue(b.Storage, 1)
            npcHandler.topic[cid] = 0
            npcHandler:say(b.TakeTaskMessage, cid)
            if b.creature or b.boss then
                player:setStorageValue(b.Storage * 2, 0)
            end
        end
    end
end

keywordHandler:addKeyword({'quests'}, StdModule.say, {
    npcHandler = npcHandler,
    text = "I can give you some good rewards in trade of some tasks."
})

npcHandler:setMessage(MESSAGE_GREET,
                      "Hey |PLAYERNAME|, can you help me in some {tasks} ?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
When you declare a local variable in lua, it have the scope limited to the block where they are declared. In your case, you are declaring the local variable two times in different if blocks.
You should declare it at the beginning of the function instead:

Lua:
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 voices = {
    {text = 'Hello there, adventurer! Looking for some quests ? I\'m your man!'}
}
npcHandler:addModule(VoiceModule:new(voices))

local function creatureSayCallback(cid, type, msg)

    local toSay

    if not npcHandler:isFocused(cid) then return false end
    local player = Player(cid)

    local min = 0
    local max = 6

    local a
    local function getStorage()
        for i = min, max do
            a = NPCTasks[i]
            if player:getStorageValue(a.Storage) ~= 2 then
                b = a
                local value = a
                return value
            end
        end
    end

    local function getPositiveStorage()
        for i = min, max do
            a = NPCTasks[i]
            if player:getStorageValue(a.Storage) == 2 then
                b = a
                local value = a
                return value
            end
        end
    end

    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'tasks') or msgcontains(msg, 'missions') or
            msgcontains(msg, 'help') then
            npcHandler.topic[cid] = 1
            local value = getStorage()
            local b = value
            if not value then
                npcHandler:say("You already made all my tasks", cid)
                return false
            end
            if player:getVocation():getId() == 0 then
                npcHandler:say("You need a vocation to take my tasks", cid)
                npcHandler:releaseFocus(cid)
                npcHandler:resetNpc(cid)
                return false
            end
            if player:getStorageValue(b.Storage) ~= 2 and npcHandler.topic[cid] ==
                1 then -- ! Doesnt has tasks
                if b.itemsToBring then
                    local c = b.itemsToBring
                    local amount = #b.itemsToBring
                    local itemList = ""

                    for i = 1, amount, 2 do
                        itemList = itemList .. c[i + 1] .. " " ..
                                       getItemName(c[i]) .. ", "
                    end
                    itemList = string.sub(itemList, 1, -3)
                    toSay = "Can you bring me these items: " .. itemList ..
                                " {yes} or {no} ?"

                    if player:getStorageValue(b.Storage) == 1 then
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay ..
                                " If you already have the items, you should {report} the quest.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler:say(toSay, cid)
                    npcHandler.topic[cid] = 2
                end
                if b.creature then
                    local c = b.creature
                    local d = b.Quantity
                    local v = #c
                    if v > 0 then
                        toSay = "Can you kill ? " .. d .. " " ..
                                    table.concat(c, ", ") .. "."
                    else
                        toSay = "Can you kill ? 0 creatures."
                    end
                    if player:getStorageValue(b.Storage) == 1 then -- ! Incomplete Quest
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay, cid)
                        return false
                    end
                    if player:getStorageValue(b.Storage) == 3 then
                        npcHandler:say(
                            "Seems that you already finished your mission, you should {report} it.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler.topic[cid] = 2
                    npcHandler:say(toSay, cid)
                    return false
                end
                if b.boss then
                    if player:getStorageValue(b.Storage) == 1 then -- ! Incomplete Quest
                        npcHandler:say(
                            "You didnt finished your task. " .. toSay, cid)
                        return false
                    end
                    if player:getStorageValue(b.Storage) == 3 then
                        npcHandler:say(
                            "Seems that you already finished your mission, you should {report} it.",
                            cid)
                        npcHandler.topic[cid] = 0
                        return false
                    end
                    npcHandler:say("You need to kil the " .. b.boss[1] ..
                                       " you accept it? {yes} or {no}", cid)
                    npcHandler.topic[cid] = 2
                    return false
                end
            end
        elseif msgcontains(msg, "report") then
            local value = getStorage()
            local b = value
            if not value then
                npcHandler:say("You already made all my tasks", cid)
                return false
            end
            if player:getStorageValue(b.Storage) == 1 or
                player:getStorageValue(b.Storage) == 3 then
                if b.itemsToBring then
                    local c = b.itemsToBring
                    local amount = 0
                    for _ in pairs(b.itemsToBring) do
                        amount = amount + 1
                    end
                    local has_all_items = true
                    for i = 1, amount, 2 do
                        if player:getItemCount(c[i]) < c[i + 1] then
                            has_all_items = false
                            break
                        end
                    end
                    if has_all_items then
                        for i = 1, amount, 2 do
                            player:removeItem(c[i], c[i + 1])
                        end
                        local rewards = b.reward
                        player:addNpcReward(rewards)
                        player:setStorageValue(b.Storage, 2)
                        npcHandler:say(b.lastMessage, cid)
                        npcHandler.topic[cid] = 0
                        return false
                    else
                        npcHandler:say("You don't have all the items.", cid)
                    end
                end

                if b.creature then
                    local rewards = b.reward
                    if player:getStorageValue(b.Storage) == 3 then
                        player:addNpcReward(rewards)
                        npcHandler:say(b.lastMessage, cid)
                        player:setStorageValue(b.Storage, 2)
                    else
                        npcHandler:say("You cannot fool me, go away!.", cid)
                    end
                end
                if b.boss then
                    local rewards = b.reward
                    if player:getStorageValue(b.Storage) == 3 then
                        player:addNpcReward(rewards)
                        npcHandler:say(b.lastMessage, cid)
                        player:setStorageValue(b.Storage, 2)
                    else
                        npcHandler:say("You cannot fool me, go away!.", cid)
                    end
                end
            else
                npcHandler:say("You don't have any task to report.", cid)
            end
        end
    end

    if msgcontains(msg, "yes") then
        if npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) == 2 or
            npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            3 then
            if b.itemsToBring then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
            if b.creature then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
            if b.boss then
                player:setStorageValue(b.Storage, 2)
                npcHandler:say(b.lastMessage, cid)
            end
        elseif npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            2 then
            player:setStorageValue(b.Storage, 1)
            npcHandler:say(b.TakeTaskMessage, cid)
            npcHandler.topic[cid] = 0
        end
        if npcHandler.topic[cid] == 2 and player:getStorageValue(b.Storage) ==
            -1 then
            player:setStorageValue(b.Storage, 1)
            npcHandler.topic[cid] = 0
            npcHandler:say(b.TakeTaskMessage, cid)
            if b.creature or b.boss then
                player:setStorageValue(b.Storage * 2, 0)
            end
        end
    end
end

keywordHandler:addKeyword({'quests'}, StdModule.say, {
    npcHandler = npcHandler,
    text = "I can give you some good rewards in trade of some tasks."
})

npcHandler:setMessage(MESSAGE_GREET,
                      "Hey |PLAYERNAME|, can you help me in some {tasks} ?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
oke so tested it, and npc still dont respond to player saying tasks, ignoring player. And this ignoring happens randomly and differently for every people.

i payed for this npc, idk programing at all just to let know.

p.s tho that error i posted happens very rare, so idk if it fixes the error.
 
Last edited:
i payed for this npc, idk programing at all just to let know.

Whoever took the money should give you a refund.

I wonder what's the mission state 3 is used for. (as it seems both 2 and 3 are kid of similar)
Seems like state 3 was meant to be used to indicate monsters/boss is killed :)

Also it's more difficult to tell something without NPCTasks
Had to reorganize it a bit to undestand but anyway I'm missing whole picture to tell more:

Lua:
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 voices = {
    {text = 'Hello there, adventurer! Looking for some quests ? I\'m your man!'}
}

npcHandler:addModule(VoiceModule:new(voices))

local TaskState = {
    STARTED = 1,
    FINISHED = 2,
    KILLS_COMPLETED = 3
}

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

    local player = Player(cid)
    local missions = table.move(NPCTasks, 1, 6, 1, {})
    local function getMission()
        for _, mission in pairs(missions) do
            if player:getStorageValue(mission.Storage) ~= TaskState.FINISHED then
                return mission
            end
        end

        return nil
    end

    if msgcontains(msg, 'tasks') or msgcontains(msg, 'missions') or msgcontains(msg, 'help') then
        npcHandler.topic[cid] = 1
        local mission = getMission()
        if not mission then
            npcHandler:say("You already made all my tasks", cid)
            return false
        end

        if player:getVocation():getId() == 0 then
            npcHandler:say("You need a vocation to take my tasks", cid)
            npcHandler:releaseFocus(cid)
            npcHandler:resetNpc(cid)
            return false
        end

        local missionState = player:getStorageValue(mission.Storage)
        -- Not yet completed task (describe it to the player)
        if missionState ~= TaskState.FINISHED then
            if mission.itemsToBring then
                local items = mission.itemsToBring -- { id, count, id_2, count_2 }
                local itemList = {}

                for i = 1, #items, 2 do
                    table.insert(itemList, items[i + 1] .. " " .. getItemName(items[i]))
                end

                local message = "Can you bring me these items: " .. table.concat(itemList, ", ") .. " {yes} or {no} ?"
                if missionState == TaskState.STARTED then
                    npcHandler:say("You didnt finished your task. " .. message .. " If you already have the items, you should {report} the quest.", cid)
                    npcHandler.topic[cid] = 0
                    return false
                end

                npcHandler:say(message, cid)
                npcHandler.topic[cid] = 2
            end

            if mission.creature then
                local creatures = mission.creature
                local quantity = #creatures

                local message = "Can you kill ? " .. quantity .. " " .. quantity > 0 and table.concat(creatures, ", ") or "creatures" .. "."
                if missionState == TaskState.STARTED then
                    npcHandler:say("You didnt finished your task. " .. message, cid)
                    return false
                end

                if missionState == TaskState.KILLS_COMPLETED then
                    npcHandler:say("Seems that you already finished your mission, you should {report} it.", cid)
                    npcHandler.topic[cid] = 0
                    return false
                end

                npcHandler.topic[cid] = 2
                npcHandler:say(message, cid)
                return false
            end

            if mission.boss then
                local message = "You need to kil the " .. mission.boss[1]
                if missionState == TaskState.STARTED then
                    npcHandler:say("You didnt finished your task. " .. message, cid)
                    return false
                end

                if missionState == TaskState.KILLS_COMPLETED then
                    npcHandler:say("Seems that you already finished your mission, you should {report} it.", cid)
                    npcHandler.topic[cid] = 0
                    return false
                end

                npcHandler:say(message .. ", you accept it? {yes} or {no}", cid)
                npcHandler.topic[cid] = 2
                return false
            end
        end
    elseif msgcontains(msg, "report") then
        local mission = getMission()
        if not mission then
            npcHandler:say("You already made all my tasks", cid)
            return false
        end

        local missionState = player:getStorageValue(mission.Storage)
        if missionState == TaskState.STARTED or missionState == TaskState.KILLS_COMPLETED then
            local rewards = mission.reward
            if mission.itemsToBring then
                local items = mission.itemsToBring
                local hasAllItems = true

                for i = 1, #items, 2 do
                    local count = items[i + 1]
                    if player:getItemCount(items[i]) < count then
                        hasAllItems = false
                        break
                    end
                end

                if hasAllItems then
                    for i = 1, #items, 2 do
                        local count = items[i + 1]
                        player:removeItem(items[i], count)
                    end

                    player:addNpcReward(rewards)
                    player:setStorageValue(mission.Storage, TaskState.FINISHED)
                    npcHandler:say(mission.lastMessage, cid)
                    npcHandler.topic[cid] = 0
                    return false
                else
                    npcHandler:say("You don't have all the items.", cid)
                end
            end

            if mission.creature then
                if missionState == TaskState.KILLS_COMPLETED then
                    player:addNpcReward(rewards)
                    npcHandler:say(mission.lastMessage, cid)
                    player:setStorageValue(mission.Storage, TaskState.FINISHED)
                else
                    npcHandler:say("You cannot fool me, go away!.", cid)
                end
            end

            if mission.boss then
                if missionState == TaskState.KILLS_COMPLETED then
                    player:addNpcReward(rewards)
                    npcHandler:say(mission.lastMessage, cid)
                    player:setStorageValue(mission.Storage, TaskState.FINISHED)
                else
                    npcHandler:say("You cannot fool me, go away!.", cid)
                end
            end
        else
            npcHandler:say("You don't have any task to report.", cid)
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        local mission = getMission() or {}
        local missionState = player:getStorageValue(mission.Storage)

        -- Do we even need that?
        -- -- npcTopic == 2 and missionState or npcTopic == 2 or npcTopic == 2 and missionState
        --if table.contains({ TaskState.FINISHED, TaskState.KILLS_COMPLETED }, missionState) then
        --    if mission.itemsToBring or mission.creature or mission.boss then
        --        player:setStorageValue(mission.Storage, TaskState.FINISHED)
        --        npcHandler:say(mission.lastMessage, cid)
        --    end
        --elseif missionState == TaskState.FINISHED then
        --    -- So is it to restart once finished? But is it even possible to get there? as it's handled above
        --    player:setStorageValue(mission.Storage, TaskState.STARTED)
        --    npcHandler:say(mission.TakeTaskMessage, cid)
        --    npcHandler.topic[cid] = 0
        --end

        -- Start task
        if missionState == -1 then
            player:setStorageValue(mission.Storage, TaskState.STARTED)
            npcHandler.topic[cid] = 0
            npcHandler:say(mission.TakeTaskMessage, cid)
            if mission.creature or mission.boss then
                player:setStorageValue(mission.Storage * 2, 0)
            end
        end
    end
end

keywordHandler:addKeyword({'quests'}, StdModule.say, { npcHandler = npcHandler, text = "I can give you some good rewards in trade of some tasks." })

npcHandler:setMessage(MESSAGE_GREET, "Hey |PLAYERNAME|, can you help me in some {tasks} ?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Whoever took the money should give you a refund.

I wonder what's the mission state 3 is used for. (as it seems both 2 and 3 are kid of similar)
Seems like state 3 was meant to be used to indicate monsters/boss is killed :)

Also it's more difficult to tell something without NPCTasks
Had to reorganize it a bit to undestand but anyway I'm missing whole picture to tell more:

Lua:
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 voices = {
    {text = 'Hello there, adventurer! Looking for some quests ? I\'m your man!'}
}

npcHandler:addModule(VoiceModule:new(voices))

local TaskState = {
    STARTED = 1,
    FINISHED = 2,
    KILLS_COMPLETED = 3
}

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

    local player = Player(cid)
    local missions = table.move(NPCTasks, 1, 6, 1, {})
    local function getMission()
        for _, mission in pairs(missions) do
            if player:getStorageValue(mission.Storage) ~= TaskState.FINISHED then
                return mission
            end
        end

        return nil
    end

    if msgcontains(msg, 'tasks') or msgcontains(msg, 'missions') or msgcontains(msg, 'help') then
        npcHandler.topic[cid] = 1
        local mission = getMission()
        if not mission then
            npcHandler:say("You already made all my tasks", cid)
            return false
        end

        if player:getVocation():getId() == 0 then
            npcHandler:say("You need a vocation to take my tasks", cid)
            npcHandler:releaseFocus(cid)
            npcHandler:resetNpc(cid)
            return false
        end

        local missionState = player:getStorageValue(mission.Storage)
        -- Not yet completed task (describe it to the player)
        if missionState ~= TaskState.FINISHED then
            if mission.itemsToBring then
                local items = mission.itemsToBring -- { id, count, id_2, count_2 }
                local itemList = {}

                for i = 1, #items, 2 do
                    table.insert(itemList, items[i + 1] .. " " .. getItemName(items[i]))
                end

                local message = "Can you bring me these items: " .. table.concat(itemList, ", ") .. " {yes} or {no} ?"
                if missionState == TaskState.STARTED then
                    npcHandler:say("You didnt finished your task. " .. message .. " If you already have the items, you should {report} the quest.", cid)
                    npcHandler.topic[cid] = 0
                    return false
                end

                npcHandler:say(message, cid)
                npcHandler.topic[cid] = 2
            end

            if mission.creature then
                local creatures = mission.creature
                local quantity = #creatures

                local message = "Can you kill ? " .. quantity .. " " .. quantity > 0 and table.concat(creatures, ", ") or "creatures" .. "."
                if missionState == TaskState.STARTED then
                    npcHandler:say("You didnt finished your task. " .. message, cid)
                    return false
                end

                if missionState == TaskState.KILLS_COMPLETED then
                    npcHandler:say("Seems that you already finished your mission, you should {report} it.", cid)
                    npcHandler.topic[cid] = 0
                    return false
                end

                npcHandler.topic[cid] = 2
                npcHandler:say(message, cid)
                return false
            end

            if mission.boss then
                local message = "You need to kil the " .. mission.boss[1]
                if missionState == TaskState.STARTED then
                    npcHandler:say("You didnt finished your task. " .. message, cid)
                    return false
                end

                if missionState == TaskState.KILLS_COMPLETED then
                    npcHandler:say("Seems that you already finished your mission, you should {report} it.", cid)
                    npcHandler.topic[cid] = 0
                    return false
                end

                npcHandler:say(message .. ", you accept it? {yes} or {no}", cid)
                npcHandler.topic[cid] = 2
                return false
            end
        end
    elseif msgcontains(msg, "report") then
        local mission = getMission()
        if not mission then
            npcHandler:say("You already made all my tasks", cid)
            return false
        end

        local missionState = player:getStorageValue(mission.Storage)
        if missionState == TaskState.STARTED or missionState == TaskState.KILLS_COMPLETED then
            local rewards = mission.reward
            if mission.itemsToBring then
                local items = mission.itemsToBring
                local hasAllItems = true

                for i = 1, #items, 2 do
                    local count = items[i + 1]
                    if player:getItemCount(items[i]) < count then
                        hasAllItems = false
                        break
                    end
                end

                if hasAllItems then
                    for i = 1, #items, 2 do
                        local count = items[i + 1]
                        player:removeItem(items[i], count)
                    end

                    player:addNpcReward(rewards)
                    player:setStorageValue(mission.Storage, TaskState.FINISHED)
                    npcHandler:say(mission.lastMessage, cid)
                    npcHandler.topic[cid] = 0
                    return false
                else
                    npcHandler:say("You don't have all the items.", cid)
                end
            end

            if mission.creature then
                if missionState == TaskState.KILLS_COMPLETED then
                    player:addNpcReward(rewards)
                    npcHandler:say(mission.lastMessage, cid)
                    player:setStorageValue(mission.Storage, TaskState.FINISHED)
                else
                    npcHandler:say("You cannot fool me, go away!.", cid)
                end
            end

            if mission.boss then
                if missionState == TaskState.KILLS_COMPLETED then
                    player:addNpcReward(rewards)
                    npcHandler:say(mission.lastMessage, cid)
                    player:setStorageValue(mission.Storage, TaskState.FINISHED)
                else
                    npcHandler:say("You cannot fool me, go away!.", cid)
                end
            end
        else
            npcHandler:say("You don't have any task to report.", cid)
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        local mission = getMission() or {}
        local missionState = player:getStorageValue(mission.Storage)

        -- Do we even need that?
        -- -- npcTopic == 2 and missionState or npcTopic == 2 or npcTopic == 2 and missionState
        --if table.contains({ TaskState.FINISHED, TaskState.KILLS_COMPLETED }, missionState) then
        --    if mission.itemsToBring or mission.creature or mission.boss then
        --        player:setStorageValue(mission.Storage, TaskState.FINISHED)
        --        npcHandler:say(mission.lastMessage, cid)
        --    end
        --elseif missionState == TaskState.FINISHED then
        --    -- So is it to restart once finished? But is it even possible to get there? as it's handled above
        --    player:setStorageValue(mission.Storage, TaskState.STARTED)
        --    npcHandler:say(mission.TakeTaskMessage, cid)
        --    npcHandler.topic[cid] = 0
        --end

        -- Start task
        if missionState == -1 then
            player:setStorageValue(mission.Storage, TaskState.STARTED)
            npcHandler.topic[cid] = 0
            npcHandler:say(mission.TakeTaskMessage, cid)
            if mission.creature or mission.boss then
                player:setStorageValue(mission.Storage * 2, 0)
            end
        end
    end
end

keywordHandler:addKeyword({'quests'}, StdModule.say, { npcHandler = npcHandler, text = "I can give you some good rewards in trade of some tasks." })

npcHandler:setMessage(MESSAGE_GREET, "Hey |PLAYERNAME|, can you help me in some {tasks} ?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye and come again, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

this npc task system, itself kinda working perfect for all mission kinds, but RARELY it starts ignoring player not ansfering anymore to 'tasks' or 'report', tho responds to 'hi'


Data/lib part script from this tasks system:


Lua:
NPCTasks = {


   [0] = { creature = {"Orc", "Orc Warrior", "Orc Spearman", "Orc Berserker", "Orc Leader", "Orc Marauder", "Orc Shaman"}, Quantity = 150, TakeTaskMessage = 'Thanks for taking this task', reward = { statsPoint = 1, experience = 50000, storage = 0, items = { 2160, 10, 26179, 1 } }, Storage = 39000, lastMessage = "Thanks for doing it for me, bye" },
   [1] = { itemsToBring = { 8872, 3, 11219, 50 }, TakeTaskMessage = 'Thanks for taking this task', reward = { statsPoint = 10, experience = 70000, storage = 1000, items = { 26179, 1 , 2160, 100} }, Storage = 39001, lastMessage = "Thanks for doing it for me, bye" }, -- ,
   [2] = { creature = {"Gozzler"}, Quantity = 180, reward = { statsPoint = 1, experience = 90000, storage = 0, items = { 2160, 10, 26179, 1 } }, Storage = 39002, TakeTaskMessage = "Please do it for me, you can find gozzlers on teleports and in exploreable area :)", lastMessage = "Thanks for doing it for me, bye" },
   [3] = { itemsToBring = { 11334, 15, 11335, 20, 5881, 25, 11333, 15 }, reward = { statsPoint = 1, experience = 100000, storage = 0, items = { 2160, 20 } }, Storage = 39003, TakeTaskMessage = "Please do it for me :)", lastMessage = "Thanks for doing it for me, bye" },
   [4] = { creature = {"Killer Caiman"}, Quantity = 80, reward = { statsPoint = 2, experience = 120000, storage = 0, items = { 2160, 20, 27604, 1 } }, Storage = 39004, TakeTaskMessage = "Please do it for me :)", lastMessage = "Thanks for doing it for me, bye" },
   [5] = { itemsToBring = { 12405, 50, 10602, 70 }, reward = { statsPoint = 2, experience = 140000, storage = 0, items = { 2160, 30 } }, Storage = 39005, TakeTaskMessage = "Please do it for me, vampires can be found on teleports and in exploreable area :)", lastMessage = "Thanks for doing it for me, bye" },
   [6] = { boss = {"Orshabaal"}, Quantity = 2, reward = { statsPoint = 4, experience = 160000, storage = 0, items = { 40554, 50, 2160, 30, 28436, 1 } }, Storage = 39006, TakeTaskMessage = "Please do it for me, you can find the boss using command /bosses and exiva the boss :)", lastMessage = "Thanks for doing it for me, bye" },

   [7] = { creature = {"Demon"}, Quantity = 150, TakeTaskMessage = 'Thanks for taking this task, you can find demons in teleports room and exploreable area', reward = { statsPoint = 2, experience = 160000, storage = 0, items = { 2160, 20, 27604, 1 } }, Storage = 39007, lastMessage = "Thanks for doing it for me, bye" },
   [8] = { itemsToBring = { 11199, 100, 41529, 2 }, TakeTaskMessage = 'Thanks for taking this task', reward = { statsPoint = 3, experience = 200000, storage = 0, items = { 27604, 1, 8306, 1 } }, Storage = 39008, lastMessage = "Thanks for doing it for me, bye" }, -- ,
   [9] = { creature = {"Infected Weeper"}, Quantity = 125, reward = { statsPoint = 3, experience = 220000, storage = 0, items = { 2160, 30 } }, Storage = 39009, TakeTaskMessage = "Please do it for me :)", lastMessage = "Thanks for doing it for me, bye" },
   [10] = { itemsToBring = { 5922, 25, 5921, 50, 10552, 100 }, reward = { statsPoint = 3, experience = 220000, storage = 0, items = { 2160, 40 } }, Storage = 39010, TakeTaskMessage = "Please do it for me :)", lastMessage = "Thanks for doing it for me, bye" },
   [11] = { creature = {"Elf", "Elf Scout", "Elf Arcanist"}, Quantity = 180, reward = { statsPoint = 3, experience = 220000, storage = 0, items = { 2472, 5 } }, Storage = 39011, TakeTaskMessage = "Please do it for me :)", lastMessage = "Thanks for doing it for me, bye" },
   [12] = { itemsToBring = { 41529, 5, 26179, 10, 5943, 2 }, reward = { statsPoint = 4, experience = 220000, storage = 0, items = { 27604, 2 } }, Storage = 39012, TakeTaskMessage = "Please do it for me, you can find boss with command /bosses :)", lastMessage = "Thanks for doing it for me, bye" },
   [13] = { boss = {"Ghazbaran"}, Quantity = 2, reward = { statsPoint = 8, experience = 420000, storage = 0, items = { 40554, 100, 8306, 2, 28436, 1 } }, Storage = 39013, TakeTaskMessage = "Young warrior i see you are growing big, this boss Morgaroth can be found in hes temple, the temple teleport is protected by Orshabaal, be carefull its very damgerous place !!!", lastMessage = "Thanks for doing it for me, bye" },
 
   [14] = { creature = {"Snake", "Bug"}, Quantity = 30, TakeTaskMessage = 'Explore around the Main Evotronus city and its tunnels.', reward = { statsPoint = 1, experience = 1000, storage = 0, items = { 2160, 1 } }, Storage = 39014, lastMessage = "Thanks you a lot for cleaning the city, here some reward for you" },
   [15] = { itemsToBring = { 24174, 1 }, TakeTaskMessage = 'I need undying light elixir, please find it in these tunnels, i know there are spiders around the elixit i feel it, bring it to me', reward = { statsPoint = 1, experience = 2000, storage = 0, items = { 2160, 1 } }, Storage = 39015, lastMessage = "Good job yoong soul, keep growing!" }, -- ,
   [16] = { creature = {"Spider", "Poison Spider"}, Quantity = 50, reward = { statsPoint = 1, experience = 3000, storage = 0, items = { 2160, 2 } }, Storage = 39016, TakeTaskMessage = "Can you get some info about {Northeast} of the city?", lastMessage = "Thanks for completing this task." },
   [17] = { itemsToBring = { 24181, 1 }, reward = { statsPoint = 1, experience = 4000, storage = 0, items = { 2160, 3 } }, Storage = 39017, TakeTaskMessage = "Please bring me elixir of life everchanging, you can find this item near crocodiles, you can use command /bosses and try locate the snapper and by trying locate it you can find this item", lastMessage = "Thanks it will help a lot, also you should check about craftingSystem" },
   [18] = { creature = {"Swamp Troll"}, Quantity = 20, reward = { statsPoint = 1, experience = 5000, storage = 0, items = { 2160, 2 } }, Storage = 39018, TakeTaskMessage = "You can find these swamp trolls deep in the city tunnels.", lastMessage = "Thanks it will help the city a lot" },
   [19] = { itemsToBring = { 26180, 20}, reward = { statsPoint = 1, experience = 6000, storage = 0, items = { 2160, 5 } }, Storage = 39019, TakeTaskMessage = "Can you get some of this item for me ?", lastMessage = "Thanks, atlast i can buy blessing with these small energy balls." },
   [20] = { boss = {"Rorc"}, Quantity = 1, reward = { statsPoint = 2, experience = 7000, storage = 0, items = { 2160, 20 } }, Storage = 39020, TakeTaskMessage = "This boss is located in Evotronus city, to easier to find it use command /bosses", lastMessage = "Good job young soul, keep exploring!" },
 
   [21] = { creature = {"Earth Elemental"}, Quantity = 50, TakeTaskMessage = 'There is 2x passages to Grasslands, and for both need keys, you can find keys if you explore, 1 acces is near me , second more east of the city.', reward = { statsPoint = 1, experience = 50000, storage = 0, items = { 2160, 10 } }, Storage = 39021, lastMessage = "Well done young explorer, i see you got some fire in you!" },
   [22] = { itemsToBring = { 32977, 1 }, TakeTaskMessage = 'Help me to get back my fellow amanita muscaria, it been taked by Dwurfs, lots of them.... Explore far north in Grasslands i heard they stay near Grasslands safehouse, bring my mushroom back, please!', reward = { statsPoint = 2, experience = 200000, storage = 0, items = { 34214, 30, 34215, 15 } }, Storage = 39022, lastMessage = "Wow you defeated Dwurfs, i heard they are more stronger then Dwarfs, well done, keep growing, here i give you some powerfull organic berrys!" }, -- ,
   [23] = { creature = {"Askarak Lord", "Askarak Demon", "Askarak Prince"}, Quantity = 250, reward = { statsPoint = 3, experience = 200000, storage = 0, items = { 2160, 20, 21401, 1 } }, Storage = 39023, TakeTaskMessage = "Please try help the grounds of Grasslands be less of Askaraks, they seem to make the hive in the Grasslands", lastMessage = "Thanks for completing this task, here some nice reward for you." },
   [24] = { itemsToBring = { 32665, 1 }, reward = { statsPoint = 4, experience = 40000, storage = 0, items = { 27604, 1 } }, Storage = 39024, TakeTaskMessage = "Please bring me rainbow amanita muscaria, the strongest magic mushroom in our galaxy...Shaburaks been speaking widely about theyr finding, bring it to me from them", lastMessage = "Oh, i hope didint bite tiny bit, this psichodelic mushroom is to strong for newbiew to handle! Oh my mushy... Thanks young soul, here are your rewards for you!" },
   [25] = { creature = {"Dark Torturer"}, Quantity = 300, reward = { statsPoint = 5, experience = 250000, storage = 0, items = { 2160, 85, 21401, 1, 8300, 2 } }, Storage = 39025, TakeTaskMessage = "The old civilization graves have beeen disrespected by those Dark Torturers , please help the old warriors graves.", lastMessage = "We already felt changed of vibration in the air even way before you reported back your mission, well done young soul, keep growing!" },
   [26] = { itemsToBring = { 15572, 1}, reward = { statsPoint = 6, experience = 1000000, storage = 0, items = { 28436, 1, 27604, 3 } }, Storage = 39026, TakeTaskMessage = "Please find me an Yielothax egg, its slimy green thingy...I hear the cave is pickable in Grasslands near those Crystalcrushers, anyway, good luck!", lastMessage = "Thanks thanks thanks i can start my alchemy now, here some rewards for you,and now i can give you last boss hunt mission!" },
   [27] = { boss = {"Wyvern Draco"}, Quantity = 5, reward = { statsPoint = 7, experience = 700000, storage = 0, items = { 40554, 100, 21401, 2, 27604, 3 } }, Storage = 39027, TakeTaskMessage = "This boss is located in Far east from Evotronus city behind the mountains, to easier to find it use command /bosses", lastMessage = "Good job young soul, keep exploring!" },
 
 
}

function Player.addNpcReward(self, value)
   if not value or not value.items then
      error("You are missing some values in the table")
   end
   local items = value.items
   local statsPoint = value.statsPoint
   local experience = value.experience
   local storage = value.storage

   local message = ""
   local item_count = #items
   if item_count >= 2 and item_count % 2 == 0 then
       for i = 1, item_count, 2 do
           local item_id = items[i]
           local item_amount = items[i + 1]
           self:addItem(item_id, item_amount)
           message = message .. "You received: x" .. item_amount .. " " .. getItemName(item_id) .. ", "
       end
       message = string.sub(message, 1, -3) .. "."
   end

   if statsPoint > 0 then
       self:addStatsPoint(statsPoint)
       message = message .. " You received: " .. statsPoint .. " stats points. "
   end
 
   if experience > 0 then
       self:addExperience(experience)
       message = message .. "You received: " .. experience .. " experience points. "
   end
 
   if storage > 0 then
       self:setStorageValue(storage, 1)
       message = message .. "You received one quest access. "
   end
 
   self:sendTextMessage(MESSAGE_INFO_DESCR, message)
end


Deleted alot mission lines so code fits to post.
So at npc i set range of missions it gives:

local min = 0
local max = 6

So from 0-6 mission npc gives.
 
Back
Top