Thorn
Spriting since 2013
Hello guys!! i was making a task npc with the limos system, and add it the slow speaking way to the npc, looks really cool, but i have a problem, i don't know why the system isn't counting my kills, and i already registered it in login.lua and creaturescripts.xml :S
I was wondering if someone could help me figure out why, and hopefully someone can help me make this whole monsters become 1 single task. You take the task and have to kill all of them for a single reward, this is beyong my "coding skills" =(
NPC lua
Creaturescript.lua
I was wondering if someone could help me figure out why, and hopefully someone can help me make this whole monsters become 1 single task. You take the task and have to kill all of them for a single reward, this is beyong my "coding skills" =(
NPC 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 storage = 62109
local monsters = {
["Deepling Worker"] = {storage = 25243, mstorage = 25251, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Scout"] = {storage = 25244, mstorage = 25252, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Brawler"] = {storage = 25245, mstorage = 25253, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Spellsinger"] = {storage = 25246, mstorage = 25254, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Warrior"] = {storage = 25247, mstorage = 25255, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Guard"] = {storage = 25248, mstorage = 25256, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Elite"] = {storage = 25249, mstorage = 25257, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}},
["Deepling Tyrant"] = {storage = 25250, mstorage = 25258, amount = 20, exp = 30000, items = {{id = 28800, count = 1}, {id = 29529, count = 2}, {id = 22397, count = 3}}}
}
local message = {
delay = 4000,
start = {
"Gaahhjj! kja kja kja...A human! Perfect! ...",
"My name is Braquiuros, and i am the leader of this quara community ...",
"For many months, we have been in peace, but deeplings have started attaacking us for no reason!! ...",
"I would be really helpful if you could help me slain a bunch of those bastards ...",
"I would go myself but you see...My knee is broken...coff coff ...",
"So, will you help our peaceful community? Say {yes} to accept and help us.",
"So, will you help our peaceful community? I just need you to kill 20 of each deeplings: worker, scout, brawler, spellsinger, warrior, guard, elite and tyrant.",
"I will give you a reward for each type completed, just say the full name of the deepling and we will start.",
}
}
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(message.start, cid, false, true, message.delay)
npcHandler.topic[cid] = 1
xmsg[cid] = msg
elseif n == 1 then
npcHandler:say(message.start, cid, false, true, message.delay)
npcHandler.topic[cid] = 1
else
npcHandler:say("You have already helped me, thank you for that!", 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 defeated Those ugly "..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("Best of luck! Come back to me when you have kill "..monsters[cmsg].amount.." "..cmsg..".", cid)
player:setStorageValue(storage, 1)
player:setStorageValue(monsters[cmsg].storage, 1)
else
npcHandler:say("You have already helped me, thank you for that!", 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("Ahhhh this is very nice, thank you human, you have helped me, 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("Don't lie to me, you haven't kill him yet...You are missing "..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("You want to kill more of these deeplings? "..text..".", cid)
npcHandler.topic[cid] = 1
else
npcHandler:say("You have helped us enough human.", cid)
end
elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
npcHandler:say("Ok then.", cid)
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "abandon") 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("Ok, dime si quieres continuar otra task, todavia puedes elegir "..text..".", cid)
else
npcHandler:say("No empezaste ninguna nueva task, si quieres empezar una, puedes elegir "..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("Gaahhjj!", cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Creaturescript.lua
Lua:
local config = {
['Deepling Worker'] = {amount = 20, startstorage = 25243, storage = 25251, startvalue = 1},
['Deepling Scout'] = {amount = 20, startstorage = 25244, storage = 25252, startvalue = 1},
['Deepling Brawler'] = {amount = 20, startstorage = 25245, storage = 25253, startvalue = 1},
['Deepling Spellsinger'] = {amount = 20, startstorage = 25246, storage = 25254, startvalue = 1},
['Deepling Warrior'] = {amount = 20, startstorage = 25247, storage = 25255, startvalue = 1},
['Deepling Guard'] = {amount = 20, startstorage = 25248, storage = 25256, startvalue = 1},
['Deepling Elite'] = {amount = 20, startstorage = 25249, storage = 25257, startvalue = 1},
['Deepling Tyrant'] = {amount = 20, startstorage = 25250, storage = 25258, 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, 'Nicee, 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