• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

problem with task script

wafuboe

Active Member
Joined
Dec 24, 2010
Messages
884
Solutions
2
Reaction score
26
Hello ive benn adding mission to this task script.

Ive work on several errors but on this one im stuck i have check other examples and i dont how to fix it
Im using tfs 1.3

also if someone can detect more problems i apreeciate

thanks

246tdvd.png


Script:
Code:
-- Collecting items and monster missions by Limos
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 missions = {
   [1] = {
     items = {
       {id = 10609, count = 5},
       {id = 2230, count = 1},
       {id = 12437, count = 5}
     },
     message = "Great, for your first mission you need to collect some items, I need for a ritual",
     level = 7, -- minimum level voor this mission
     rewarditems = {
       {id = 2152, count = 5}
     },
     rewardexp = 5000
   },
   [2] = {
     monsters = {
       {name = "Rotworms", count = 30, storage = 21900}
     },
     message = "Thanks, we have a problem in the city sewers for your next mission kill",
     level = 7,
     rewarditems = {
       {id = 5710, count = 5}
     },
     rewardexp = 10000
   },
   [3] = {
     items = {
       {id = 10569, count = 1},
       {id = 12400, count = 15},
       {id = 12399, count = 15}
     },
     message = "Awesome rookie, now get me from the amazon camp",
     level = 10,
     rewarditems = {
       {id = 2463, count = 1}
     },
     rewardexp = 170000
   },
   [4] = {
     monsters = {
       {name = "Minotaurs", count = 50, storage = 21901},
       {name = "Minotaur Archers", count = 25, storage = 21902},
       {name = "Minotaur Mages", count = 15, storage = 21903},
       {name = "Minotaur Guards", count = 15, storage = 21904}
     },
     message = "Good job, we are having problems in the outer camps near plains of havoc now kill",
     level = 15,
     rewarditems = {
       {id = 2152, count = 35}
     },
     rewardexp = 40000
   },
   [5] = {
     items = {
       {id = 10574, count = 45},
       {id = 7398, count = 1}
     },
     message = "Good, i need some items from the cyclops camp,",
     level = 20,
     rewarditems = {
       {id = 2486, count = 1}
     },
     rewardexp = 50000
      },
    [6] = {
     monsters = {
       {name = "Dwarf Soldiers", count = 50, storage = 21905},
       {name = "Dwarf Guards", count = 25, storage = 21906},
       {name = "Dwarf Geomancer", count = 5, storage = 21907}
     },
     message = "Good job, we are having problems with dwarf rebels in the mine now kill",
     level = 20,
     rewarditems = {
       {id = 5880, count = 20}
     },
     rewardexp = 65000
   },
   [7] = {
     items = {
       {id = 11198, count = 45},
       {id = 8859, count = 25}
     },
     message = "Excellent, i need some arachnids items for my research on the plague bring me",
     level = 20,
     rewarditems = {
       {id = 8872, count = 1}
     },
     [8] = {
     monsters = {
       {name = "Dragons", count = 15, storage = 21908}
     },
     message = "Impressive those dwarfs will stay calm, you need a real challenge kill",
     level = 30,
     rewarditems = {
       {id = 2516, count = 1},
       {id = 2392, count = 1}
     },
     rewardexp = 80000
   },
    [9] = {
     items = {
       {id = 10566, count = 20},
       {id = 12422, count = 20},
       {id = 12423, count = 50},
       {id = 10564, count = 10},
       {id = 11200, count = 15},
       {id = 10602, count = 5}
     },
     message = "I'm amazed, ok i need some undead items for my ritual try not to die okay? Bring me",
     level = 30,
     rewarditems = {
       {id = 2656, count = 1}
     },
     [10] = {
     monsters = {
       {name = "Blue Djinns", count = 40, storage = 21909},
       {name = "Green Djinns", count = 40, storage = 21910}
     },
     message = "Tension between the djinns are causing serious problems kill",
     level = 35,
     rewarditems = {
       {id = 7730, count = 1}
     },
     rewardexp = 90000
   },
   [11] = {
     items = {
       {id = 12413, count = 35},
       {id = 5877, count = 20},
       {id = 5920, count = 5}
     },
     message = "That would be it. Merchants are asking me for dragon products. Bring me",
     level = 40,
     rewarditems = {
       {id = 2160, count = 2}
     },
     [12] = {
     monsters = {
       {name = "Necromancers", count = 150, storage = 21911}
     },
     message = "We have to erracticate Necromancers, they are kidnaping people for their rituals. Kill ",
     level = 40,
     rewarditems = {
       {id = 8922, count = 1},
        {id = 8910, count = 1}
     },
     rewardexp = 120000
   },
   [13] = {
     items = {
       {id = 11225, count = 50},
       {id = 10585, count = 25},
       {id = 10579, count = 20},
       {id = 11228, count = 20}
     },
     message = "The king thanks you.I'm on a research of the cause of mutation I need you to bring me",
     level = 40,
     rewarditems = {
       {id = 2160, count = 1},
        {id = 2476, count = 1},
         {id = 2477, count = 1}
     },
      [14] = {
     monsters = {
       {name = "Orc Berserkers", count = 50, storage = 21912},
       {name = "Orc Leaders", count = 30, storage = 21913},
       {name = "Orc Shamans", count = 50, storage = 21914},
       {name = "Orc Warlords", count = 15, storage = 21915}
     },
     message = "Thank you. The orcs are trying to do something, cut the head of them! kill ",
     level = 45,
     rewarditems = {
       {id = 8891, count = 1},
        {id = 11323, count = 1},
        {id = 2160, count = 2}
     },
     rewardexp = 140000
   },
   [15] = {
     items = {
       {id = 11222, count = 60},
       {id = 11339, count = 20}
     },
     message = "I need some materials to enchants an earth barrier bring me",
     level = 50,
     rewarditems = {
       {id = 2160, count = 2},
       {id = 7884, count = 1},
       {id = 7885, count = 1}
     },
     [16] = {
     monsters = {
       {name = "Bonebeasts", count = 150, storage = 21916}
     },
     message = "This will help. Some creatures are hunting merchants in the desert kill",
     level = 50,
     rewarditems = {
       {id = 5925, count = 45},
        {id = 2528, count = 1},
        {id = 2160, count = 3}
     },
     rewardexp = 180000
   },
   [17] = {
     items = {
       {id = 10548, count = 100}
     },
     message = "I need some materials for a powerful venom bring me",
     level = 50,
     rewarditems = {
       {id = 2160, count = 3},
        {id = 2524, count = 1}
     },
      [18] = {
     monsters = {
       {name = "Dragons", count = 70, storage = 21917}
     },
     message = "Great, dragon activity has risen putting in the danger the cities, kill ",
     level = 50,
     rewarditems = {
       {id = 7383, count = 1}
     },
     rewardexp = 220000
}
}

local storage = 45551
local function getItemsMonstersFromTable(imtable)
     local text = ""
     for v = 1, #imtable do
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #imtable then
             ret = " and "
         end
         text = text .. ret
         count = imtable[v].count
         if imtable[v].id then
             info = ItemType(imtable[v].id)
             text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
         else
             text = text .. count .." "..imtable[v].name
         end
     end
     return text
end
function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end
     local player = Player(cid)
     local x = missions[player:getStorageValue(storage)]
     if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
         if player:getStorageValue(storage) == -1 then
             selfSay("I have several missions for you, do you accept the challenge?", cid)
             npcHandler.topic[cid] = 1
         elseif x then
             if player:getLevel() >= x.level then
                 selfSay("Did you "..(x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)).."?", cid)
                 npcHandler.topic[cid] = 1
             else
                 selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
             end
         else
             selfSay("You already did all the missions, great job though.", cid)
             npcHandler:releaseFocus(cid)
         end
     elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(storage) == -1 then
             player:setStorageValue(storage, 1)
             local x = missions[player:getStorageValue(storage)]
             selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
         elseif x then
             local imtable = x.items or x.monsters
             local amount = 0
             for it = 1, #imtable do
                 local check = x.items and player:getItemCount(imtable[it].id) or player:getStorageValue(imtable[it].storage)
                 if check >= imtable[it].count then
                     amount = amount + 1
                 end
             end
             if amount == #imtable then
                 if x.items then
                     for it = 1, #x.items do
                         player:removeItem(x.items[it].id, x.items[it].count)
                     end
                 end
                 if x.rewarditems then
                     for r = 1, #x.rewarditems do
                         player:addItem(x.rewarditems[r].id, x.rewarditems[r].count)
                     end
                     player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
                 end
                 if x.rewardexp then
                     player:addExperience(x.rewardexp)
                     player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
                 end
                 player:setStorageValue(storage, player:getStorageValue(storage) + 1)
                 local x = missions[player:getStorageValue(storage)]
                 if x then
                     selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
                 else
                     selfSay("Well done! You did a great job on all your missions.", cid)
                 end
             else
                 local n = 0
                 for i = 1, #imtable do
                     local check = x.items and player:getItemCount(imtable[i].id) or player:getStorageValue(imtable[i].storage)
                     if check < imtable[i].count then
                         n = n + 1
                     end
                 end
                 local text = ""
                 local c = 0
                 for v = 1, #imtable do
                     local check = x.items and player:getItemCount(imtable[v].id) or player:getStorageValue(imtable[v].storage)
                     if check < imtable[v].count then
                         c = c + 1
                         local ret = ", "
                         if c == 1 then
                             ret = ""
                         elseif c == n then
                             ret = " and "
                         end
                         text = text .. ret
                         if x.items then
                             local count, info = imtable[v].count - player:getItemCount(imtable[v].id), ItemType(imtable[v].id)
                             text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
                         else
                             local count = imtable[v].count - (player:getStorageValue(imtable[v].storage) + 1)
                             text = text .. count.." "..imtable[v].name
                         end
                     end
                 end
                 selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill all monsters, you still need to kill "..text..".", cid)
             end
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
         selfSay("Oh well, I guess not then.", cid)
         npcHandler.topic[cid] = 0
     end
     return true
end
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
LUA:
-- Collecting items and monster missions by Limos
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 missions = {
   [1] = {
     items = {
       {id = 10609, count = 5},
       {id = 2230, count = 1},
       {id = 12437, count = 5}
     },
     message = "Great, for your first mission you need to collect some items, I need for a ritual",
     level = 7, -- minimum level voor...
LUA:
-- Collecting items and monster missions by Limos
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 missions = {
   [1] = {
     items = {
       {id = 10609, count = 5},
       {id = 2230, count = 1},
       {id = 12437, count = 5}
     },
     message = "Great, for your first mission you need to collect some items, I need for a ritual",
     level = 7, -- minimum level voor this mission
     rewarditems = {
       {id = 2152, count = 5}
     },
     rewardexp = 5000
   },
   [2] = {
     monsters = {
       {name = "Rotworms", count = 30, storage = 21900}
     },
     message = "Thanks, we have a problem in the city sewers for your next mission kill",
     level = 7,
     rewarditems = {
       {id = 5710, count = 5}
     },
     rewardexp = 10000
   },
   [3] = {
     items = {
       {id = 10569, count = 1},
       {id = 12400, count = 15},
       {id = 12399, count = 15}
     },
     message = "Awesome rookie, now get me from the amazon camp",
     level = 10,
     rewarditems = {
       {id = 2463, count = 1}
     },
     rewardexp = 170000
   },
   [4] = {
     monsters = {
       {name = "Minotaurs", count = 50, storage = 21901},
       {name = "Minotaur Archers", count = 25, storage = 21902},
       {name = "Minotaur Mages", count = 15, storage = 21903},
       {name = "Minotaur Guards", count = 15, storage = 21904}
     },
     message = "Good job, we are having problems in the outer camps near plains of havoc now kill",
     level = 15,
     rewarditems = {
       {id = 2152, count = 35}
     },
     rewardexp = 40000
   },
   [5] = {
     items = {
       {id = 10574, count = 45},
       {id = 7398, count = 1}
     },
     message = "Good, i need some items from the cyclops camp,",
     level = 20,
     rewarditems = {
       {id = 2486, count = 1}
     },
     rewardexp = 50000
      },
    [6] = {
     monsters = {
       {name = "Dwarf Soldiers", count = 50, storage = 21905},
       {name = "Dwarf Guards", count = 25, storage = 21906},
       {name = "Dwarf Geomancer", count = 5, storage = 21907}
     },
     message = "Good job, we are having problems with dwarf rebels in the mine now kill",
     level = 20,
     rewarditems = {
       {id = 5880, count = 20}
     },
     rewardexp = 65000
   },
   [7] = {
     items = {
       {id = 11198, count = 45},
       {id = 8859, count = 25}
     },
     message = "Excellent, i need some arachnids items for my research on the plague bring me",
     level = 20,
     rewarditems = {
       {id = 8872, count = 1}
     },
     },
     [8] = {
     monsters = {
       {name = "Dragons", count = 15, storage = 21908}
     },
     message = "Impressive those dwarfs will stay calm, you need a real challenge kill",
     level = 30,
     rewarditems = {
       {id = 2516, count = 1},
       {id = 2392, count = 1}
     },
     rewardexp = 80000
   },
    [9] = {
     items = {
       {id = 10566, count = 20},
       {id = 12422, count = 20},
       {id = 12423, count = 50},
       {id = 10564, count = 10},
       {id = 11200, count = 15},
       {id = 10602, count = 5}
     },
     message = "I'm amazed, ok i need some undead items for my ritual try not to die okay? Bring me",
     level = 30,
     rewarditems = {
       {id = 2656, count = 1}
     },
    },
     [10] = {
     monsters = {
       {name = "Blue Djinns", count = 40, storage = 21909},
       {name = "Green Djinns", count = 40, storage = 21910}
     },
     message = "Tension between the djinns are causing serious problems kill",
     level = 35,
     rewarditems = {
       {id = 7730, count = 1}
     },
     rewardexp = 90000
   },
   [11] = {
     items = {
       {id = 12413, count = 35},
       {id = 5877, count = 20},
       {id = 5920, count = 5}
     },
     message = "That would be it. Merchants are asking me for dragon products. Bring me",
     level = 40,
     rewarditems = {
       {id = 2160, count = 2}
     },
    },
     [12] = {
     monsters = {
       {name = "Necromancers", count = 150, storage = 21911}
     },
     message = "We have to erracticate Necromancers, they are kidnaping people for their rituals. Kill ",
     level = 40,
     rewarditems = {
       {id = 8922, count = 1},
        {id = 8910, count = 1}
     },
     rewardexp = 120000
   },
   [13] = {
     items = {
       {id = 11225, count = 50},
       {id = 10585, count = 25},
       {id = 10579, count = 20},
       {id = 11228, count = 20}
     },
     message = "The king thanks you.I'm on a research of the cause of mutation I need you to bring me",
     level = 40,
     rewarditems = {
       {id = 2160, count = 1},
        {id = 2476, count = 1},
         {id = 2477, count = 1}
     },
    },
      [14] = {
     monsters = {
       {name = "Orc Berserkers", count = 50, storage = 21912},
       {name = "Orc Leaders", count = 30, storage = 21913},
       {name = "Orc Shamans", count = 50, storage = 21914},
       {name = "Orc Warlords", count = 15, storage = 21915}
     },
     message = "Thank you. The orcs are trying to do something, cut the head of them! kill ",
     level = 45,
     rewarditems = {
       {id = 8891, count = 1},
        {id = 11323, count = 1},
        {id = 2160, count = 2}
     },
     rewardexp = 140000
   },
   [15] = {
     items = {
       {id = 11222, count = 60},
       {id = 11339, count = 20}
     },
     message = "I need some materials to enchants an earth barrier bring me",
     level = 50,
     rewarditems = {
       {id = 2160, count = 2},
       {id = 7884, count = 1},
       {id = 7885, count = 1}
     },
     },
     [16] = {
     monsters = {
       {name = "Bonebeasts", count = 150, storage = 21916}
     },
     message = "This will help. Some creatures are hunting merchants in the desert kill",
     level = 50,
     rewarditems = {
       {id = 5925, count = 45},
        {id = 2528, count = 1},
        {id = 2160, count = 3}
     },
     rewardexp = 180000
   },
   [17] = {
     items = {
       {id = 10548, count = 100}
     },
     message = "I need some materials for a powerful venom bring me",
     level = 50,
     rewarditems = {
       {id = 2160, count = 3},
        {id = 2524, count = 1}
     },
    },
      [18] = {
     monsters = {
       {name = "Dragons", count = 70, storage = 21917}
     },
     message = "Great, dragon activity has risen putting in the danger the cities, kill ",
     level = 50,
     rewarditems = {
       {id = 7383, count = 1}
     },
     rewardexp = 220000
}
}
local storage = 45551
local function getItemsMonstersFromTable(imtable)
     local text = ""
     for v = 1, #imtable do
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #imtable then
             ret = " and "
         end
         text = text .. ret
         count = imtable[v].count
         if imtable[v].id then
             info = ItemType(imtable[v].id)
             text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
         else
             text = text .. count .." "..imtable[v].name
         end
     end
     return text
end
function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end
     local player = Player(cid)
     local x = missions[player:getStorageValue(storage)]
     if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
         if player:getStorageValue(storage) == -1 then
             selfSay("I have several missions for you, do you accept the challenge?", cid)
             npcHandler.topic[cid] = 1
         elseif x then
             if player:getLevel() >= x.level then
                 selfSay("Did you "..(x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)).."?", cid)
                 npcHandler.topic[cid] = 1
             else
                 selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
             end
         else
             selfSay("You already did all the missions, great job though.", cid)
             npcHandler:releaseFocus(cid)
         end
     elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(storage) == -1 then
             player:setStorageValue(storage, 1)
             local x = missions[player:getStorageValue(storage)]
             selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
         elseif x then
             local imtable = x.items or x.monsters
             local amount = 0
             for it = 1, #imtable do
                 local check = x.items and player:getItemCount(imtable[it].id) or player:getStorageValue(imtable[it].storage)
                 if check >= imtable[it].count then
                     amount = amount + 1
                 end
             end
             if amount == #imtable then
                 if x.items then
                     for it = 1, #x.items do
                         player:removeItem(x.items[it].id, x.items[it].count)
                     end
                 end
                 if x.rewarditems then
                     for r = 1, #x.rewarditems do
                         player:addItem(x.rewarditems[r].id, x.rewarditems[r].count)
                     end
                     player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
                 end
                 if x.rewardexp then
                     player:addExperience(x.rewardexp)
                     player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
                 end
                 player:setStorageValue(storage, player:getStorageValue(storage) + 1)
                 local x = missions[player:getStorageValue(storage)]
                 if x then
                     selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
                 else
                     selfSay("Well done! You did a great job on all your missions.", cid)
                 end
             else
                 local n = 0
                 for i = 1, #imtable do
                     local check = x.items and player:getItemCount(imtable[i].id) or player:getStorageValue(imtable[i].storage)
                     if check < imtable[i].count then
                         n = n + 1
                     end
                 end
                 local text = ""
                 local c = 0
                 for v = 1, #imtable do
                     local check = x.items and player:getItemCount(imtable[v].id) or player:getStorageValue(imtable[v].storage)
                     if check < imtable[v].count then
                         c = c + 1
                         local ret = ", "
                         if c == 1 then
                             ret = ""
                         elseif c == n then
                             ret = " and "
                         end
                         text = text .. ret
                         if x.items then
                             local count, info = imtable[v].count - player:getItemCount(imtable[v].id), ItemType(imtable[v].id)
                             text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
                         else
                             local count = imtable[v].count - (player:getStorageValue(imtable[v].storage) + 1)
                             text = text .. count.." "..imtable[v].name
                         end
                     end
                 end
                 selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill all monsters, you still need to kill "..text..".", cid)
             end
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
         selfSay("Oh well, I guess not then.", cid)
         npcHandler.topic[cid] = 0
     end
     return true
end
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Not sure exactly, try this and post errors please.
 
Solution
Back
Top