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

NPC Task Problem

Dorianek

Member
Joined
Nov 29, 2018
Messages
247
Reaction score
10
Location
Poland
Hello All.

Hello, I have a problem with the npc task script, I note that I have a problem with only one line because the rest works

the point is that when he performs the task to kill 1 Demon Lord (when he kills him) I come back and receive the message that I did not kill the Demon Lord


(Creaturescript)

Code:
    local storage_string = {[80000] = "The Snapper",
[80001] = "Demodras",
[80002] = "The Hide",
[80003] = "The Bloodtusk",
[80004] = "The Shardhead",
[80005] = "Thul",
[80006] = "Esmeralda",
[80007] = "The Old Widow",
[80008] = "The Many",
[80009] = "The Leviathan",
[80010] = "The Stonecracker",
[80011] = "The Noxious Spawn",
[80012] = "Merikh The Slaughterer",
[80013] = "Fahim The Wise",
[80014] = "pirate leader",
[80015] = "The Horned Fox",
[80016] = "Necropharus",
[80017] = "Demon Lord",

NPC

Code:
local storage = 62003
local monsters = {
   ["Dragon"] = {storage = 5010, mstorage = 19000, amount = 600, exp = 5000, items = {{id = 2157, count = 1}, {id = 2160, count = 3}}},
   ["Dragon Lord"] = {storage = 5011, mstorage = 19001, amount = 600, exp = 1000, items = {{id = 2492, count = 1}, {id = 2160, count = 5}}},
   ["Hydra"] = {storage = 5012, mstorage = 19002, amount = 600, exp = 18000, items = {{id = 2195, count = 1}, {id = 2157, count = 8}}},
   ["Demon"] = {storage = 5013, mstorage = 19003, amount = 600, exp = 20000, items = {{id = 2520, count = 1}, {id = 2160, count = 10}}},
   ["Demon Lord"] = {storage = 5014, mstorage = 19004, amount = 1, exp = 25000, items = {{id = 2520, count = 1}, {id = 2160, count = 50}}},
}


Does not work only for me Demon Lord can someone help maybe something I'm doing wrong?
 
Hello Ramirow ! :)
ok

Script.lua

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}
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 storage = 62003
local monsters = {
   ["Dragon"] = {storage = 5010, mstorage = 19000, amount = 1, exp = 5000, items = {{id = 2157, count = 1}, {id = 2160, count = 3}}},
   ["Dragon Lord"] = {storage = 5011, mstorage = 19001, amount = 600, exp = 1000, items = {{id = 2492, count = 1}, {id = 2160, count = 5}}},
   ["Hydra"] = {storage = 5012, mstorage = 19002, amount = 600, exp = 18000, items = {{id = 2195, count = 1}, {id = 2157, count = 8}}},
   ["Demon"] = {storage = 5013, mstorage = 19003, amount = 600, exp = 20000, items = {{id = 2520, count = 1}, {id = 2160, count = 10}}},
   ["Demon Lord"] = {storage = 5014, mstorage = 19004, amount = 1, exp = 25000, items = {{id = 2520, count = 1}, {id = 2160, count = 50}}},
}
local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end
local function Cptl(f, r)
     return f:upper()..r:lower()
end
function creatureSayCallback(cid, type, msg)
     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You already did all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, 2)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You already did all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue an other task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You didn't start any new task yet, if you want to start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)



Task Widow Creature

Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
   if modalWindowId ~= 1900 then
       return false
   end
  
   local rank = getCreatureStorage(cid, rankStorage)
   if rank < 0 then
       doCreatureSetStorage(cid, rankStorage, 0)
   end
                  
   local r_string = function() if tasks[choiceId].repeatable then return "repeatable" end return "not repeatable" end
   local r_article_string = function (id, amount)
       task_item_word = ""
       if amount > 1 then
           task_item_word = task_item_word .. amount .. "x " .. getItemName(id)
       else
           if ItemType(itemId):getArticle() == "" then
               task_item_word = task_item_word .. getItemName(id)
           else
               task_item_word = task_item_word .. ItemType(itemId):getArticle() .. " " .. getItemName(id)
           end
       end
   return task_item_word
   end
   local storage_string = {[80000] = "The Snapper",
[80001] = "Demodras",
[80002] = "The Hide",
[80003] = "The Bloodtusk",
[80004] = "The Shardhead",
[80005] = "Thul",
[80006] = "Esmeralda",
[80007] = "The Old Widow",
[80008] = "The Many",
[80009] = "The Leviathan",
[80010] = "The Stonecracker",
[80011] = "The Noxious Spawn",
[80012] = "Merikh The Slaughterer",
[80013] = "Fahim The Wise",
[80014] = "pirate leader",
[80015] = "The Horned Fox",
[80016] = "Necropharus",
[80017] = "Demon Lord",

   }

   if buttonId == 1 then -- confirm task
       if getCreatureStorage(cid, tasks[choiceId].questStarted) < 1 then
           doCreatureSetStorage(cid, tasks[choiceId].questStarted, 1)
           doCreatureSetStorage(cid, tasks[choiceId].questStorage, 0)
           doCreatureSay(taskNPCuid, "In this mission you have to hunt " .. tasks[choiceId].killsRequired .. " " .. tasks[choiceId].raceName .. " down. Good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
       else
           if getCreatureStorage(cid, tasks[choiceId].questStarted) == 1 then
               if tasks[choiceId].killsRequired > getCreatureStorage(cid, tasks[choiceId].questStorage) then
                   doPlayerPopupFYI(cid,"Status: Active\nKills: " .. getCreatureStorage(cid, tasks[choiceId].questStorage) .. "/" .. tasks[choiceId].killsRequired .. " (" .. tasks[choiceId].killsRequired - getCreatureStorage(cid, tasks[choiceId].questStorage) .. " left)\n\nThis mission is " .. r_string() .. ".")
                   sendTaskWindow(cid)
               else
                   doCreatureSetStorage(cid, tasks[choiceId].questStarted, 2)
                   task_reward_str = "Reward(s):\n"
                   for i = 1, table.maxn(tasks[choiceId].rewards) do
                       if(tasks[choiceId].rewards[i].enable) then
                           if isInArray({"boss", "teleport", 1}, tasks[choiceId].rewards[i].type) then
                               doTeleportThing(cid, tasks[choiceId].rewards[i].values)
                               task_reward_str = task_reward_str .. "You have been teleported.\n"
                           elseif isInArray({"exp", "experience", 2}, tasks[choiceId].rewards[i].type) then
                               doPlayerAddExperience(cid, tasks[choiceId].rewards[i].values)
                               task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " exp\n"
                           elseif isInArray({"item", 3}, tasks[choiceId].rewards[i].type) then
                               doPlayerAddItem(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
                               task_reward_str = task_reward_str .. r_article_string(tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2]) .. "\n"
                           elseif isInArray({"money", 4}, tasks[choiceId].rewards[i].type) then
                               doPlayerAddMoney(cid, tasks[choiceId].rewards[i].values)
                               task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " gp\n"
                           elseif isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
                               doCreatureSetStorage(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
                               task_reward_str = task_reward_str .. "Chance to duel " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. ".\n"
                           elseif isInArray({"points", "rank", 2}, tasks[choiceId].rewards[i].type) then
                               doCreatureSetStorage(cid, rankStorage, getCreatureStorage(cid, rankStorage) + tasks[choiceId].rewards[i].values)
                               task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " rank points.\n"
                           else
                               print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[choiceId].rewards[i].type or "nil") .. ", reward could not be loaded.")
                           end
                       end
                   end
                   if task_reward_str == "Reward(s):\n" then
                       doPlayerPopupFYI(cid,task_reward_str .. "none")
                   else
                       doPlayerPopupFYI(cid,task_reward_str)
                   end
                   doCreatureSay(taskNPCuid, "Great job" .. (((rank > 4 and rank < 10) and (", Huntsman") or (rank > 9 and rank < 20) and (", Ranger") or (rank > 19 and rank < 30) and (", Big Game Hunter") or (rank > 29 and rank < 50) and (", Trophy Hunter") or (rank > 49) and (", Elite Hunter")) or ", my Beginner") .. "! Here is your reward. Keep hunting and good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
               end
           else
               if tasks[choiceId].repeatable then
                   for i = 1, table.maxn(tasks[choiceId].rewards) do
                       if isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
                           doPlayerPopupFYI(cid,"To repeat this mission again, fight with " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. " first.")
                           break
                       end
                       if i == table.maxn(tasks[choiceId].rewards) then
                           doPlayerPopupFYI(cid,"You can't repeat this mission.")
                       end
                   end
               else
                   doPlayerPopupFYI(cid,"You can't repeat this mission.")
               end
               sendTaskWindow(cid)
           end
       end
   elseif buttonId == 255 then
       doPlayerPopupFYI(cid,"Please use a button.")
       sendTaskWindow(cid)
   end
  
return true
end

Version 1.3 tfs
 
Bump

after killing eg Demon Lord npc claims that I did not kill the below I'm putting the script

creature script
Code:
local config = {
     ['dragon'] = {amount = 10, storage = 19000, startstorage = 5010, startvalue = 1},
     ['dragon lord'] = {amount = 10, storage = 19001, startstorage = 5011, startvalue = 1},
     ['hydra'] = {amount = 10, storage = 19002, startstorage = 5012, startvalue = 1},
     ['demon'] = {amount = 10, storage = 19003, startstorage = 5013, startvalue = 1},
     ['demon lord'] = {amount = 1, storage = 19004, startstorage = 5014, startvalue = 1}


}
function onKill(player, target)
     local monster = config[target:getName():lower()]
     if target:isPlayer() or not monster or target:getMaster() then
         return true
     end
     local stor = player:getStorageValue(monster.storage)+1
     if stor < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
         player:setStorageValue(monster.storage, stor)
         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(stor +1)..' of '..monster.amount..' '..target:getName()..'s killed.')
     end
     if (stor +1) == monster.amount then
         player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(stor +1)..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
         player:setStorageValue(monster.storage, stor +1)
     end
     return true
end


.Lua

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}
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 storage = 62003
local monsters = {
   ["Dragon"] = {storage = 5010, mstorage = 19000, amount = 1, exp = 5000, items = {{id = 2157, count = 1}, {id = 2160, count = 3}}},
   ["Dragon Lord"] = {storage = 5011, mstorage = 19001, amount = 600, exp = 1000, items = {{id = 2492, count = 1}, {id = 2160, count = 5}}},
   ["Hydra"] = {storage = 5012, mstorage = 19002, amount = 600, exp = 18000, items = {{id = 2195, count = 1}, {id = 2157, count = 8}}},
   ["Demon"] = {storage = 5013, mstorage = 19003, amount = 600, exp = 20000, items = {{id = 2520, count = 1}, {id = 2160, count = 10}}},
   ["Demon Lord"] = {storage = 5014, mstorage = 19004, amount = 1, exp = 25000, items = {{id = 2520, count = 1}, {id = 2160, count = 50}}},
}
local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end
local function Cptl(f, r)
     return f:upper()..r:lower()
end
function creatureSayCallback(cid, type, msg)
     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You already did all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, 2)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You already did all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue an other task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You didn't start any new task yet, if you want to start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)




I have to kill 50DL, I need to kill 50DL, I get info from npc
You did not kill them all, you still need to kill 39 Dragon Lord.
 
Last edited:
Back
Top