--[[ Jetro's Mission quest npc 1.0
ALL CREDITS TO JETRO
]]--
local config =
{
requirements =
{
storage = 0, --STORAGE REQUIRED
requiredlevel = false, --REQUIRES LEVEL? TRUE OR FALSE
level = 300, --LEVEL (IF REQUIRED)
requiredpremium = false, --REQUIRES PREMIUM? TRUE OR FALSE
itemsrequired = --ITEMS REQUIRED'S LIST
{
[2157] = {amount = 1},
[9971] = {amount = 1}
},
},
rewards =
{
expvalue = 10000000, --EXPERIENCE. (false if it won't give exp)
expcolor = 35, --COLOR OF ANIMATED TEXT: min = 1, max = 255
money = 1000000, --MONEY. (false if it won't give money)
reward = --ITEMS'S LIST (false if it won't give items)
{
[2130] = {amount = 1},
},
}
}
local function getRequiredThings(cid)
local msg = ""
local itemsleft = { }
for i,x in pairs(config.requirements.itemsrequired) do
local item = getPlayerItemCount(cid, i)
if (item < x.amount) then
table.insert(itemsleft, x.amount - item.. "x "..getItemNameById(i))
end
end
msg = #itemsleft > 0 and "Items: "..table.concat(itemsleft, ", ") or ""
return msg
end
local itemscap = 0
for i,x in pairs (config.requirements.itemsrequired) do
itemscap = itemscap + getItemWeightById(i, x.amount)
end
local requir = {}
for i,x in pairs(config.requirements.itemsrequired) do
table.insert (requir, x.amount .. "x "..getItemNameById(i))
end
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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local cap = getPlayerFreeCap(cid)
local s = getPlayerStorageValue(cid, config.requirements.storage) == 1 and true or false
local lv = getPlayerLevel(cid)
local prm = isPremium(cid)
--LIST OF MESSAGES THAT THE NPC WILL SAY--
local msgs =
{
requirements = "If you want to make a very nice deal with me, listen up. I need "..table.concat(requir, ", ").. ". Do you have "..(#requir > 1 and "them" or "it").. "?",
reward = "And here's my part of the deal.",
done = "You have already done this mission.",
notpremium = "Sorry, only players with premium account can make this mission.",
notitems = "I think you missed something there, you don't have all the items "..getRequiredThings(cid),
notlevel = "I think you should be atleast level 300 before demanding such a trade {"..config.requirements.level.."}",
wrong = "Huh?",
negation = "Ok, maybe next time.."
}
local rq = getRequiredThings(cid)
if (msgcontains(msg, 'mission')) then
if (config.requirements.requiredpremium == true and not prm ) then
return selfSay(msgs.notpremium, cid)
end
if (s == true)then
return selfSay(msgs.done, cid)
end
if (config.requirements.requiredlevel == true and lv < config.requirements.level) then
return selfSay(msgs.notlevel, cid)
end
selfSay(msgs.requirements,cid)
talk_state = 1
elseif (msgcontains(msg, "yes")) and talk_state == 1 then
if ( rq == "" ) then
if (cap < itemscap) then
return selfSay("Sorry, you don't have enough capacity to carry the reward. All weights items.cap", cid)
end
if (config.rewards.expvalue ~= false) then
doPlayerAddExp(cid, config.rewards.expvalue)
if (config.rewards.expcolor > 255 or config.rewards.expcolor <= 0) then
config.rewards.expcolor = math.random(255)
end
doSendAnimatedText(getThingPos(cid), config.rewards.expvalue, config.rewards.expcolor)
end
if (config.rewards.money ~= false) then
doPlayerAddMoney(cid, config.rewards.money)
end
if (config.rewards.reward ~= false) then
for i,x in pairs (config.rewards.reward) do
doPlayerAddItem(cid, i, x.amount)
end
end
for i,x in pairs (config.requirements.itemsrequired) do
doPlayerRemoveItem(cid, i, x.amount)
end
selfSay(msgs.reward.."".. rq, cid)
talk_state = 0
else
selfSay("You still don't have all items, you still need "..rq, cid)
talk_state = 0
end
elseif (msgcontains(msg, "no") and talk_state == 1 ) then
selfSay(msgs.negation, cid)
talk_state = 0
else
selfSay(msgs.wrong, cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())