Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Collecting items and monster 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 = {
- {name = "Rats", count = 1, storage = 21900},
- {name = "Rotworms", count = 1, storage = 21901}
- },
- message = "Thanks, for your next mission kill",
- level = 30,
- rewarditems = {
- {id = 2160, count = 5}
- },
- rewardexp = 40000
- },
- [2] = {
- monsters = {
- {name = "Dragon Lords", count = 1, storage = 21902}
- },
- message = "Good job, now kill",
- level = 70,
- rewarditems = {
- {id = 2160, count = 25}
- },
- rewardexp = 200000
- },
- }
- local storage = 46661
- local function getItemsMonstersFromTable(imtable)
- local text = ""
- for v = 1, #imtable do
- local ret = ", "
- if v == 1 then
- ret = ""
- elseif v == #imtable then
- ret = " and "
- end
- text = text .. ret
- count = imtable[v].count
- if imtable[v].id then
- info = getItemInfo(imtable[v].id)
- text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
- else
- text = text .. count .." "..imtable[v].name
- end
- end
- return text
- end
- function creatureSayCallback(cid, type, msg)
- local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
- if not npcHandler:isFocused(cid) then
- return false
- end
- local xstorage = getPlayerStorageValue(cid, storage)
- local x = missions[getPlayerStorageValue(cid, storage)]
- if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
- if not exhaustion.check(cid, 45946) and getPlayerStorageValue(cid, storage) > 0 then
- setPlayerStorageValue(cid, storage, -1)
- xstorage = getPlayerStorageValue(cid, storage)
- end
- if xstorage == -1 then
- selfSay("I have several missions for you, do you accept the challenge?", cid)
- talkState[talkUser] = 1
- elseif x then
- if getPlayerLevel(cid) >= x.level then
- local mess = x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)
- selfSay("Did you "..mess.."?", cid)
- talkState[talkUser] = 1
- else
- selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
- end
- else
- selfSay("You already did all the missions, great job though.", cid)
- npcHandler:releaseFocus(cid)
- end
- elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
- if xstorage == -1 then
- setPlayerStorageValue(cid, storage, 1)
- local x = missions[getPlayerStorageValue(cid, storage)]
- local imtable = x.items or x.monsters
- selfSay(x.message.." "..getItemsMonstersFromTable(imtable)..".", cid)
- exhaustion.set(cid, 45946, 86400)
- elseif x then
- local imtable = x.items or x.monsters
- local amount = 0
- for it = 1, #imtable do
- local check = x.items and getPlayerItemCount(cid, imtable[it].id) or getPlayerStorageValue(cid, imtable[it].storage)
- if check >= imtable[it].count then
- amount = amount + 1
- end
- end
- if amount == #imtable then
- if x.items then
- for it = 1, #x.items do
- doPlayerRemoveItem(cid, x.items[it].id, x.items[it].count)
- end
- end
- if x.rewarditems then
- for r = 1, #x.rewarditems do
- doPlayerAddItem(cid, x.rewarditems[r].id, x.rewarditems[r].count)
- end
- doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
- end
- if x.rewardexp then
- doPlayerAddExp(cid, x.rewardexp)
- doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
- end
- setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
- local x = missions[getPlayerStorageValue(cid, storage)]
- if x then
- selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
- else
- selfSay("Well done! You did a great job on all your missions.", cid)
- exhaustion.set(cid, 45946, 86400)
- end
- else
- local n = 0
- for i = 1, #imtable do
- local check = x.items and getPlayerItemCount(cid, imtable[i].id) or getPlayerStorageValue(cid, imtable[i].storage)
- if check < imtable[i].count then
- n = n + 1
- end
- end
- local text = ""
- local c = 0
- for v = 1, #imtable do
- local check = x.items and getPlayerItemCount(cid, imtable[v].id) or getPlayerStorageValue(cid, imtable[v].storage)
- if check < imtable[v].count then
- c = c + 1
- local ret = ", "
- if c == 1 then
- ret = ""
- elseif c == n then
- ret = " and "
- end
- text = text .. ret
- if x.items then
- local count, info = imtable[v].count - getPlayerItemCount(cid, imtable[v].id), getItemInfo(imtable[v].id)
- text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
- else
- local count = imtable[v].count - (getPlayerStorageValue(cid, imtable[v].storage) + 1)
- text = text .. count.." "..imtable[v].name
- end
- end
- end
- selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill all monsters, you still need to kill "..text..".", cid)
- end
- end
- talkState[talkUser] = 0
- 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, "Good bye, have a nice day!")
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement