Hello guys, I need help with this script to do repeatable when all tasks finished, if possible, or everone. (REPEAT EVERY WEEK IF POSSIBLE)
Thank you!
@Edit: the creaturescript.lua
Thank you!
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 monsters = {
["Lizard Chosens"] = {storage = 5010, mstorage = 19000, amount = 900, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 80}}},
["Wyrms"] = {storage = 5011, mstorage = 19001, amount = 900, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 80}}},
["Behemoths"] = {storage = 5012, mstorage = 19002, amount = 700, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 50}}},
["Crawlers"] = {storage = 5013, mstorage = 19003, amount = 900, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 80}}},
["Ghastly Dragons"] = {storage = 5014, mstorage = 19004, amount = 600, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 60}}},
["Serpent Spawns"] = {storage = 5015, mstorage = 19005, amount = 900, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 80}}},
["Hellspawns"] = {storage = 5016, mstorage = 19006, amount = 800, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 70}}},
["Juggernauts"] = {storage = 5017, mstorage = 19007, amount = 300, exp = 5000000, items = {{id = 10503, count = 4}, {id = 6527, count = 100}}},
["Dark Torturers"] = {storage = 5018, mstorage = 19008, amount = 400, exp = 4000000, items = {{id = 10503, count = 2}, {id = 6527, count = 100}}},
["Frazzlemaws"] = {storage = 5019, mstorage = 19009, amount = 900, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 80}}},
["Dark Magicians"] = {storage = 5020, mstorage = 19010, amount = 300, exp = 1000000, items = {{id = 2160, count = 50}, {id = 6527, count = 30}}},
["Dragons"] = {storage = 5021, mstorage = 19011, amount = 700, exp = 2000000, items = {{id = 10503, count = 1}, {id = 6527, count = 65}}},
["Heroes"] = {storage = 5022, mstorage = 19012, amount = 650, exp = 1500000, items = {{id = 10503, count = 1}, {id = 6527, count = 50}}},
["Souleaters"] = {storage = 5023, mstorage = 19013, amount = 750, exp = 2500000, items = {{id = 10503, count = 1}, {id = 6527, count = 60}}},
["Furies"] = {storage = 5024, mstorage = 19014, amount = 350, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 80}}},
["Ancient Scarabs"] = {storage = 5025, mstorage = 19015, amount = 700, exp = 2000000, items = {{id = 10503, count = 1}, {id = 6527, count = 70}}},
["Draken Warmaster"] = {storage = 5026, mstorage = 19016, amount = 850, exp = 3000000, items = {{id = 10503, count = 1}, {id = 6527, count = 60}}},
["Demons"] = {storage = 5027, mstorage = 19017, amount = 3000, exp = 10000000, items = {{id = 10503, count = 15}, {id = 6527, count = 500}}},
["Grim Reapers"] = {storage = 5028, mstorage = 19018, amount = 2000, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Dragon Lords"] = {storage = 5029, mstorage = 19019, amount = 3000, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Medusaes"] = {storage = 5030, mstorage = 19020, amount = 2000, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Hellhounds"] = {storage = 5031, mstorage = 19021, amount = 500, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Hellflayers"] = {storage = 5032, mstorage = 19022, amount = 500, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Demon Outcasts"] = {storage = 5033, mstorage = 19023, amount = 1500, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Elder Wyrms"] = {storage = 5034, mstorage = 19024, amount = 2500, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Ironblights"] = {storage = 5035, mstorage = 19025, amount = 500, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}},
["Hellfire Fighters"] = {storage = 5036, mstorage = 19026, amount = 1500, exp = 10000000, items = {{id = 10503, count = 10}, {id = 6527, count = 500}}}
}
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 already did 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 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)
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 already did 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 an other task, you can still choose "..text..".", cid)
else
npcHandler:say("You didn't start any new task yet, if you want to 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)
@Edit: the creaturescript.lua
Code:
local config = {
['lizard chosen'] = {amount = 900, storage = 19000, startstorage = 5010, startvalue = 1},
['wyrm'] = {amount = 900, storage = 19001, startstorage = 5011, startvalue = 1},
['behemoth'] = {amount = 700, storage = 19002, startstorage = 5012, startvalue = 1},
['crawler'] = {amount = 900, storage = 19003, startstorage = 5013, startvalue = 1},
['ghastly dragon'] = {amount = 600, storage = 19004, startstorage = 5014, startvalue = 1},
['serpent spawn'] = {amount = 900, storage = 19005, startstorage = 5015, startvalue = 1},
['hellspawn'] = {amount = 800, storage = 19006, startstorage = 5016, startvalue = 1},
['juggernaut'] = {amount = 300, storage = 19007, startstorage = 5017, startvalue = 1},
['dark torturer'] = {amount = 400, storage = 19008, startstorage = 5018, startvalue = 1},
['frazzlemaw'] = {amount = 900, storage = 19009, startstorage = 5019, startvalue = 1},
['dark magician'] = {amount = 300, storage = 19010, startstorage = 5020, startvalue = 1},
['dragon'] = {amount = 700, storage = 19011, startstorage = 5021, startvalue = 1},
['hero'] = {amount = 650, storage = 19012, startstorage = 5022, startvalue = 1},
['souleater'] = {amount = 750, storage = 19013, startstorage = 5023, startvalue = 1},
['fury'] = {amount = 350, storage = 19014, startstorage = 5024, startvalue = 1},
['ancient scarab'] = {amount = 700, storage = 19015, startstorage = 5025, startvalue = 1},
['draken warmaster'] = {amount = 850, storage = 19016, startstorage = 5026, startvalue = 1},
['demon'] = {amount = 3000, storage = 19017, startstorage = 5027, startvalue = 1},
['grim reaper'] = {amount = 2000, storage = 19018, startstorage = 5028, startvalue = 1},
['dragon lord'] = {amount = 3000, storage = 19019, startstorage = 5029, startvalue = 1},
['medusa'] = {amount = 2000, storage = 19020, startstorage = 5030, startvalue = 1},
['hellhound'] = {amount = 500, storage = 19021, startstorage = 5031, startvalue = 1},
['hellflayer'] = {amount = 500, storage = 19022, startstorage = 5032, startvalue = 1},
['demon outcast'] = {amount = 1500, storage = 19023, startstorage = 5033, startvalue = 1},
['elder wyrm'] = {amount = 2500, storage = 19024, startstorage = 5034, startvalue = 1},
['ironblight'] = {amount = 500, storage = 19025, startstorage = 5035, startvalue = 1},
['hellfire fighter'] = {amount = 1500, storage = 19026, startstorage = 5036, 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
Last edited: