Ninkobi
Owner /Founder of Syphera
Well, answering a thread at the Lua & XML help, I've just made a script to make a creature (mostly likely an npc) to say several phrases with a certain delay (like some npcs in real tibia who tells very long stories). I liked the script, and I think that it could be useful to other people too.
I hope that you will like it, it is my first contribution (five cents) at this forum.
As an example of how to use it:
Well, I hope that you all enjoy it.
EDITED: At my home, I put all my functions in a lib (HTLib) and I wrote it here as if I was using this library. I've corrected it now. Also, a small typo has been corrected. I've also removed some debug print messages that I forgot to remove. I've also tested it AGAIN and it is working in clean SVN (I don't see any reason why it shouldn't work in TFS also).
Cheers,
Credits to Assassina Mutante
I hope that you will like it, it is my first contribution (five cents) at this forum.
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
As an example of how to use it:
Code:
local talk_var
function onCreatureSay(cid, type, msg)
local msgs={"first message","second message","third message","4","5","6","7","8","9","10"}
if msg=="hi" then
talk_var=doNPCTalkALot(msgs,2750) --if the 2750 is ommited, it uses 3000 always
else
if (msg=="stop") and (talk_var~=nil) then
local i=cancelNPCTalk(talk_var)
if i<table.getn(msgs) then
selfSay("Afff, but I was about to get into the best part! The part "..i)
else
selfSay("But I have already finished!")
end
end
end
end
Well, I hope that you all enjoy it.
EDITED: At my home, I put all my functions in a lib (HTLib) and I wrote it here as if I was using this library. I've corrected it now. Also, a small typo has been corrected. I've also removed some debug print messages that I forgot to remove. I've also tested it AGAIN and it is working in clean SVN (I don't see any reason why it shouldn't work in TFS also).
Cheers,
Credits to Assassina Mutante