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

Solved [TFS 1.2] Daily reset Task NPC is not resetting storage.

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to alter Limos' Monster Task System to incorporate a daily resets using os.time().
The x.storage is being set to the correct Unix epoch time. I still need the npc to check for the x.storage & if x.storage is => os.time() + 86400 then player:setStorageValue(x.storage, -1).

Something like this, I suppose. Not 100% as to how to apply this.
Code:
for k, x in pairs(monsters) do
       if player:getStorageValue(x.storage) >= os.time() then
             player:setStorageValue(x.storage, -1)
else
       npcHandler:say("Come back later..", cid)
end

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
-- os.time() + 86400

local monsters = {
   ["Rotworms"] = {storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, os.time() + 86400)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
Solution
It kind of depens how you want it to work exactly, for seperate time storages for each monster mission you can do it like this.
Code:
for k, x in pairs(monsters) do
     if player:getStorageValue(x.exstorage) ~= -1 and player:getStorageValue(x.exstorage) < os.time() then -- If the 24 hours have passed
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
     end
end

player:setStorageValue(x.exstorage, os.time() + 24*60*60)
Then add exstorage in the monster mission tables, for example: exstorage = 6010.


[*mod edit] Solution (appended from below post):
Lua:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)...
Any help at all? I have been going in circles trying to get this to work.

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
-- os.time() + 86400
--if player:getStorageValue(x.storage) >= os.time() then

local monsters = {
   ["Rotworms"] = {storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                         else if player:getStorageValue(x.storage) >= os.time() then
                            for k, x in pairs(monsters) do
                                player:setStorageValue(x.storage, -1)
                                player:setStorageValue(x.mstorage, -1)
                            end
                        end
                    end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, os.time() + 86400)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
You can do something like this.
Code:
-- At the top under local player
if player:getStorageValue(exstorage) < os.time() then -- If the 24 hours have passed
     player:setStorageValue(setstorage, -1)
     for k, x in pairs(monsters) do
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
     end
end


-- Then where the npc gives the mission
if player:getStorageValue(setstorage) ~= 1 then
     player:setStorageValue(setstorage, 1) -- You can use an extra storage so it will only set it 1x and not again after another mission, if it should be 24 hours after any mission you can remove that setstorage part
     player:setStorageValue(exstorage, os.time() + 24*60*60) -- os.time() + 24 hours, so after 24 hours os.time() will be higher than the player storagevalue
end
-- Don't forget to define the storage variables
 
You can do something like this.
Code:
-- At the top under local player
if player:getStorageValue(exstorage) < os.time() then -- If the 24 hours have passed
     player:setStorageValue(setstorage, -1)
     for k, x in pairs(monsters) do
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
     end
end


-- Then where the npc gives the mission
if player:getStorageValue(setstorage) ~= 1 then
     player:setStorageValue(setstorage, 1) -- You can use an extra storage so it will only set it 1x and not again after another mission, if it should be 24 hours after any mission you can remove that setstorage part
     player:setStorageValue(exstorage, os.time() + 24*60*60) -- os.time() + 24 hours, so after 24 hours os.time() will be higher than the player storagevalue
end
-- Don't forget to define the storage variables
local storage = 62003
so would I add
local exstorage = 62004 -- example

I have this, but the npc will not speak to me after I accept the task. local storage is setting to 1, but no task message.

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
-- os.time() + 86400

local monsters = {
   ["Rotworms"] = {storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     for k, x in pairs(monsters) do
     if player:getStorageValue(x.storage) < os.time() then -- If the 24 hours have passed
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
             end
         end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, os.time() + 86400)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
You need to use an other storage for the time, like I did as example with the exstorage.
If you set the storage at the moment the player gets the reward, then edit the line like this.
Code:
if player:getStorageValue(exstorage) ~= -1 and player:getStorageValue(exstorage) < os.time() then
Else the first time before the storage is set it will reset it after accepting the mission and coming back.
 
I don't understand what I am supposed to do here. at all. here is what I have right now


Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
local exstorage = 62004

local monsters = {
   ["Rotworms"] = {storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if player:getStorageValue(exstorage) < os.time() then -- If the 24 hours have passed
     player:setStorageValue(storage, -1)
     for k, x in pairs(monsters) do
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
         end
     end
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) ~= 1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(exstorage, os.time() + 24*60*60)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, os.time() + 86400)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
Atm you use x.storage instead a new storage, x.storage is for the npc monster storage, it's used to start/stop a mission. So use a different storage for the 24 hours wait time, like I wrote in my examples.
You can call it for example exstorage and at the top of the script write which storage number it should be, for example: local exstorage = 62004.
 
So I am not worried about setting the x.storage on turn in? leave it as is? I want each task to be repeatable each 24 hours. I'm not understanding what you are saying about exstorage. how does this reset the task?
 
use two storages
- task status
- delay (if os.time() > storage then --[[script, setting storage to os.time()+86400]] else --[[it's not time yet]] end)

sry if my reply doesn't solve your problem (I'm a bit busy now)
 
If you want each task to be repeatable after 24 hours seperately, then you can add the exstorage in the monster table, so it will be like x.exstorage, so every monster mission will have a different time storage.
The x.storage is for the monster mission, so you have to use a different one for the time.
 
Last edited:
If you want each task to be repeatable after 24 hours seperately, then add the exstorage in the monster table, so it will be like x.exstorage, so every monster mission will have a different wait storage.

this is where I am right now. what needs to be fixed? I am confused to all hell.

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
local exstorage = 62004

local monsters = {
   ["Rotworms"] = {storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if player:getStorageValue(exstorage) < os.time() then -- If the 24 hours have passed
     player:setStorageValue(storage, -1)
     for k, x in pairs(monsters) do
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
         end
     end
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) ~= 1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(exstorage, os.time() + 24*60*60)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, 2)
             player:setStorageValue(storage, -1)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
It kind of depens how you want it to work exactly, for seperate time storages for each monster mission you can do it like this.
Code:
for k, x in pairs(monsters) do
     if player:getStorageValue(x.exstorage) ~= -1 and player:getStorageValue(x.exstorage) < os.time() then -- If the 24 hours have passed
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
     end
end

player:setStorageValue(x.exstorage, os.time() + 24*60*60)
Then add exstorage in the monster mission tables, for example: exstorage = 6010.


[*mod edit] Solution (appended from below post):
Lua:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
local exstorage = 62004

local monsters = {
   ["Rotworms"] = {exstorage = 6010, storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {exstorage = 6011, storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {exstorage = 6012, storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {exstorage = 6013, storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {exstorage = 6014, storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {exstorage = 6015, storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     for k, x in pairs(monsters) do
     if player:getStorageValue(x.exstorage) ~= -1 and player:getStorageValue(x.exstorage) < os.time() then -- If the 24 hours have passed
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
         player:setStorageValue(x.exstorage, -1)
         end
     end
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, 2)
             player:setStorageValue(storage, -1)
             player:setStorageValue(x.exstorage, os.time() + 24*60*60)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited by a moderator:
Solution
This seems to work. Thank you @Limos

Code:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 62003
local exstorage = 62004

local monsters = {
   ["Rotworms"] = {exstorage = 6010, storage = 5010, mstorage = 19000, amount = 20, exp = 1000, items = { {id = 2160, count = 1}}},
   ["Dragons"] = {exstorage = 6011, storage = 5011, mstorage = 19001, amount = 50, exp = 20000, items = { {id = 2160, count = 3}}},
   ["Dragon Lords"] = {exstorage = 6012, storage = 5012, mstorage = 19002, amount = 50, exp = 20000, items = { {id = 2160, count = 5}}},
   ["Hydras"] = {exstorage = 6013, storage = 5013, mstorage = 19003, amount = 100, exp = 60000, items = { {id = 2160, count = 10}}},
   ["Demons"] = {exstorage = 6014, storage = 5014, mstorage = 19004, amount = 100, exp = 80000, items = { {id = 2160, count = 10}}},
   ["Warlocks"] = {exstorage = 6015, storage = 5015, mstorage = 19005, amount = 100, exp = 75000, items = { {id = 2160, count = 10}}}
}


local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)

     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     for k, x in pairs(monsters) do
     if player:getStorageValue(x.exstorage) ~= -1 and player:getStorageValue(x.exstorage) < os.time() then -- If the 24 hours have passed
         player:setStorageValue(x.storage, -1)
         player:setStorageValue(x.mstorage, -1)
         player:setStorageValue(x.exstorage, -1)
         end
     end
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .. ", "
                         text = text .. ""..x.amount.." {"..k.."}"
                     end
                 end
                 if n > 1 then
                     npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 elseif n == 1 then
                     npcHandler:say("I have one last task for you"..text..".", cid)
                     npcHandler.topic[cid] = 1
                 else
                     npcHandler:say("You have completed all tasks, I have nothing for you to do anymore, good job though.", cid)
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back when you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         else
             npcHandler:say("You already did the "..cmsg.." mission.", cid)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience(x.exp)
             player:setStorageValue(x.storage, 2)
             player:setStorageValue(storage, -1)
             player:setStorageValue(x.exstorage, os.time() + 24*60*60)
             npcHandler.topic[cid] = 3
         else
             npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
         end
     elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
             end
         end
         if text ~= "" then
             npcHandler:say("Want to do another task? You can choose "..text..".", cid)
             npcHandler.topic[cid] = 1
         else
             npcHandler:say("You have completed all tasks.", cid)
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "stop") then
         local text, n = "",  0
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 n = n + 1
                 text = text .. (n == 1 and "" or ", ")
                 text = text .. "{"..k.."}"
                 if player:getStorageValue(x.storage) == 1 then
                      player:setStorageValue(x.storage, -1)
                 end
             end
         end
         if player:getStorageValue(storage) == 1 then
             npcHandler:say("Alright, let me know if you want to continue another task, you can still choose "..text..".", cid)
         else
             npcHandler:say("You have not started any new task yet, if you want to a start one, you can choose "..text..".", cid)
         end
         player:setStorageValue(storage, -1)
         npcHandler.topic[cid] = 1
     elseif msgcontains(msg, "list") then
         local text = "Tasks\n\n"
         for k, x in pairs(monsters) do
             if player:getStorageValue(x.mstorage) < x.amount then
                 text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n  Rewards:\n  "..getItemsFromTable(x.items).."\n  "..x.exp.." experience \n\n"
             else
                 text = text .. k .." [DONE]\n"
             end
         end
         player:showTextDialog(1949, "" .. text)
         npcHandler:say("Here you are.", cid)
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Bye.", cid)
         npcHandler:releaseFocus(cid)
     else
         npcHandler:say("What?", cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Last edited:
Is it possible to get x random tasks increasing by level?
I mean, the first task to be only for creatures for level 20-50 (Ex: Cyclops, Dragon), then the second task creatures for 50 or higher (EX: Drag Lord, Demons). Then you can do only 3 tasks daily.
Is it possible for this system?
 
Is it possible to get x random tasks increasing by level?
I mean, the first task to be only for creatures for level 20-50 (Ex: Cyclops, Dragon), then the second task creatures for 50 or higher (EX: Drag Lord, Demons). Then you can do only 3 tasks daily.
Is it possible for this system?
Hello guys, I just wanted to share this with you!
I have just modified the script for a daily task that you are able to choose and you can only do 1 per day.

NPCScript.lua
Lua:
-- Monster Tasks by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local xmsg = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end
local config = {
     tstorage = 45394,
     exstorage = 40824
                }
local storage = 62101

local monsters = {
   ["Demons"] = {storage = 20001, mstorage = 20002, amount = 100, exp = 0, items = {{id = 2160, count = 15}}},
   ["Medusas"] = {storage = 20003, mstorage = 20004, amount = 100, exp = 0, items = {{id = 2160, count = 15}}}
}

local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, ItemType(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
     end
     return text
end

local function Cptl(f, r)
     return f:upper()..r:lower()
end

function creatureSayCallback(cid, type, msg)
     local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             npcHandler:addFocus(cid)
     if player:getStorageValue(config.tstorage) == tonumber(os.date("%w")) and player:getStorageValue(config.exstorage) > os.time() then -- Check daily time if completed
        return        npcHandler:say("You have done enough for today. Come back tomorrow!", cid)
     end
             if player:getStorageValue(storage) == -1 then
                 local text, n = "",  0
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.mstorage) < x.amount then
                         n = n + 1
                         text = text .." or "
                         text = text .. "{"..k.."}"
                     end
                 end
                 if n > 0 then
                     npcHandler:say("I have just one daily task for you: You need to kill 100"..text.." for today. Which one would you like to try? You can only choose one per day. Choose wisely! ", cid)
                     npcHandler.topic[cid] = 1
                     xmsg[cid] = msg
                 end
             elseif player:getStorageValue(storage) == 1 then
                 for k, x in pairs(monsters) do
                     if player:getStorageValue(x.storage) == 1 then
                         npcHandler:say("Have you slain {"..x.amount.." "..k.."}?", cid)
                         npcHandler.topic[cid] = 2
                         xmsg[cid] = k
                     end
                 end
             end
         else
             return false
         end
     elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
         if player:getStorageValue(monsters[cmsg].storage) == -1 then
             npcHandler:say("Good luck, come back once you have killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
             player:setStorageValue(storage, 1)
             player:setStorageValue(monsters[cmsg].storage, 1)
         end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
         local x = monsters[xmsg[cid]]
         if player:getStorageValue(x.mstorage) >= x.amount then
             npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items).." and "..((900000 * (getPlayerLevel(cid) / 300))).." experience points. Come back tomorrow for your next task!", cid)
             for g = 1, #x.items do
                 player:addItem(x.items[g].id, x.items[g].count)
             end
             player:addExperience((900000 * (getPlayerLevel(cid) / 300)))
             player:setStorageValue(x.storage, -1)
             player:setStorageValue(x.mstorage, -1)
             player:setStorageValue(storage, -1)
             player:setStorageValue(config.tstorage, tonumber(os.date("%w")))
             player:setStorageValue(config.exstorage, os.time() + 24*60*60)
             npcHandler.topic[cid] = 3
         else
            if player:getStorageValue(x.mstorage) < 1 then
             npcHandler:say("You have not even started the task. Go and kill some "..xmsg[cid]..".", cid)
            else
             npcHandler:say("You have just killed "..(player:getStorageValue(x.mstorage)).."/"..x.amount.." "..xmsg[cid]..". Come back once you finish this task!", cid)
            end
         end
     elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
         npcHandler:say("Ok then.", cid)
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "bye") then
         npcHandler:say("Good bye! Happy hunting!", cid)
         npcHandler:releaseFocus(cid)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Creaturescript.lua
Code:
<event type="death" name="DailyTasks" script="Creaturescript.lua"/>
data/creaturescriptd/scripts/Creaturescript.lua
Code:
local config = {
['demon'] = {amount = 100, storage = 20002, startstorage = 20001, startvalue = 1},
['medusa'] = {amount = 100, storage = 20004, startstorage = 20003, startvalue = 1}
}
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local monster = config[creature:getName():lower()]
    if creature:isPlayer() or not monster or creature:getMaster() then
    return true
    end
    for attackerUid, damage in pairs(creature:getDamageMap()) do
        local player = Player(attackerUid)
        if player then
       
            local stor = player:getStorageValue(monster.storage)
            local storx = player:getStorageValue(monster.storage) +1              
            if storx >= monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Daily Task: Completed!')
            player:setStorageValue(monster.storage, storx)
            elseif stor < 1 and player:getStorageValue(monster.startstorage) >= monster.startvalue then
            player:setStorageValue(monster.storage, 1)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Daily Task: 1 of '..monster.amount..' '..creature:getName()..'s killed.')
            elseif stor < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
            player:setStorageValue(monster.storage, storx)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Daily Task: '..(storx)..' of '..monster.amount..' '..creature:getName()..'s killed.')
            end  
           
        end
    end
return true
end

This is working fine on my own OTS TFS 1.2. I hope someone might find this useful to add some exp buff for your OTS. By the way the exp points provided to the player is being calculated depending on player's level, so I'm not using the original exp reward system used by Limos, for now. I will point for another upgrades and I will be sharing! Please comment for questions or corrections!
Thanks to @Limos!

EDIT: Btw, I changed the creaturescript to onDeath function, so it could be done while you are with other players, so it is easy to complete this task even if you just hit the creature once. I have not explored yet the ways to make it only for party members or any other limit. So feel free to provide ideas about that!
 
Last edited:
Back
Top