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 cost = 500
local target = nil
local position = nil
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, "find") and npcHandler.topic[cid] == 0 then
npcHandler:say("Who do you want me to find for you?", cid)
npcHandler.topic[cid] = 1
elseif npcHandler.topic[cid] == 1 then
target = Player(msg)
if target then
if target:getSex() == PLAYERSEX_FEMALE then
npcHandler:say("Indeed i know where she is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
else
npcHandler:say("Indeed i know where he is, however, this information will cost you " .. cost .. " gp. Are you willing to know too?", cid)
end
position = target:getPosition()
npcHandler.topic[cid] = 2
else
npcHandler:say("Unfortunately i didn\'t saw anybody of this name.", cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 2
if msgcontains(msg, "yes") then
if Player(cid):removeMoney(cost) then
local message = target:getName() .. " is "
local horizontal = Player(cid):getPosition().x - position.x
local vertical = Player(cid):getPosition().y - position.y
local floor = Player(cid):getPosition().z - position.z
if horizontal < 0 then
message = message .. math.abs(horizontal) .. "steps to East, "
elseif horizontal > 0 then
message = message .. math.abs(horizontal) .. "steps to West, "
end
if vertical < 0 then
message = message .. math.abs(vertical) .. "steps to North, "
elseif vertical > 0 then
message = message .. math.abs(vertical) .. "steps to South, "
end
if floor < 0 then
message = message .. "above us, "
elseif floor > 0 then
message = message .. "beneath us, "
end
if math.abs(horizontal) < 2 and math.abs(vertical) < 2 and floor = 0 then
message = target:getName() .. " is here, "
end
npcHandler:say(message .. "This is all what i know.", cid)
npcHandler.topic[cid] == 0
else
npcHandler:say("Im sorry but you don\'t have enough money.", cid)
npcHandler.topic[cid] == 0
end
else
npcHandler:say("Come back when you\'ve decided.", cid)
npcHandler.topic[cid] == 0
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())