Untitled diff

Created Diff never expires
1 removal
193 lines
1 addition
194 lines
-- Collecting items and monster missions by Limos
-- Collecting items and monster missions by Limos
local keywordHandler = KeywordHandler:new()
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function onThink() npcHandler:onThink() end
local missions = {
local missions = {
[1] = {
[1] = {
items = {
items = {
{id = 2350, count = 1}
{id = 2350, count = 1}
},
},
message = "Great, a city guard may have more information of the first item which is",
message = "Great, a city guard may have more information of the first item which is",
level = 0, -- minimum level for this mission
level = 0, -- minimum level for this mission
rewarditems = {
rewarditems = {
{id = 2406, count = 1},
{id = 2406, count = 1},
{id = 2512, count = 1}
{id = 2512, count = 1}
},
},
rewardexp = 50
rewardexp = 50
},
},
[2] = {
[2] = {
monsters = {
monsters = {
{name = "Rats", count = 10, storage = 21900}
{name = "Rats", count = 10, storage = 21900}
},
},
message = "Thanks, for your next mission kill",
message = "Thanks, for your next mission kill",
level = 0,
level = 0,
rewarditems = {
rewarditems = {
{id = 2485, count = 1}
{id = 2485, count = 1}
},
},
rewardexp = 100
rewardexp = 100
},
},
[3] = {
[3] = {
items = {
items = {
{id = 11113, count = 1}
{id = 11113, count = 1}
},
},
message = "Awesome, now get",
message = "Awesome, now get",
level = 0,
level = 0,
rewarditems = {
rewarditems = {
{id = 1988, count = 1},
{id = 1988, count = 1},
{id = 2050, count = 3},
{id = 2050, count = 3},
{id = 2120, count = 1}
{id = 2120, count = 1}
},
},
rewardexp = 200
rewardexp = 200
},
},
[4] = {
[4] = {
monsters = {
monsters = {
{name = "Minotaur", count = 5, storage = 21901}
{name = "Minotaur", count = 5, storage = 21901}
},
},
message = "Good job, now kill",
message = "Good job, now kill",
level = 5,
level = 5,
rewarditems = {
rewarditems = {
{id = 7618, count = 3}
{id = 7618, count = 3}
},
},
rewardexp = 400
rewardexp = 400
},
},
[5] = {
[5] = {
items = {
items = {
{id = 5878, count = 1},
{id = 5878, count = 1},
{id = 12435, count = 1},
{id = 12435, count = 1},
{id = 10606, count = 1}
{id = 10606, count = 1}
},
},
message = "Good, now your final mission, there are a few more items you need to get,",
message = "Good, now your final mission, there are a few more items you need to get,",
level = 6,
level = 6,
rewarditems = {
rewarditems = {
{id = 2152, count = 5}
{id = 2152, count = 5}
},
},
rewardexp = 800
rewardexp = 800
}
}
}
}
local storage = 45551
local storage = 45551
local function getItemsMonstersFromTable(imtable)
local function getItemsMonstersFromTable(imtable)
local text = ""
local text = ""
for v = 1, #imtable do
for v = 1, #imtable do
local ret = ", "
local ret = ", "
if v == 1 then
if v == 1 then
ret = ""
ret = ""
elseif v == #imtable then
elseif v == #imtable then
ret = " and "
ret = " and "
end
end
text = text .. ret
text = text .. ret
count = imtable[v].count
count = imtable[v].count
if imtable[v].id then
if imtable[v].id then
info = ItemType(imtable[v].id)
info = ItemType(imtable[v].id)
text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
else
else
text = text .. count .." "..imtable[v].name
text = text .. count .." "..imtable[v].name
end
end
end
end
return text
return text
end
end
function creatureSayCallback(cid, type, msg)
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
if not npcHandler:isFocused(cid) then
return false
return false
end
end
local player = Player(cid)
local player = Player(cid)
player:save()
local x = missions[player:getStorageValue(storage)]
local x = missions[player:getStorageValue(storage)]
if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
if player:getStorageValue(storage) == -1 then
if player:getStorageValue(storage) == -1 then
selfSay("I have several missions for you, do you accept the challenge?", cid)
selfSay("I have several missions for you, do you accept the challenge?", cid)
npcHandler.topic[cid] = 1
npcHandler.topic[cid] = 1
elseif x then
elseif x then
if player:getLevel() >= x.level then
if player:getLevel() >= x.level then
selfSay("Did you "..(x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)).."?", cid)
selfSay("Did you "..(x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)).."?", cid)
npcHandler.topic[cid] = 1
npcHandler.topic[cid] = 1
else
else
selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
end
end
else
else
selfSay("You already did all the missions, great job though.", cid)
selfSay("You already did all the missions, great job though.", cid)
npcHandler:releaseFocus(cid)
npcHandler:releaseFocus(cid)
end
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
if player:getStorageValue(storage) == -1 then
if player:getStorageValue(storage) == -1 then
player:setStorageValue(storage, 1)
player:setStorageValue(storage, 1)
local x = missions[player:getStorageValue(storage)]
local x = missions[player:getStorageValue(storage)]
selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
elseif x then
elseif x then
local imtable = x.items or x.monsters
local imtable = x.items or x.monsters
local amount = 0
local amount = 0
for it = 1, #imtable do
for it = 1, #imtable do
local check = x.items and player:getItemCount(imtable[it].id) or player:getStorageValue(imtable[it].storage)
local check = x.items and player:getItemCount(imtable[it].id) or player:getStorageValue(imtable[it].storage)
if check >= imtable[it].count then
if check >= imtable[it].count then
amount = amount + 1
amount = amount + 1
end
end
end
end
if amount == #imtable then
if amount == #imtable then
if x.items then
if x.items then
for it = 1, #x.items do
for it = 1, #x.items do
player:removeItem(x.items[it].id, x.items[it].count)
player:removeItem(x.items[it].id, x.items[it].count)
end
end
end
end
if x.rewarditems then
if x.rewarditems then
for r = 1, #x.rewarditems do
for r = 1, #x.rewarditems do
player:addItem(x.rewarditems[r].id, x.rewarditems[r].count)
player:addItem(x.rewarditems[r].id, x.rewarditems[r].count)
end
end
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
end
end
if x.rewardexp then
if x.rewardexp then
player:addExperience(x.rewardexp)
player:addExperience(x.rewardexp)
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
end
end
player:setStorageValue(storage, player:getStorageValue(storage) + 1)
player:setStorageValue(storage, player:getStorageValue(storage) + 1)
local x = missions[player:getStorageValue(storage)]
local x = missions[player:getStorageValue(storage)]
if x then
if x then
selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
else
else
selfSay("Well done! You did a great job on all your missions.", cid)
selfSay("Well done! You did a great job on all your missions.", cid)
end
end
else
else
local n = 0
local n = 0
for i = 1, #imtable do
for i = 1, #imtable do
local check = x.items and player:getItemCount(imtable[i].id) or player:getStorageValue(imtable[i].storage)
local check = x.items and player:getItemCount(imtable[i].id) or player:getStorageValue(imtable[i].storage)
if check < imtable[i].count then
if check < imtable[i].count then
n = n + 1
n = n + 1
end
end
end
end
local text = ""
local text = ""
local c = 0
local c = 0
for v = 1, #imtable do
for v = 1, #imtable do
local check = x.items and player:getItemCount(imtable[v].id) or player:getStorageValue(imtable[v].storage)
local check = x.items and player:getItemCount(imtable[v].id) or player:getStorageValue(imtable[v].storage)
if check < imtable[v].count then
if check < imtable[v].count then
c = c + 1
c = c + 1
local ret = ", "
local ret = ", "
if c == 1 then
if c == 1 then
ret = ""
ret = ""
elseif c == n then
elseif c == n then
ret = " and "
ret = " and "
end
end
text = text .. ret
text = text .. ret
if x.items then
if x.items then
local count, info = imtable[v].count - player:getItemCount(imtable[v].id), ItemType(imtable[v].id)
local count, info = imtable[v].count - player:getItemCount(imtable[v].id), ItemType(imtable[v].id)
text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
else
else
local count = imtable[v].count - (player:getStorageValue(imtable[v].storage) + 1)
local count = imtable[v].count - (player:getStorageValue(imtable[v].storage) + 1)
text = text .. count.." "..imtable[v].name
text = text .. count.." "..imtable[v].name
end
end
end
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)
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
end
end
npcHandler.topic[cid] = 0
npcHandler.topic[cid] = 0
elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
selfSay("Oh well, I guess not then.", cid)
selfSay("Oh well, I guess not then.", cid)
npcHandler.topic[cid] = 0
npcHandler.topic[cid] = 0
end
end
return true
return true
end
end
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
npcHandler:addModule(FocusModule:new())