local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
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
-- OTServ event handling functions end
function doCreatureSayWithDelay(cid,text,type,delay,e)
if delay<=0 then
doCreatureSay(cid,text,type)
else
local func=function(pars)
doCreatureSay(pars.cid,pars.text,pars.type)
pars.e.done=TRUE
end
e.done=FALSE
e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
end
end
--returns how many msgs he have said already
function cancelNPCTalk(events)
local ret=1
for aux=1,table.getn(events) do
if events[aux].done==FALSE then
stopEvent(events[aux].event)
else
ret=ret+1
end
end
events=nil
return(ret)
end
function doNPCTalkALot(msgs,interval)
local e={}
local ret={}
if interval==nil then interval=3000 end --3 seconds is default time between messages
for aux=1,table.getn(msgs) do
e[aux]={}
doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux])
table.insert(ret,e[aux])
end
return(ret)
end
function creatureSayCallback(cid, type, msg)
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
if (not npcHandler:isFocused(cid)) then
return false
end
function greetCallback(cid)
if getPlayerStorageValue(cid, 60452) == -1 then
npcHandler:setMessage(MESSAGE_GREET, "xDd")
elseif getPlayerStorageValue(cid, 60452) == 1 then
npcHandler:setMessage(MESSAGE_GREET, "xP :P")
else
npcHandler:setMessage(MESSAGE_GREET, "xdd")
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
if(msgcontains(msg, 'yes')) and getPlayerStorageValue(cid, 60452) == -1 then
local msgs={
"Thank you, kid. I am really tired, and I feel that there is not much time for me left, but still- I have to eat something. There are many rabbits nearby, but I am too old to hunt them. I still got some savings, so if you bring me 5 pieces of {meat} and I will reward you.",
"Ohh my poor hip...",
}
doNPCTalkALot(msgs,9000) --if the 2750 is ommited, it uses 3000 always
doPlayerSetStorageValue(cid,60452, 1)
---------------------------------------------------------
elseif msgcontains(msg, 'meat') or msgcontains(msg, 'yes') or msgcontains(msg, 'help') and getPlayerStorageValue(cid, 60452) == 1 then
if(doPlayerRemoveItem(cid, 2666, 5) == TRUE) then
setPlayerStorageValue(cid,60452,2)
doPlayerAddExperience(cid,1000)
doPlayerAddItem(cid, 2152, 10)
doPlayerSendTextMessage(cid, 22, "1000 exp gained.")
selfSay('Thank you my dear. I really appreciate it. Here is 1000 gold coins. I really hope, that gods saw your good deed and rewarded you aswell. You can bring me as many food as you can, I will reward you each time.', cid)
else
selfSay('Please bring me some food. I am starving.', cid)
end
end
------------------------------------------------ confirm no ------------------------------------------------
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())