• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[NPC] unGreet+delay event.

Hameq

Banned User
Joined
Aug 8, 2010
Messages
374
Reaction score
36
Hello guys.
It is possible to add (addevent function) to my npc system(Jiddos), i mean something like ungreet with delay. I found some related functions like changeFocus(0), releaseFocus(), unGreet(), onFarewell(). For example how to add delay event into this ungreet function?

Code:
	function NpcHandler:unGreet()
		if(self.focus == 0) then
			return
		end
		local callback = self:getCallback(CALLBACK_FAREWELL)
		if(callback == nil or callback()) then
			if(self:processModuleCallback(CALLBACK_FAREWELL)) then
				if(self.queue == nil or not self.queue:greetNext()) then
					local msg = self:getMessage(MESSAGE_FAREWELL)
					local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(self.focus) }
					msg = self:parseMessage(msg, parseInfo)
					self:say(msg)
					self:releaseFocus()
				end
			end
		end
	end

I tried that: addEvent(releaseFocus() 1000, cid) i know it won't work but maybe you guys can help :rolleyes:
 
LUA:
addEvent(function(focus) if(not npcHandler:isFocused(focus)) then return end for k,v in pairs(npcHandler.focuses) do if v == focus then table.remove(npcHandler.focuses, k) break end end npcHandler.talkStart[focus] = nil closeShopWindow(focus) npcHandler:updateFocus() end, 1000, cid)
 
I modified a bit your function with my little older nps system(my npc system is without talaturens's update) and I have something like this:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

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 focus(cid)
 if(npcHandler.focus ~= cid) then
   return 0
 end
for k,v in pairs(npcHandler.focus) do 
 if v == focus then
    table.remove(npcHandler.focus, k) break 
 end
end 
npcHandler:updateFocus()
end

function creatureSayCallback (cid, type, msg)

         if msgcontains(msg:lower(),'stop') then
             addEvent(focus, 1000, cid)
         end
         return 1
end

npcHandler:addModule(FocusModule:new())
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Console error:

Code:
[20/04/2011  13:58:48] Lua Script Error: [Npc interface] 
[20/04/2011  13:58:48] in a timer event called from: 
[20/04/2011  13:58:48] data/npc/scripts/aruda.lua:onCreatureSay

[20/04/2011  13:58:48] data/npc/scripts/aruda.lua:17: bad argument #1 to 'pairs' (table expected, got number)
[20/04/2011  13:58:48] stack traceback:
[20/04/2011  13:58:48] 	[C]: in function 'pairs'
[20/04/2011  13:58:48] 	data/npc/scripts/aruda.lua:17: in function <data/npc/scripts/aruda.lua:13>
 
replace
Code:
for k,v in pairs(npcHandler.focus) do 
 if v == focus then
    table.remove(npcHandler.focus, k) break 
 end
end
with npcHandler.focus = 0
 
It works only when 1 npc is on the server. When i create another else, seems like "npcHandler:updateFocus()" stops working.(Npc is unfocused but he doesn't move)

It's this function in my npchandler.lua:
Code:
	function NpcHandler:updateFocus()
		doNpcSetCreatureFocus(self.focus)
            end

What causing that?
 
Last edited:
Back
Top