• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Help] Npc Talk Delay

tarjei

Necronian Engineer
Joined
May 25, 2008
Messages
504
Reaction score
126
Location
Poland
Hello. ;p
My question is:
Can make it with delay?
Example:
Text1 after 1sec
Text2 after 2sec
Etc.


Code:
		selfSay('Text1') 

		selfSay( 'Text2' ) 
    
	        selfSay('Text3')
 
Last edited:
Hello. ;p
My question is:
Can make it with delay?
Example:
Text1 after 1sec
Text2 after 2sec
Etc.


Code:
		selfSay('Text1') 

		selfSay( 'Text2' ) 
    
	        selfSay('Text3')
Hey, from what I understand: selfSay("text", target) is how it works.

NPC now talks in channels, to different players same time if I'm not mistaken.

I've created this small, untested, script:
Code:
local ispiro_npc_delay = {}
function say(text, target)
	local cid = getNpcCid()
	local delay = ispiro_npc_delay[cid][target] or getWorldUpTime()
	if(getWorldUpTime() >= delay) then
		selfSay(text, target)
		ispiro_npc_delay[cid][target] = getWorldUpTime()+1
	else
		addEvent(say, 250, text, target) -- try again in a second?
	end
end

It's probably not what you want exactly, but thought maybe it might give someone an idea.

Sorry I couldn't help much. However, if you wish not to use the script for the latest 'chat channels', then this script might be what you want:

Code:
local ispiro_npc_delay = {}
function say(text)
	local cid = getNpcCid()
	local delay = ispiro_npc_delay[cid] or getWorldUpTime()
	if(getWorldUpTime() >= delay) then
		selfSay(text)
		ispiro_npc_delay[cid] = getWorldUpTime()+1
	else
		addEvent(say, 250, text) -- try again in a second?
	end
end

say('Text1') -- says the text, and sets the last time npc spoke
say('Text2') -- attempts to say text, but fails, so tries again later
say('Text3') -- same as above
 
I guess he just wanted:
selfSay("text1", cid)
addEvent(selfSay, 1000, "text2", cid)
addEvent(selfSay, 2000, "text3", cid)

Dunno if its the correct form of addEvent tho :(
 
I guess he just wanted:
selfSay("text1", cid)
addEvent(selfSay, 1000, "text2", cid)
addEvent(selfSay, 2000, "text3", cid)

Dunno if its the correct form of addEvent tho :(
Yea, I thought of that, but what if he doesn't want it in that order, but the order player requests it.

For example:
Player: Hi
NPC: Hello
Player: Quest
NPC: Sorry, I don't have a quest for you //1 second before speaking from last msg
Player: Hi
NPC: I'm already talking to you //1 second again

Player: Hi
NPC: Hello
Player: Hi
NPC: I'm already talking to you //1 second from last message,
Player: Quest
NPC: Sorry, I don't have a quest for you //again, 1 second from last message

It wouldn't work if you just use addEvents inside the npc script itself.
 
I wanted something like Story teller ^^ with a pause before next 'SelfSay'. I Tried it with addEvent but then few npc are talking :?
Text1 after 1sec
Text2 after 2sec
Etc.


Code:

selfSay('Text1')

selfSay( 'Text2' )

selfSay('Text3')

With addevents one npc Say text1 after delay another random npc say text2 etc ;/
 
I'm not using my computer at the moment, so the script might seem a bit messy.

Code:
function say(cid, text)
    doCreatureSay(cid, text)
end

selfSay('Text1')
addEvent(say, 1000, getNpcCid(), 'Text2')
addEvent(say, 2000, getNpcCid(), 'Text3')
addEvent(say, 3000, getNpcCid(), 'Text4')

-- an alternative can be:
local text = {"text1", "text2", "text3", "text4"}
for i, v in ipairs(text) do
     addEvent(say, (i*1000)-1000, getNpcCid(), v)
end

Hope I helped,
Ispiro.
 
Nah it doesnt work :(
There is bug which says "addevent : a parameter should be a function" or something like that.

Maybe someone have a function getNpcCid()? :PP
I think i should add it into functions.lua

Btw. Im using TFS 0.3
 
Last edited:
Nah it doesnt work :(
There is bug which says "addevent : a parameter should be a function" or something like that.

Maybe someone have a function getNpcCid()? :PP
I think i should add it into functions.lua

Btw. Im using TFS 0.3
Well, I'm not sure really what's the problem.

But just an idea, try using this instead:
Code:
function say(param)
    doCreatureSay(param.cid, param.text)
end

selfSay('Text1')
addEvent(say, 1000, {cid = getNpcCid(), text = 'Text2'})
addEvent(say, 2000, {cid = getNpcCid(), text = 'Text3'})
addEvent(say, 3000, {cid = getNpcCid(), text = 'Text4'})

If this doesn't work, please send me the whole script, and sentences you want the NPC to say. I promise it'll stay private, and that way I'll have a better chance of seeing that I'm doing wrong.
 
Back
Top