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)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local pos = getPlayerPosition(cid)
local monster = "Monk"
local cost = 300
local summonPos = {x=pos+1, y=pos.y, z=pos.z}
local target = getPlayerName(cid)
local summons = getCreatureSummons(cid)
-- script begins
if(msgcontains(msg, 'help') or msgcontains(msg, 'support')) then
npcHandler:say("Hello, I can sell you a trainer for 300 gold pieces for you to personally!", cid)
elseif(msgcontains(msg, 'trainer') or msgcontains(msg, 'training monk')) then
npcHandler:say("Would you like to buy 1 personal trainer for 300 gold pieces", cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getTilePzInfo(pos) == true then
npcHandler:say("You are in PZ...How do you expect to train...", cid)
elseif getTilePzInfo(pos) == false and doPlayerRemoveMoney(cid, cost) == true then
npcHandler:say("Here you are, your own personal trainer.", cid)
doSummonCreature(monster, summonPos)
doMonsterSetTarget(cid, target)
talkState[talkUser] = 0
elseif (table.maxn(summons) >= 2) then
npcHandler:say("You already have enough personal trainers.", cid)
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
npcHandler:say("Then not.", cid)
talkState[talkUser] = 0
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())