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

C++ Mission script wont count monster storage

Batalj

Member
Joined
May 26, 2017
Messages
51
Solutions
1
Reaction score
13
Hello there everyone! I have rush into a problem concerning a script I am suppose to use as a starter questline on my server. The thing I want help with is that monster count doesnt work, I have tried everything but when I ask the npc he still says I have the same amount of monsters left to kill even tho I killed them all. I think it has something to do with the monster storage and have tried to add scripts into creaturescripts but cant get it to work properly. No error messeges shown aswell in the console. Is it that I have to change in the 051-storages.lua in the lib file?

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 = 2350, count = 1}
     },
     message = "Great, a city guard may have more information of the first item which is",
     level = 0, -- minimum level voor this mission
     rewarditems = {
       {id = 2406, count = 1},
       {id = 2050, count = 1}
     },
     rewardexp = 50
   },
   [2] = {
     monsters = {
       {name = "Rats", count = 20, storage = 21900},
       {name = "Cave Rats", count = 5, storage = 21901}     
     },
     message = "Thanks, for your next mission kill",
     level = 0,
     rewarditems = {
       {id = 2160, count = 5}
     },
     rewardexp = 40000
   },
   [3] = {
     items = {
       {id = 5920, count = 45},
       {id = 5877, count = 22}
     },
     message = "Awesome, now get",
     level = 50,
     rewarditems = {
       {id = 2160, count = 15}
     },
     rewardexp = 100000
   },
   [4] = {
     monsters = {
       {name = "Dragon Lords", count = 25, storage = 21902}
     },
     message = "Good job, now kill",
     level = 70,
     rewarditems = {
       {id = 2160, count = 25}
     },
     rewardexp = 200000
   },
   [5] = {
     items = {
       {id = 5906, count = 35},
       {id = 5882, count = 42},
       {id = 4850, count = 1}
     },
     message = "Good, now your final mission, there are a few more items you need to get,",
     level = 100,
     rewarditems = {
       {id = 2160, count = 50}
     },
     rewardexp = 450000
   }
}
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
Here is the code, it does however not send out any orange text messege either on kill which it should according to this script?

Lua:
local config = {
     ['rat'] = {amount = 10, storage = 21900, startstorage = 45551, startvalue = 1},
     ['minotaur'] = {amount = 10, storage = 21901, startstorage = 45551, 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)...
Is this Limos script?
Check that thread again.
There should be an onKill script you need to install
 
The only problem I have right now is that I have to kill 6 minotaurs instead of 5 since the npc otherwise says that you still have 0 minotaurs to kill. How to fix this problem?


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 = 2350, count = 1}
     },
     message = "Great, a city guard may have more information of the first item which is",
     level = 0, -- minimum level for this mission
     rewarditems = {
       {id = 2406, count = 1},
       {id = 2512, count = 1}
     },
     rewardexp = 50
   },
   [2] = {
     monsters = {
       {name = "Rats", count = 10, storage = 21900}
     },
     message = "Thanks, for your next mission kill",
     level = 0,
     rewarditems = {
       {id = 2485, count = 1}
     },
     rewardexp = 100
   },
   [3] = {
     items = {
       {id = 11113, count = 1}
     },
     message = "Awesome, now get",
     level = 0,
     rewarditems = {
       {id = 1988, count = 1},
       {id = 2050, count = 3},
       {id = 2120, count = 1}    
     },
     rewardexp = 200
   },
   [4] = {
     monsters = {
       {name = "Minotaur", count = 5, storage = 21901}
     },
     message = "Good job, now kill",
     level = 5,
     rewarditems = {
       {id = 7618, count = 3}
     },
     rewardexp = 400
   },
   [5] = {
     items = {
       {id = 5878, count = 1},
       {id = 12435, count = 1},
       {id = 10606, count = 1}
     },
     message = "Good, now your final mission, there are a few more items you need to get,",
     level = 6,
     rewarditems = {
       {id = 2152, count = 5}
     },
     rewardexp = 800
   }
}
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())
 
Last edited:
Try this:

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 = 2350, count = 1}
     },
     message = "Great, a city guard may have more information of the first item which is",
     level = 0, -- minimum level for this mission
     rewarditems = {
       {id = 2406, count = 1},
       {id = 2512, count = 1}
     },
     rewardexp = 50
   },
   [2] = {
     monsters = {
       {name = "Rats", count = 10, storage = 21900}
     },
     message = "Thanks, for your next mission kill",
     level = 0,
     rewarditems = {
       {id = 2485, count = 1}
     },
     rewardexp = 100
   },
   [3] = {
     items = {
       {id = 11113, count = 1}
     },
     message = "Awesome, now get",
     level = 0,
     rewarditems = {
       {id = 1988, count = 1},
       {id = 2050, count = 3},
       {id = 2120, count = 1}   
     },
     rewardexp = 200
   },
   [4] = {
     monsters = {
       {name = "Minotaur", count = 5, storage = 21901}
     },
     message = "Good job, now kill",
     level = 5,
     rewarditems = {
       {id = 7618, count = 3}
     },
     rewardexp = 400
   },
   [5] = {
     items = {
       {id = 5878, count = 1},
       {id = 12435, count = 1},
       {id = 10606, count = 1}
     },
     message = "Good, now your final mission, there are a few more items you need to get,",
     level = 6,
     rewarditems = {
       {id = 2152, count = 5}
     },
     rewardexp = 800
   }
}
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)
    player:save()
     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())
 
Here is the code, it does however not send out any orange text messege either on kill which it should according to this script?

Lua:
local config = {
     ['rat'] = {amount = 10, storage = 21900, startstorage = 45551, startvalue = 1},
     ['minotaur'] = {amount = 10, storage = 21901, startstorage = 45551, 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
 
Here is the code, it does however not send out any orange text messege either on kill which it should according to this script?

Lua:
local config = {
     ['rat'] = {amount = 10, storage = 21900, startstorage = 45551, startvalue = 1},
     ['minotaur'] = {amount = 10, storage = 21901, startstorage = 45551, 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:
local config = {
     ['rat'] = {amount = 10, storage = 21900, startstorage = 45551, startvalue = 1},
     ['minotaur'] = {amount = 10, storage = 21901, startstorage = 45551, 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)
     stor = stor == -1 and 1 or stor + 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 ..' of '..monster.amount..' '..target:getName()..'s killed.')
     end
     if stor == monster.amount then
         player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '.. stor ..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
         player:setStorageValue(monster.storage, stor)
     end
     return true
end
 
Solution
Sadly I just tested it again, and the npc still says you still need to kill 0 Minotaur.
jN8kZmn.png
...
 
are you sure this is the same npc for the script you posted? there is no text that is identical to the script you posted
 
Looking through the code, I can't find the issue.

This won't solve the issue, but might give us some insight into what's happening.

line 119-126
Lua:
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
Can you change to this..
Lua:
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)
   selfSay("check == " .. check ..", count == " .. imtable[it].count .. "", cid)
   if check >= imtable[it].count then
       amount = amount + 1
   end
end
selfSay("amount == " .. amount .. ", imtable == " .. #imtable .. "", cid)

Then do this
-> start quest
-> kill the set amount of minotaurs until you receive the message stating "Congratulations, you have killed ........."
-> talk to npc and try to turn in the quest.

Send a small screenshot of each step that you've done, and also post the current scripts your using. (npc + onKill)
 
Try this guy out for size if you like.

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
--Can use items, monster, reward_items, exp, and level_req as keys in table.
local missions = {
    [1] = {
    --items = {[1] = {itemid = 1111, amount = 5}, [2] = {itemid = 1111, amount = 3}}, items and monsters can be added to same mission.--
    monsters = {[1] = {name = "Rat", amount = 5, storage = 21900}}, -- Multiple monsters
    reward_items = {[1] = {itemid 2160, amount = 1}}, --Multiple item rewards
    exp = 100, --Exp reward
    level_req = 10, --Level required for mission
    msg = "Go kill 5 rats." --Msg of Mission
    },
    [2] = {
    --items = {[1] = {itemid = 1111, amount = 5}, [2] = {itemid = 1111, amount = 3}}, items and monsters can be added to same mission.--
    monsters = {[1] = {name = "Minotaur", amount = 5, storage = 21901}}, -- Multiple monsters
    reward_items = {[1] = {itemid 2160, amount = 1}}, --Multiple item rewards
    exp = 100, --Exp reward
    level_req = 10, --Level required for mission
    msg = "Go kill 5 Minotaurs." --Msg of Mission
    }
}
local storage = 45000
function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end
     local player = Player(cid)
     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)
        else
            MISSION = missions[player:getStorageValue(storage)]
            if MISSION then
            local hasItems = false
            local hasKills = false
                if MISSION.items then
                    for i = 1, #MISSION.items do
                        if player:getItemCount(MISSION.items[i].itemid) >= MISSION.items[i].amount then
                            hasItems = true
                        else
                            hasItems = false
                            break
                        end
                    end
                end
           
                if MISSION.monsters then
                    for i = 1, #MISSION.monsters do
                        if player:getStorageValue(MISSION.monsters[i].storage) == MISSION.monsters[i].amount then
                            hasKills = true
                        else
                            hasKills = false
                            break
                        end
                    end
                end
           
                if MISSION.items and not hasItems or MISSION.monsters and not hasKills then
                    selfSay(MISSION.msg, cid)
                    return false
                end
           
                if MISSION.monsters do
                    for i = 1, #MISSION.monsters do
                        player:setStorageValue(MISSION.monsters[i].storage, -1)
                    end
                end
           
                player:setStorageValue(storage, player:getStorageValue(storage) + 1)
                if MISSION.reward_items then
                    for i = 1, #MISSION.reward_items do
                        player:addItem(MISSION.reward_items[i].itemid, MISSION.reward_items[i].amount)
                    end
                end
                if MISSION.exp then
                    player:addExperience(MISSION.exp)
                end
           
                MISSION = missions[player:getStorageValue(storage)]
           
                if MISSION then
           
                if player:getLevel() < MISSION.level_req then
                    selfSay("You must reach level "..MISSION.level_req.." for my next mission.")
                    return false
                end
       
                if MISSION.monsters then
                    for i = 1, #MISSION.monsters do
                        player:setStorageValue(MISSION.monsters[i].storage, 0)
                    end
                end
           
                    selfSay(MISSION.msg, cid)
           
                else
           
                    selfSay("I have no missions left for you.", cid)
                end
           
        end
        end
    end
 
    elseif msgcontains(msg, 'yes') and player:getStorageValue(storage) == -1 then
        local MISSION = missions[1]
            if player:getLevel() < MISSION.level_req then
                selfSay("You must be level "..MISSION.level_req.." to start my missions.")
            return false
            end
       
            if MISSION.monsters then
                for i = 1, #MISSION.monsters do
                    player:setStorageValue(MISSION.monsters[i].storage, 0)
                end
            end
        player:setStorageValue(storage, 1)
        selfSay(MISSION.msg, cid)
     elseif msgcontains(msg, 'no') and player:getStorageValue(storage) == -1 then
         selfSay("Oh well, I guess not then.", cid)
     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())

and use this onKill event
Lua:
local config = {
     ['rat'] = {amount = 10, storage = 21900},
     ['minotaur'] = {amount = 10, storage = 21901}
}
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)
     if stor ~= -1 and stor < monster.amount and stor ~= monster.amount - 1 then
         player:setStorageValue(monster.storage, player:getStorageValue(monster.storage) + 1)
        local newStor = player:getStorageValue(monster.storage)
         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: ['.. newStor ..'/'..monster.amount..'] '..target:getName()..'(s) killed.')
     else stor == monster.amount - 1 then
        player:setStorageValue(monster.storage, player:getStorageValue(monster.storage) + 1)
        local newStor = player:getStorageValue(monster.storage)
         player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed ['.. newStor ..'/ '..monster.amount..'] '..target:getName()..'(s).')
         player:setStorageValue(monster.storage, player:getStorageValue(monster.storage) + 1)
     end
     return true
end
 
Last edited:
As I see it now it has to do with the creaturescript, changed only the creaturescript and it changed to start from 18 rats to just not count at all.. Here is the scripts:

Lua:
local config = {
     ['rat'] = {amount = 20, storage = 21900, startstorage = 45552, startvalue = 1},
     ['cave rat'] = {amount = 10, storage = 21901, startstorage = 45552, 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)
     stor = stor == -1 and 1 or stor + 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 ..' of '..monster.amount..' '..target:getName()..'s killed.')
     end
     if stor == monster.amount then
         player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '.. stor ..' '..target:getName()..' and completed the '..target:getName()..' mission.')
         player:setStorageValue(monster.storage, stor)
     end
     return true
end

Npc script:

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 = 1987, count = 1}
     },
     message = "I see that you dont have a real bag yet! Go talk to Guard Theon in the city for clues how to get a",
     level = 2, -- minimum level for this mission
     rewarditems = {
       {id = 1988, count = 1}
     },
     rewardexp = 100
   },
   [2] = {
     monsters = {
       {name = "Rat", count = 20, storage = 21900} 
     },
     message = "I see that you have potential to be a great adventurer and therefore I will give you a real backpack instead. Now you need to start gain experience, an easy way to do that is to start kill monsters, hunt down",
     level = 3,
     rewarditems = {
       {id = 2120, count = 1}
     },
     rewardexp = 160
   },
   [3] = {
     items = {
       {id = 10576, count = 1}
     },
     message = "That went smooth, great! Now you need to get me an item of a little higher value, go kill the fat cave rat and bring me its",
     level = 5,
     rewarditems = {
       {id = 7618, count = 1},
       {id = 2050, count = 1}      
     },
     rewardexp = 320
   },
   [4] = {
     monsters = {
       {name = "Cave Rat", count = 10, storage = 21901}
     },
     message = "Discusting but a good piece for my researches! Next mission is to continue the hunt, kill ",
     level = 6,
     rewarditems = {
       {id = 2554, count = 1}
     },
     rewardexp = 640
   },
   [5] = {
     items = {
       {id = 3976, count = 50},
       {id = 2148, count = 50}
     },
     message = "Good, you still miss a few armor pieces. Now your final mission, there are a few more items you need to get,",
     level = 7,
     rewarditems = {
       {id = 1988, count = 1},
       {id = 2553, count = 1}
     },
     rewardexp = 1280
   }
}
local storage = 45552
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 do have some missions for you, do you want to start right away?", cid)
             npcHandler.topic[cid] = 1
         elseif x then
             if player:getLevel() >= x.level then
                 selfSay("Did you "..(x.items and "get me "..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).."s.")
                 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).."s.", cid)
                 else
                     selfSay("Well done! You did a great job on all your missions, now you are ready to start the real hunt! Head down to the prison and find Khadgar for more 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 bring "..text.."." or "You didn't kill all monsters, you still need to kill "..text.."s.", 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())
 
Back
Top