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

Lua Npc questlog problem

Hokku

Member
Joined
Jul 25, 2013
Messages
95
Reaction score
18
Location
Extremadura, Spain
Hello! im getting a problem with a quest npc, when i finish a mission, the quest log removes the last mission, and only show the actually, its mean only 1 mission is displayed on the quest log, and i want to have all them, here is the npc and quest log, quest is fully working.
Using tfs 1.1 by Mark Samman.

Npc
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 = 13191, count = 1}
     },
     message = "We have sent one of our best soldiers to explore the cemetery because of the reports we have received lately, it seems that something is corrupting this sacred land, we have not had news in days, it is time to act, go and find him, he carries a",
     level = 15, -- minimum level voor this mission
     rewarditems = {
       {id = 2152, count = 40}
     },
     rewardexp = 4000
   },
   [2] = {
     monsters = {
       {name = "Witchs", count = 30, storage = 21900}
     },
     message = "It seems that the witches are involved and are the cause of this evil, you must cross through the catacombs of the cemetery to the south to find the witchs aquelarre, get in and slay",
     level = 17,
     rewarditems = {
       {id = 2152, count = 70}
     },
     rewardexp = 5000
   },
   [3] = {
     items = {
       {id = 12431, count = 5},
       {id = 11237, count = 10}
     },
     message = "Good job. We got new notices, it seems that near where our man died there is an altar of necromancy, we can not allow such acts in our domains, to take reprimands we must be sure, as proof bring me",
     level = 28,
     rewarditems = {
       {id = 2152, count = 200}
     },
     rewardexp = 8000
   },
   [4] = {
     monsters = {
       {name = "Dark Necromant", count = 1, storage = 21901}
     },
     message = "Good job. Its time for the divine wraith, get in again and kill her master the",
     level = 35,
     rewarditems = {
       {id = 5942, count = 1},
       {id = 2160, count = 2}
     },
     rewardexp = 10000
   },
   [5] = {
     items = {
       {id = 10602, count = 15},
       {id = 5905, count = 20}
     },
     message = "Good job! Hope he burned in the hell. Take this blessed wooden stake, you will need it. I got a report of Vampires in cementery undergrounds, bring me ",
     level = 40,
     rewarditems = {
       {id = 2160, count = 2}
     },
     rewardexp = 20000
   },
   [6] = {
     monsters = {
       {name = "Zevelon Duskbringer", count = 1, storage = 21902}
     },
     message = "Those devils needs a lesson. Its time to visit her master, slay ",
     level = 45,
     rewarditems = {
       {id = 2160, count = 4}
     },
     rewardexp = 32000
   },
   [7] = {
     items = {
       {id = 9663, count = 1}
     },
     message = "Those blood suckers have earned the lesson. I have another mission for you, but you must be careful. I need a document from the Warlocks Order, they are located at south-east of Venore Camp, in the Darkness Cave. Bring me ",
     level = 65,
     rewarditems = {
       {id = 8298, count = 3}
     },
     rewardexp = 55000
   },
   [8] = {
     items = {
       {id = 5906, count = 20}
     },
     message = "Magnificent! You are a truly hero, eh? I need something from Darkness Cave. Now for my experiments i need ",
     level = 75,
     rewarditems = {
       {id = 8298, count = 3},
       {id = 8310, count = 2},
       {id = 8299, count = 1}
     },
     rewardexp = 65000
   }
}

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("Im looking for an experienced adventurer. The Inquisiton order is always busy and I researched information that must probe. Are you interested in help? With economic compensation.", 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())

mission quest log

Code:
    <quest name="Black cats, bones and bats" startstorageid="45551" startstoragevalue="1">
                <mission name="The path of the faith" storageid="45551" startvalue="1" endvalue="2">
                <missionstate id="1" description="Explore the cementery and find the inquisition soldier."/>
                <missionstate id="2" description="You have found the Mission orders letter in the death body of the soldier."/>
        </mission>
                <mission name="The purge" storageid="45551" startvalue="2" endvalue="3">
                <missionstate id="2" description="Slay 30 witches in the aquelarre at south of the cemetery."/>
                <missionstate id="3" description="Killed 30 witchs in the aquelarre and reported to Soraya."/>
        </mission>
                <mission name="Blood rituals" storageid="45551" startvalue="3" endvalue="5">
                <missionstate id="3" description="Get 10 necromantic robes and 20 books of necromantic ritual from Necromancers and bring them to Soraya."/>
                <missionstate id="4" description="Kill the Master of necromancers, The Dark Necromant at Cementery undergrounds."/>
                <missionstate id="5" description="You have cleared the necromancers catacombs and defeated their boss, the dark necromancer."/>
        </mission>
                <mission name="Sacred office" storageid="45551" startvalue="5" endvalue="7">
                <missionstate id="5" description="Get 20 vampire tooth and 10 vampire dust and bring them to Soraya."/>
                <missionstate id="6" description="Kill the Master of the vampires, Zevelon Duskbringer at Cementery undergrounds."/>
                <missionstate id="7" description="You have slained the vampire master Zevelon and his minions on the cemetery catacombs."/>
        </mission>
                <mission name="Knowledge preservation" storageid="45551" startvalue="7" endvalue="8">
                <missionstate id="7" description="Retrive an old document from Warlocks at Darkness Cave, at south east of Swamplands Camp."/>
                <missionstate id="8" description="The old document is now safe in the inquisition hands."/>
        </mission>
                <mission name="Demonic curses" storageid="45551" startvalue="8" endvalue="9">
                <missionstate id="8" description="Get 20 demon dusts and bring them to Soraya."/>
                <missionstate id="9" description="You completed all Soraya missions. Now you can access to the enchanting shop."/>
        </mission>
    </quest>
 
I guess storage should be the same. Your mission Ids seems to collide.
Try like this.

Lua:
<quest name="Black cats, bones and bats" startstorageid="45551" startstoragevalue="1">
                <mission name="The path of the faith" storageid="45551" startvalue="1" endvalue="2">
                <missionstate id="1" description="Explore the cementery and find the inquisition soldier."/>
                <missionstate id="2" description="You have found the Mission orders letter in the death body of the soldier."/>
        </mission>
                <mission name="The purge" storageid="45551" startvalue="3" endvalue="4">
                <missionstate id="3" description="Slay 30 witches in the aquelarre at south of the cemetery."/>
                <missionstate id="4" description="Killed 30 witchs in the aquelarre and reported to Soraya."/>
        </mission>
                <mission name="Blood rituals" storageid="45551" startvalue="5" endvalue="7">
                <missionstate id="5" description="Get 10 necromantic robes and 20 books of necromantic ritual from Necromancers and bring them to Soraya."/>
                <missionstate id="6" description="Kill the Master of necromancers, The Dark Necromant at Cementery undergrounds."/>
                <missionstate id="7" description="You have cleared the necromancers catacombs and defeated their boss, the dark necromancer."/>
        </mission>
                <mission name="Sacred office" storageid="45551" startvalue="8" endvalue="10">
                <missionstate id="8" description="Get 20 vampire tooth and 10 vampire dust and bring them to Soraya."/>
                <missionstate id="9" description="Kill the Master of the vampires, Zevelon Duskbringer at Cementery undergrounds."/>
                <missionstate id="10" description="You have slained the vampire master Zevelon and his minions on the cemetery catacombs."/>
        </mission>
                <mission name="Knowledge preservation" storageid="45551" startvalue="11" endvalue="12">
                <missionstate id="11" description="Retrive an old document from Warlocks at Darkness Cave, at south east of Swamplands Camp."/>
                <missionstate id="12" description="The old document is now safe in the inquisition hands."/>
        </mission>
                <mission name="Demonic curses" storageid="45551" startvalue="13" endvalue="14">
                <missionstate id="13" description="Get 20 demon dusts and bring them to Soraya."/>
                <missionstate id="14" description="You completed all Soraya missions. Now you can access to the enchanting shop."/>
        </mission>
    </quest>
 
I guess storage should be the same. Your mission Ids seems to collide.
Try like this.

Lua:
<quest name="Black cats, bones and bats" startstorageid="45551" startstoragevalue="1">
                <mission name="The path of the faith" storageid="45551" startvalue="1" endvalue="2">
                <missionstate id="1" description="Explore the cementery and find the inquisition soldier."/>
                <missionstate id="2" description="You have found the Mission orders letter in the death body of the soldier."/>
        </mission>
                <mission name="The purge" storageid="45551" startvalue="3" endvalue="4">
                <missionstate id="3" description="Slay 30 witches in the aquelarre at south of the cemetery."/>
                <missionstate id="4" description="Killed 30 witchs in the aquelarre and reported to Soraya."/>
        </mission>
                <mission name="Blood rituals" storageid="45551" startvalue="5" endvalue="7">
                <missionstate id="5" description="Get 10 necromantic robes and 20 books of necromantic ritual from Necromancers and bring them to Soraya."/>
                <missionstate id="6" description="Kill the Master of necromancers, The Dark Necromant at Cementery undergrounds."/>
                <missionstate id="7" description="You have cleared the necromancers catacombs and defeated their boss, the dark necromancer."/>
        </mission>
                <mission name="Sacred office" storageid="45551" startvalue="8" endvalue="10">
                <missionstate id="8" description="Get 20 vampire tooth and 10 vampire dust and bring them to Soraya."/>
                <missionstate id="9" description="Kill the Master of the vampires, Zevelon Duskbringer at Cementery undergrounds."/>
                <missionstate id="10" description="You have slained the vampire master Zevelon and his minions on the cemetery catacombs."/>
        </mission>
                <mission name="Knowledge preservation" storageid="45551" startvalue="11" endvalue="12">
                <missionstate id="11" description="Retrive an old document from Warlocks at Darkness Cave, at south east of Swamplands Camp."/>
                <missionstate id="12" description="The old document is now safe in the inquisition hands."/>
        </mission>
                <mission name="Demonic curses" storageid="45551" startvalue="13" endvalue="14">
                <missionstate id="13" description="Get 20 demon dusts and bring them to Soraya."/>
                <missionstate id="14" description="You completed all Soraya missions. Now you can access to the enchanting shop."/>
        </mission>
    </quest>
using this way made me the quest end at stateid 9 on Sacred office mission, seems a npc problem.
 
using this way made me the quest end at stateid 9 on Sacred office mission, seems a npc problem.

That's because your missions table ends up on 8.


Lua:
local missions = {
   [1] = {
     items = {
       {id = 13191, count = 1}
     },
     message = "We have sent one of our best soldiers to explore the cemetery because of the reports we have received lately, it seems that something is corrupting this sacred land, we have not had news in days, it is time to act, go and find him, he carries a",
     level = 15, -- minimum level voor this mission
     rewarditems = {
       {id = 2152, count = 40}
     },
     rewardexp = 4000
   },
   [2] = {
     monsters = {
       {name = "Witchs", count = 30, storage = 21900}
     },
     message = "It seems that the witches are involved and are the cause of this evil, you must cross through the catacombs of the cemetery to the south to find the witchs aquelarre, get in and slay",
     level = 17,
     rewarditems = {
       {id = 2152, count = 70}
     },
     rewardexp = 5000
   },
   [3] = {
     items = {
       {id = 12431, count = 5},
       {id = 11237, count = 10}
     },
     message = "Good job. We got new notices, it seems that near where our man died there is an altar of necromancy, we can not allow such acts in our domains, to take reprimands we must be sure, as proof bring me",
     level = 28,
     rewarditems = {
       {id = 2152, count = 200}
     },
     rewardexp = 8000
   },
   [4] = {
     monsters = {
       {name = "Dark Necromant", count = 1, storage = 21901}
     },
     message = "Good job. Its time for the divine wraith, get in again and kill her master the",
     level = 35,
     rewarditems = {
       {id = 5942, count = 1},
       {id = 2160, count = 2}
     },
     rewardexp = 10000
   },
   [5] = {
     items = {
       {id = 10602, count = 15},
       {id = 5905, count = 20}
     },
     message = "Good job! Hope he burned in the hell. Take this blessed wooden stake, you will need it. I got a report of Vampires in cementery undergrounds, bring me ",
     level = 40,
     rewarditems = {
       {id = 2160, count = 2}
     },
     rewardexp = 20000
   },
   [6] = {
     monsters = {
       {name = "Zevelon Duskbringer", count = 1, storage = 21902}
     },
     message = "Those devils needs a lesson. Its time to visit her master, slay ",
     level = 45,
     rewarditems = {
       {id = 2160, count = 4}
     },
     rewardexp = 32000
   },
   [7] = {
     items = {
       {id = 9663, count = 1}
     },
     message = "Those blood suckers have earned the lesson. I have another mission for you, but you must be careful. I need a document from the Warlocks Order, they are located at south-east of Venore Camp, in the Darkness Cave. Bring me ",
     level = 65,
     rewarditems = {
       {id = 8298, count = 3}
     },
     rewardexp = 55000
   },
   [8] = {
     items = {
       {id = 5906, count = 20}
     },
     message = "Magnificent! You are a truly hero, eh? I need something from Darkness Cave. Now for my experiments i need ",
     level = 75,
     rewarditems = {
       {id = 8298, count = 3},
       {id = 8310, count = 2},
       {id = 8299, count = 1}
     },
     rewardexp = 65000
   }
}
 
Back
Top