local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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 mission = {
storage = 45001,
reward = {
female = {
outfitLooktype = 136, -- data/XML/outfits.xml
addon = 3 -- addon 1, addon 2, or addon 3 (both 1 & 2)
},
male = {
outfitLooktype = 128, -- as currently scripted, it will reward the player
addon = 3 -- for both the female and male outfit addons.
}
},
requiredGold = 10000,
requiredItems =
{
{itemId = 1111, amount = 1},
{itemId = 2222, amount = 20}
}
}
local function getMissionRequiredItems()
local text = ""
for i = 1, #mission.requiredItems do
if text ~= "" then
text = text .. ", "
end
text = text .. mission.requiredItems[i].amount .. " " .. ItemType(mission.requiredItems[i].itemId):getName()
end
text = mission.requiredGold .. " gold, " .. text
return text
end
local function getOutfitName(outfitLooktype)
local outfitsTable = Game.getOutfits(PLAYERSEX_FEMALE)
for i = 1, #outfitsTable do
local outfit = outfitsTable[i]
if outfit.id == outfitLooktype then
return outfit.name
end
end
outfitsTable = Game.getOutfits(PLAYERSEX_MALE)
for i = 1, #outfitsTable do
local outfit = outfitsTable[i]
if outfit.id == outfitLooktype then
return outfit.name
end
end
return "OUTFIT_UNKNOWN"
end
local function greetCallback(cid)
local player = Player(cid)
local storageValue = player:getStorageValue(mission.storage)
if storageValue == 0 or storageValue == 1 then
if storageValue == 0 then
player:setStorageValue(mission.storage, 1)
end
npcHandler:setMessage(MESSAGE_GREET, "Have you brought me those items?")
npcHandler.topic[cid] = 1
else
npcHandler:setMessage(MESSAGE_GREET, "Hey. How you doing?")
end
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
local storageValue = player:getStorageValue(mission.storage)
if (msgcontains(msg, "outfit") or msgcontains(msg, "quest") or msgcontains(msg, "mission")) and npcHandler.topic[cid] == 0 then
if storageValue == -1 then
npcHandler:say("You're interested in obtaining the " .. getOutfitName(mission.reward.female.outfitLooktype) .. " outfit addon, eh? Would you like to fetch me a few things to make it for ya?", cid)
npcHandler.topic[cid] = 1
return true
end
if storageValue == 0 then
npcHandler:say("Well, what are you waiting for? Go get the items and talk to me again.", cid)
npcHandler.topic[cid] = 0
return true
end
if storageValue == 1 then
npcHandler:say("Have you brought me those items?", cid)
npcHandler.topic[cid] = 1
return true
end
npcHandler:say("I don't have any other outfits to give.", cid)
npcHandler.topic[cid] = 1
return true
elseif npcHandler.topic[cid] == 1 then
if storageValue == -1 then
if not msgcontains(msg, "yes") then
npcHandler:say("Alright. I won't pressure you.", cid)
npcHandler.topic[cid] = 0
return true
end
npcHandler:say("Alright. Bring me " .. getMissionRequiredItems() .. ".", cid)
player:setStorageValue(mission.storage, 0)
npcHandler.topic[cid] = 0
return true
end
if storageValue == 1 then
if not msgcontains(msg, "yes") then
npcHandler:say("Well, what are you waiting for? Go get the items and talk to me again.", cid)
npcHandler.topic[cid] = 0
return true
end
local hasAllRequiredItems = true
for i = 1, #mission.requiredItems do
if player:getItemCount(mission.requiredItems[i].itemId) < mission.requiredItems[i].amount then
hasAllRequiredItems = false
break
end
end
if player:getMoney() < mission.requiredGold then
hasAllRequiredItems = false
end
if not hasAllRequiredItems then
npcHandler:say("You don't seem to have them with you. Bring me " .. getMissionRequiredItems() .. ".", cid)
player:setStorageValue(mission.storage, 0)
npcHandler.topic[cid] = 0
return true
end
for i = 1, #mission.requiredItems do
player:removeItem(mission.requiredItems[i].itemId, mission.requiredItems[i].amount)
end
player:addOutfitAddon(mission.reward.female.outfitLooktype, mission.reward.female.addon)
player:addOutfitAddon(mission.reward.male.outfitLooktype, mission.reward.male.addon)
player:setStorageValue(mission.storage, 2)
npcHandler.topic[cid] = 0
return true
end
end
return true
end
local function onAddFocus(cid)
npcHandler.topic[cid] = 0
end
local function onReleaseFocus(cid)
npcHandler.topic[cid] = 0
end
npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())