Skip to content

Instantly share code, notes, and snippets.

@BenDol
Created December 3, 2014 14:59
Show Gist options
  • Save BenDol/0be952bf4d747aeddaa7 to your computer and use it in GitHub Desktop.
Save BenDol/0be952bf4d747aeddaa7 to your computer and use it in GitHub Desktop.
NpcHandler:onThink()
-- Handles onThink events. If you wish to handle this yourself, please use the CALLBACK_ONTHINK callback.
function NpcHandler:onThink()
local callback = self:getCallback(CALLBACK_ONTHINK)
if callback == nil or callback() then
for i, speech in pairs(self.talkDelay) do
if (speech.cid == nil or speech.cid == 0) and speech.time ~= nil and speech.message ~= nil then
if os.mtime() >= speech.time then
selfSay(speech.message)
self.talkDelay[i] = nil
end
elseif isCreature(speech.cid) and speech.start ~= nil and speech.time ~= nil and speech.message ~= nil then
if os.mtime() >= speech.time then
local talkStart = (NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT and self.talkStart[speech.cid] or self.talkStart)
if speech.force or (self:isFocused(speech.cid) and talkStart == speech.start) then
if NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT then
selfSay(speech.message, speech.cid)
else
selfSay(speech.message)
end
end
self.talkDelay[i] = nil
end
else
self.talkDelay[i] = nil
end
end
if self:processModuleCallback(CALLBACK_ONTHINK) then
if NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT then
for _, focus in pairs(self.focuses) do
if focus ~= nil then
if not self:isInRange(focus) then
self:onWalkAway(focus)
elseif (os.time() - self.talkStart[focus]) > self.idleTime then
self:unGreet(focus)
else
self:updateFocus()
end
end
end
elseif self.focuses ~= 0 then
if not self:isInRange(self.focuses) then
self:onWalkAway(self.focuses)
elseif (os.time() - self.talkStart) > self.idleTime then
self:unGreet(self.focuses)
else
self:updateFocus()
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment