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

Teleport/Reward npc based on one word container

Lopaskurwa

Well-Known Member
Joined
Oct 6, 2017
Messages
936
Solutions
2
Reaction score
57
Hello
so im using quest npc and im wondering is it possible to delete all unnecessary words and make it work on one word container. Basically i mean this npc has words like "mission/quest" and "teleport" if you died once in that quest it makes you repeat your quest again. So my question is, is it possible to make everything on one word? So if its your first time on this quest it works like always (hi, mission, yes) but if you died in this mission and you want to repeat this quest you talk with this npc it should be on same word (hi, mission, yes) instead of (teleport).
LUA:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Karin" script="KarinQuest.lua" walkinterval="2000" walkradius="0" floorchange="0">
     <health now="100" max="100"/>
     <look type="572" head="59" body="132" legs="0" feet="57" addons="0"/>
     <parameters>
         <parameter key="message_greet" value="Hello |PLAYERNAME|, I'am giving mission for those who are intrested in my rare potions, take your {mission} now, and if you already took your mission {teleport} to there."/>
     </parameters>
</npc>
LUA:
-- Collecting items and monster missions by Carcoo
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] = {
     monsters = {
       {name = "The Great Rat", count = 1, storage = 84735},
     },
     message = "Ohh, Good luck with the boss !",
     level = 50,
     rewarditems = {
       {id = 12779, count = 50}
     },
     rewardexp = 95500000
   },
}

local storage = 42351

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 great mission 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 the mission, 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)
             player:teleportTo(Position(479, 642, 7))
             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 your mission.", 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 the boss, 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
     elseif msgcontains(msg, 'teleport') then
        local x = missions[player:getStorageValue(storage)]
         if x then
            player:teleportTo(Position(479, 642, 7))
            selfSay("Good luck this time!.", cid)
            npcHandler:releaseFocus(cid)
            else
            selfSay("You already done the mission or you didn't start it yet!.", cid)
           
     end
     return true
end
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
X
LUA:
-- Collecting items and monster missions by Carcoo
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] = {
     monsters = {
       {name = "The Great Rat", count = 1, storage = 84735},
     },
     message = "Ohh, Good luck with the boss !",
     level = 50,
     rewarditems = {
       {id = 12779, count = 50}
     },
     rewardexp = 95500000
   },
}...
Code:
P: Hi
N: Hi
P: mission
N: want to start mission?
P: yes
N: Okay, do this. (and teleports players)

P: Hi
N: Hi
P: mission
N: Have you completed mission?
P: yes
N: Okay, here's reward. / sorry mission not completed.

There's no room to work around your quest unless you do something janky like

Code:
P: Hi
N: Hi
P: mission
N: Have you completed mission, or if you haven't completed the mission, would you like to teleport?
P: yes
N: Okay, here's reward. / teleport player

If you want that..
add this between line 140/141
Code:
player:teleportTo(Position(479, 642, 7))
and edit line 63 with the double option for 1 answer.
 
Code:
P: Hi
N: Hi
P: mission
N: want to start mission?
P: yes
N: Okay, do this. (and teleports players)

P: Hi
N: Hi
P: mission
N: Have you completed mission?
P: yes
N: Okay, here's reward. / sorry mission not completed.

There's no room to work around your quest unless you do something janky like

Code:
P: Hi
N: Hi
P: mission
N: Have you completed mission, or if you haven't completed the mission, would you like to teleport?
P: yes
N: Okay, here's reward. / teleport player

If you want that..
add this between line 140/141
Code:
player:teleportTo(Position(479, 642, 7))
and edit line 63 with the double option for 1 answer.
Pretty close to perfection what i need but it teleports even when you kill that monster it should lock teleportation when you kill that specific monster.

Right, and its fine when you die because its same.
Code:
P- Hi
N - Hello Player, I'am giving mission for those who are intrested in my rare potions, take your "mission" now
P - Mission
N - I have great mission for you, do you accept the challenge?
P - yes
N - (Teleports)

Now if you kill that monster and you go to take your reward.
Code:
P - Hi
N - Hello Player, I'am giving mission for those who are intrested in my rare potions, take your "mission" now
P - Mission
N - Did you kill 1 The Great Rat?
P - yes
N - (Gives you reward) and teleports you, but it shouldnt teleport you.
 
Pretty close to perfection what i need but it teleports even when you kill that monster it should lock teleportation when you kill that specific monster.

Right, and its fine when you die because its same.
Code:
P- Hi
N - Hello Player, I'am giving mission for those who are intrested in my rare potions, take your "mission" now
P - Mission
N - I have great mission for you, do you accept the challenge?
P - yes
N - (Teleports)

Now if you kill that monster and you go to take your reward.
Code:
P - Hi
N - Hello Player, I'am giving mission for those who are intrested in my rare potions, take your "mission" now
P - Mission
N - Did you kill 1 The Great Rat?
P - yes
N - (Gives you reward) and teleports you, but it shouldnt teleport you.
post the current script after your modifications.
 
post the current script after your modifications.
LUA:
-- Collecting items and monster missions by Carcoo
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] = {
     monsters = {
       {name = "The Great Rat", count = 1, storage = 84735},
     },
     message = "Ohh, Good luck with the boss !",
     level = 50,
     rewarditems = {
       {id = 12779, count = 50}
     },
     rewardexp = 95500000
   },
}

local storage = 42351

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 great mission 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 the mission, 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)
             player:teleportTo(Position(479, 642, 7))
             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 your mission.", 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 the boss, you still need to kill "..text..".", cid)
             end
         player:teleportTo(Position(479, 642, 7))
         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
     elseif msgcontains(msg, 'teleport') then
        local x = missions[player:getStorageValue(storage)]
         if x then
            player:teleportTo(Position(479, 642, 7))
            selfSay("Good luck this time!.", cid)
            npcHandler:releaseFocus(cid)
            else
            selfSay("You already done the mission or you didn't start it yet!.", cid)
          
     end
     return true
end
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())
Edited line 142.
 
LUA:
-- Collecting items and monster missions by Carcoo
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] = {
     monsters = {
       {name = "The Great Rat", count = 1, storage = 84735},
     },
     message = "Ohh, Good luck with the boss !",
     level = 50,
     rewarditems = {
       {id = 12779, count = 50}
     },
     rewardexp = 95500000
   },
}

local storage = 42351

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 great mission 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 the mission, 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)
             player:teleportTo(Position(479, 642, 7))
             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 your mission.", 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 the boss, you still need to kill "..text..".", cid)
             end
         player:teleportTo(Position(479, 642, 7))
         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
     elseif msgcontains(msg, 'teleport') then
        local x = missions[player:getStorageValue(storage)]
         if x then
            player:teleportTo(Position(479, 642, 7))
            selfSay("Good luck this time!.", cid)
            npcHandler:releaseFocus(cid)
            else
            selfSay("You already done the mission or you didn't start it yet!.", cid)
        
     end
     return true
end
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())
Edited line 142.
You were supposed to put that line between lines 140 and 141. xP
-- edit I realise now that there was extra spacing at the top, so you actually put it where I had said to put it. Not your fault. lol

try this
LUA:
-- Collecting items and monster missions by Carcoo
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] = {
        monsters = {
            {name = "The Great Rat", count = 1, storage = 84735},
        },
        message = "Ohh, Good luck with the boss !",
        level = 50,
        rewarditems = {
            {id = 12779, count = 50}
        },
        rewardexp = 95500000
    },
}

local storage = 42351

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 great mission 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 the mission, 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)
            player:teleportTo(Position(479, 642, 7))
            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 your mission.", 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
                player:teleportTo(Position(479, 642, 7))
                selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill the boss, 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
    elseif msgcontains(msg, 'teleport') then
        local x = missions[player:getStorageValue(storage)]
        if x then
            player:teleportTo(Position(479, 642, 7))
            selfSay("Good luck this time!.", cid)
            npcHandler:releaseFocus(cid)
        else
            selfSay("You already done the mission or you didn't start it yet!.", cid)
      
        end
    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
You were supposed to put that line between lines 140 and 141. xP
-- edit I realise now that there was extra spacing at the top, so you actually put it where I had said to put it. Not your fault. lol

try this
LUA:
-- Collecting items and monster missions by Carcoo
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] = {
        monsters = {
            {name = "The Great Rat", count = 1, storage = 84735},
        },
        message = "Ohh, Good luck with the boss !",
        level = 50,
        rewarditems = {
            {id = 12779, count = 50}
        },
        rewardexp = 95500000
    },
}

local storage = 42351

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 great mission 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 the mission, 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)
            player:teleportTo(Position(479, 642, 7))
            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 your mission.", 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
                player:teleportTo(Position(479, 642, 7))
                selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill the boss, 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
    elseif msgcontains(msg, 'teleport') then
        local x = missions[player:getStorageValue(storage)]
        if x then
            player:teleportTo(Position(479, 642, 7))
            selfSay("Good luck this time!.", cid)
            npcHandler:releaseFocus(cid)
        else
            selfSay("You already done the mission or you didn't start it yet!.", cid)
     
        end
    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())
Perfection (y)
 
Back
Top