• 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 talkdelay + talkstate

Massen

Masserv RPG
Joined
Jul 23, 2007
Messages
324
Reaction score
1
Location
Sweden
Hello, Im using a functions for my npcs when telling long stories. Im not sure who the author of the function(s) is but all credit goes to him.

However I need help modifing this function to set a talkstate once all messages are printed

for example

Npc: I live here (3sec)
Npc: In my house (6sec)
Npc: Im happy here (9sec)
talkstate=5 (10 sec)

this is how the delay and npc text is working inside a script


Code:
local missionX={"","",""}



if msgcontains(msg, 'mission') and quest==2 then
    talk_var=doNPCTalkALot(missionX,DELAY)
end
and here is the function I currently use

Code:
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_SAY,(aux-1)*interval,e[aux])
      table.insert(ret,e[aux])
  end
  return(ret)
end
So what I need is a function or something similar that sets "talkstate=X" in a configurable way after a set time inside a npc script.


Thanks in advance


//Massen
 
Why dont you use that functions and instead of setting each message from 3 to 6 to 9 secs, all with a 5 seconds delay?
 
I dont think you understand me, what I basicly need is a function that sets talkstate==X after a configurable time, X should also be configurable

for example

setNpcTalkstate(10,5)

10 is the delay
5 is the talkstate

So the function sets talkstate==5 after 10 seconds.

If anyone attempts too create such function I'd really apreaciate a function that adds a configurable item after a configurable time aswell

such as:

doPlayerAddItemWithDelay(cid,1347,10)

add item 1347 after 10 seconds


cheers

//Massen
 
Why not simply use addEvent?
Lua:
addEvent(function(cid) if isPlayer(cid) then talkState[cid] = 5 end end, 10000, cid)
 
I didn't know that I could do it that way o_O I was thinking that only functions would fit inside addEvent =P

Ill try it and edit this post :) thanks alot of the help Cykotian.

Alright I tested it with this code

Lua:
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return FALSE
	end
		if msgcontains(msg, 'mission') then
			selfSay('first')
				addEvent(function(cid) if isPlayer(cid) then talkState[cid] =2 end end, 10000, cid)
		end
			if msgcontains(msg, 'yes') and talkstate==2 then
				selfSay('works')
			end

end

He will reply to "mission" and 10 seconds after that this error prints and no reply to "yes"

Code:
[23/11/2010 15:12:15] Lua Script Error: [Npc interface] 
[23/11/2010 15:12:15] in a timer event called from: 
[23/11/2010 15:12:15] data/npc/scripts/max test.lua:onCreatureSay

[23/11/2010 15:12:15] data/npc/scripts/max test.lua:16: attempt to index global 'talkState' (a nil value)
[23/11/2010 15:12:15] stack traceback:
[23/11/2010 15:12:15] 	data/npc/scripts/max test.lua:16: in function <data/npc/scripts/max test.lua:16>

And another question, is it possible for talkstate too be local? as I use it in alot of npcs :p

//Massen
 
Last edited:
And another question, is it possible for talkstate too be local? as I use it in alot of npcs :p

Variables aren't shared among scripts, unless in lib.
About the error, are you sure it's defined with the exactly same name? Character case matters.
 
Nvm I solved it =) changed

addEvent(function(cid) if isPlayer(cid) then talkState=2 end end, 10000, cid)

by removing [cid] after talkState.

It works perfectly now :D thanks alot for your help. + rep
 
Aha, you don't store talkState for each cid, so I suppose you're using an older Tibia client version or not using NPC channel. :p
Otherwise, it must be a table or else talkStates of different players will conflict.
 
Back
Top