-- Collecting monsters missions by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local missions = {
[1] = {monsters = {
{id = hydra, count = 12},
{id = demon, count = 8}
},
message = "Great, I need alot of monsters, but you can start with",
level = 15, -- minimum level voor this mission
rewarditem = {id = 2160, count = 1},
rewardexp = 15000
},
[2] = {monsters = {
{id = 5898, count = 20},
{id = 6098, count = 26}
},
message = "Thank you, the next monsters are",
level = 30,
rewarditem = {id = 2160, count = 5},
rewardexp = 40000
},
[3] = {monsters = {
{id = 5920, count = 45},
{id = 5877, count = 22}
},
message = "Awesome, now get",
level = 50,
rewarditem = {id = 2160, count = 15},
rewardexp = 100000
},
[4] = {monsters = {
{id = 5913, count = 20},
{id = 5910, count = 10}
},
message = "Thanks, now I need",
level = 70,
rewarditem = {id = 2160, count = 25},
rewardexp = 200000
},
[5] = {monsters = {
{id = 5906, count = 35},
{id = 4850, count = 1}
},
message = "Good, only a few monsters left,",
level = 10000,
rewarditem = {id = 2160, count = 50},
rewardlevel = 45
}
}
local storage = 45550
local function getmonstersFromTable(itemtable)
local text = ""
for v = 1, #itemtable do
count, info = itemtable[v].count, getItemInfo(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.article).." "..(count > 1 and info.plural or info.name)
end
return text
end
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local xstorage = getPlayerStorageValue(cid, storage)
local x = missions[xstorage]
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, 'mission') then
if not exhaustion.check(cid, 45646) and getPlayerStorageValue(cid, storage) > 0 then
setPlayerStorageValue(cid, storage, -1)
xstorage = getPlayerStorageValue(cid, storage)
end
if xstorage == -1 then
selfSay("I am a discoverer and I am currently doing some research, do you think you can help me out?", cid)
talkState[talkUser] = 1
elseif x then
if getPlayerLevel(cid) >= x.level then
selfSay("Did you get the {monsters} I asked you?", cid)
talkState[talkUser] = 1
else
selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
end
else
selfSay("Thanks again for all your monsters, it helped me alot.", cid)
npcHandler:releaseFocus(cid)
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
if xstorage == -1 then
setPlayerStorageValue(cid, storage, 1)
local x = missions[getPlayerStorageValue(cid, storage)]
selfSay(x.message.." "..getmonstersFromTable(x.monsters)..".", cid)
exhaustion.set(cid, 45646, 86400)
elseif x then
local amount = 0
for i = 1, #x.monsters do
if getPlayerItemCount(cid, x.monsters[i].id) >= x.monsters[i].count then
amount = amount + 1
end
end
if amount == #x.monsters then
for i = 1, #x.monsters do
doPlayerRemoveItem(cid, x.monsters[i].id, x.monsters[i].count)
end
if x.rewarditem then
local count, info = x.rewarditem.count, getItemInfo(x.rewarditem.id)
doPlayerAddItem(cid, x.rewarditem.id, count)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..(count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)..".")
end
if x.rewardexp then
doPlayerAddExp(cid, x.rewardexp)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
end
if x.rewardlevel then
doPlayerAddLevel(cid, x.rewardlevel)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardlevel.." level.")
end
setPlayerStorageValue(cid, storage, xstorage + 1)
local x = missions[getPlayerStorageValue(cid, storage)]
if x then
selfSay(x.message.." "..getmonstersFromTable(x.monsters)..".", cid)
else
selfSay("Thanks alot! I can finish my research now.", cid)
end
exhaustion.set(cid, 45646, 86400)
else
local n = 0
for i = 1, #x.monsters do
if getPlayerItemCount(cid, x.monsters[i].id) < x.monsters[i].count then
n = n + 1
end
end
local text = ""
local c = 0
for v = 1, #x.monsters do
count, info = x.monsters[v].count - getPlayerItemCount(cid, x.monsters[v].id), getItemInfo(x.monsters[v].id)
if getPlayerItemCount(cid, x.monsters[v].id) < x.monsters[v].count then
c = c + 1
local ret = ", "
if c == 1 then
ret = ""
elseif c == n then
ret = " and "
end
text = text .. ret
text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
end
end
selfSay("You don't have all monsters, you still need to get "..text..".", cid)
end
end
talkState[talkUser] = 0
elseif msgcontains(msg, 'monsters') and x then
selfSay("The monsters I asked you are "..getmonstersFromTable(x.monsters)..".", cid)
elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
selfSay("Oh well, I guess not then.", cid)
end
return true
end
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye? I guess...")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())