• 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!

Lua NPC delay problem

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
I use this function to make NPC's delays:

LUA:
function doCreatureSayWithDelay(cid,text,type,delay,e,cid)
	if delay<=0 then
		doCreatureSay(cid,text,type, false,cid)
	else
		local func=function(pars)
			doCreatureSay(pars.cid,pars.text,pars.type, false,pars.cid)
			pars.e.done=TRUE
		end
		e.done=FALSE
		e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e,cid=cid})
	end
end
 
function doNPCTalkALot(msgs,interval,cid)
	local e={}
	local ret={}
	if interval==nil then interval=6000 end --6 seconds is default time between messages
		for aux=1,table.getn(msgs) do
		e[aux]={}
		doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_MONSTER,(aux-1)*interval,e[aux],pcid)
		table.insert(ret,e[aux])
	end
	return(ret)
end
LUA:
doNPCTalkALot({"Message 1", "Message 2", "Message 3", "So on"},3000,cid)

The problem is, when someone is chatting with the NPC, everyone can see it... For example:

http://i51.tinypic.com/5xuz2u.jpg
(link to image, 'cause it's kinda big)

Trust me, I really tried to fix it, it's not about lazyness.. 'Been trying here for +1 hour and no success, I'm frustrated :s
 
LUA:
function doNPCTalkALot(msgs, interval, pcid)
	interval = interval or 6000
	local cid = getNpcCid()
	for i = 1, #msgs do
		if i == 1 then
			doCreatureSay(cid, msgs[1], TALKTYPE_MONSTER, false, pcid)
		else
			addEvent(doCreatureSay, (i-1)*interval, cid, msgs[i], TALKTYPE_MONSTER, false, pcid)
		end
	end
end
 
Last edited:
Hmm... Unfortunately problem persists..

I've changed TALKTYPE_MONSTER to TALKTYPE_PRIVATE_NP, as it is the correct one.. I've put MONSTER when trying to fix the script, I was trying to debug it lol
 
Hmm, really?

What do you think it could be?

I've tried to change

doCreatureSay with, npchandler:say (error on console, npc didn't answer) and selfsay (same thing as docreaturesay)

I don't know if it's of any use, but here's some functions envolving say:

npc.lua:
LUA:
function selfSayChannel(cid, message)
	return selfSay(message, cid, false)
end

npchandler.lua
LUA:
	function NpcHandler:onCreatureSay(cid, class, msg)
		local callback = self:getCallback(CALLBACK_CREATURE_SAY)
		if(callback == nil or callback(cid, class, msg)) then
			if(self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, class, msg)) then
				if(not self:isInRange(cid)) then
					return
				end

				if(self.keywordHandler ~= nil) then
					if((self:isFocused(cid) and (class == TALKTYPE_PRIVATE_PN or NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT)) or not self:isFocused(cid)) then
						local ret = self.keywordHandler:processMessage(cid, msg)
						if(not ret) then
							local callback = self:getCallback(CALLBACK_MESSAGE_DEFAULT)
							if(callback ~= nil and callback(cid, class, msg)) then
								if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
									self.talkStart[cid] = os.time()
								else
									self.talkStart = os.time()
								end
							end


						else
							if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
								self.talkStart[cid] = os.time()
							else
								self.talkStart = os.time()
							end
						end
					end
				end
			end
		end
	end

LUA:
	-- Makes the npc represented by this instance of NpcHandler say something.
	--	This implements the currently set type of talkdelay.
	--	shallDelay is a boolean value. If it is false, the message is not delayed. Default value is false.
	function NpcHandler:say(message, focus, shallDelay)
		local shallDelay = shallDelay or false

		if(NPCHANDLER_TALKDELAY == TALKDELAY_NONE or not shallDelay) then
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				selfSay(message, focus)
				return
			else
				selfSay(message)
				return
			end

What NPC lib do you use? What REV version? I'm using 3884 (I was VIP 'til december 2010)
 
Why you don't use
Code:
npcHandler:say(message, focus, [COLOR="red"]shallDelay[/COLOR])

Ex:
Code:
npcHandler:say("Bla bla bla", cid, 3000) --message will be sended after 3 seconds
 
Cyk

NPC.lua

Darkhaos, all my quest npcs uses talkalot :s

if it works and I can't make it with talkalot, I'll try it :]] thanks

-- Darkhaos --

I haven't used this function 'cause I heard it doesn't work properly, and it really does not... It does not delay the message, I've tried with many different values and the delay was always about 1 second but, it shows only to the player npc is focused to, not to everyone in the screen

-- CYK --

OK IT's working!!!!

I've put the function in the NPC file and it works!! Where should I put then to be a global function? I was trying in NPC.lua
 
Last edited:
Why you don't use
Code:
npcHandler:say(message, focus, [COLOR="red"]shallDelay[/COLOR])

Ex:
Code:
npcHandler:say("Bla bla bla", cid, 3000) --message will be sended after 3 seconds
shallDelay is a boolean, so only true/false is available
I've put the function in the NPC file and it works!! Where should I put then to be a global function? I was trying in NPC.lua
maybe you have old versions of the script inside some NPC files, so try to remove it from ALL lua scripts and only leave it inside npc.lua
 
Back
Top