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

addEvent on SlefSay[NPC]

Pitufo™

InfinityOT.com
Joined
Feb 14, 2008
Messages
1,438
Reaction score
10
Location
Mexico, Cuernavaca
Can somone give me an example for addEvent on Selfsay for NPC...

Ive tried alot of things, the only one workings is using like this:

addEvent(selfsay, 5000, cid)

The addEvent works but the NPC im talking too doesnt say the addEvent is another NPC that tell me the addEvent LOL,

Also ive tried with:

addEvent(selfsay, 5000, getNpcCid())
addEvent(selfsay, 5000, {cid=getNpcCid()})

And many other things...

Im using TFS 0.3 Beta 2
 
nah, send him a pm, he ve got a function to PAUSE scripts, example...

selfsay(hunted)
--pause 5 secs
selsay(just joking)

Won't work for NPC since it basically does same as addEvent, but just easier :p

I do indeed know that the current NPC system does allow you to send messages with delay... Not sure how though, but it is possible :)

My sleep function to "pause" the script is not 100% done yet so it won't work for NPC's...
 
Won't work for NPC since it basically does same as addEvent, but just easier :p

I do indeed know that the current NPC system does allow you to send messages with delay... Not sure how though, but it is possible :)

My sleep function to "pause" the script is not 100% done yet so it won't work for NPC's...


o_O didn't know it have that.. I have been searching around in the files too find something like this and i'v never seen it...

If anyone finds out how to add events without AddEvent then please let me know :D

//Massen
 
doCreatureSay will only write in default and not in NPC channel, and if it can send in NPC channel you can't add those dark blue texts?
 
Lua:
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 --default delay between msgs if not specified.
  for aux=1,table.getn(msgs) do
      e[aux]={}
      doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux])
      table.insert(ret,e[aux])
  end
  return(ret)
end

 -- example of usage
	local msgs={
			"msg text. ...",
			"msg text. ...",
			"msg text."
	}
    doNPCTalkALot(msgs,6500)
 
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

function greetCallback(cid)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
Topic[talkUser] = 0
return true
end

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_PRIVATE_NP,(aux-1)*interval,e[aux])
table.insert(ret,e[aux])
end
return(ret)
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local namee = getPlayerName(cid)

if msgcontains(msg, 'name') or msgcontains(msg, 'Name') then
npcHandler:say("My name is Marlene.", cid)
Topic[cid] = nil
elseif msgcontains(msg, 'job') or msgcontains(msg, 'Job') then
npcHandler:say("I'm Bruno's wife. Besides: Have you already heard the latest news about the seamonster, Aneus, or the rumours in this area?", cid)
Topic[cid] = nil
elseif msgcontains(msg, 'bruno') or msgcontains(msg, 'Bruno') then
npcHandler:say("Bruno is a wonderful husband. But he is seldom at home. *looks a little bit sad*", cid)
Topic[cid] = nil
elseif msgcontains(msg, 'Graubart') or msgcontains(msg, 'graubart') then
npcHandler:say("Ah, old Graubart. A very nice person. But he is strange. He always is busy when I want to talk to him. *lost in thoughts*", cid)
Topic[cid] = nil
elseif msgcontains(msg, 'seamonster') or msgcontains(msg, 'Seamonster') then
local msgs={
"Only some days ago I was at the docks late in the night and was looking for my husband's ship when suddenly a known noise appeared near the docks. ...",
"I know this noise very well because it is the noise of a ship sailing very fast. I searched the horizon in hope to see my husbands ship. ...",
"But instead of a ship I saw a huge shape far away. It was like a big snake swimming in the sea. ...",
"I couldn't see it clearly because of the fog but I think I saw two lava-red eyes glowing in the nightly fog. ...",
"I ran into the house and hoped that my husband would arrive safely from fishing. And after one hour he finally arrived. ...",
"I told him about what I saw but he didn't believe me because he never saw anything like that in all the years before. But you believe me right? Go and convince yourself. ...",
"Just go to the docks at exactly midnight and be very quiet. Look at the horizon and maybe you will hear and see it, too!",
}
doNPCTalkALot(msgs,7052)
Topic[cid] = nil
elseif msgcontains(msg, 'aneus') or msgcontains(msg, 'Aneus') then
local msgs={
"A very nice person. He has a great story to tell with big fights and much magic. Just ask him for his story. ...",
"I heard that he came from far, far away. He must have seen soooo many countries, cities, different races. ...",
"He must have collected so much wisdom. *sigh* I wish I could also travel around the world. ...",
"I would try to visit as many cities and meet as many beings as possible. Who knows what strange races I will meet? ...",
"Maybe I can also find a lovely new dress for me. I have been looking for one for months now but never found a good one. Maybe... *keeps on babbling*",
}
doNPCTalkALot(msgs,7052)
Topic[cid] = nil
elseif msgcontains(msg, 'rumours') or msgcontains(msg, 'Rumours') then
local msgs={
"Well, I heard about evil beings living in a dungeon below us. So once I tried to find them and went down the hole far to the southwest. ...",
"I'm pretty curious, you know. *smiles* So I took the coat of invisibility from my husband and went down there. At first I only found some spiders, snakes, and wolves. ...",
"But after some time I found a ladder to a deeper level of the dungeon but I didn't dare to go down there because I heard many voices. ...",
"The voices were very strange and I ran back to my house because they were very loud and very angry. I hope they will never get the idea to attack the surface beings. ...",
"I heard they are almighty and have incredible powers! I already packed our stuff for an emergency escape. You never know. Maybe they plan to conquer the whole world. ...",
"I bet that they look very ugly. Most mighty monsters look very ugly. Hmm, you seem to be very strong. Maybe you can go deeper and explore the area. But be careful, please. ...",
"I heard that they can kill humans with only one hit! And that they have magic abilities twenty times stronger than the mightiest sorcerer in our world.",
}
doNPCTalkALot(msgs,7052)
Topic[cid] = nil
elseif msgcontains(msg, 'thank you') or msgcontains(msg, 'Thank You') then
npcHandler:say("My pleasure, I always enjoy sharing interesting stories..", cid)
Topic[cid] = nil
end
return true
end

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



If i use this all people around me get the same npc channel as i do if i say something that has a doNPCTalkALot, its just me who should see the conversation but if someone stand beside it opens a npc channel for him to.
 
weakly made, but can be edited i guess
Lua:
function doCreatureSayWithDelay(cid, text, type, delay, e)
	if delay <= 0 then
		doCreatureSay(getNpcCid(), text, type, false, cid, getNpcPos())
	else
		local func = function(pars)
			doCreatureSay(getNpcCid(), pars.text, pars.type, false, pars.cid, getNpcPos())
			pars.e.done = true
		end
		e.done = false
		e.event = addEvent(func, delay, {cid=cid, text=text, type=type, e=e})
	end
end
 
I'm necro-ing a old thread to provide a solution that I think is the answer the poster was looking for. While I realize after 10 years he definitely doesn't need this script anymore, hopefully this helps someone later down the road.

Replace oculeth in various places with whatever your NPC name is.

if npcHandler.topic[cid] == 5 then
if player:removeTotalMoney(10000) then
player:setStorageValue(Storage.TeleportationQuest, 4)
local oculeth = getNpcCid()
addEvent(function() doCreatureSay(oculeth, 'Wonderful. I will attune you right now. Stand still for a moment..', TALKTYPE_PRIVATE_NP,true) end, 1000)
addEvent(function() player:getPosition():sendMagicEffect(CONST_ME_YALAHARIGHOST) end, 5000)
addEvent(function() doCreatureSay(oculeth, 'Almost done, stop fidgetting.', TALKTYPE_PRIVATE_NP,true) end, 9000)
addEvent(function() player:getPosition():sendMagicEffect(CONST_ME_YALAHARIGHOST) end, 12000)
addEvent(function() player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) end, 15000)
addEvent(function() doCreatureSay(oculeth,'There! You are attuned. You will be able to access the major leyline downstairs....', TALKTYPE_PRIVATE_NP,true) end, 16000)
addEvent(function() doCreatureSay(oculeth,'Uhh, It\'s natural to feel a bit ..lighter.. for a short time after the attunement process.', TALKTYPE_PRIVATE_NP,true) end, 20000)
npcHandler.topic[cid]= 0
 
Slight correction because I noticed that script makes it talk to all players in the area... So here's the actual working version.
I added cid


Lua:
        elseif npcHandler.topic[cid] == 5 then
            if player:removeTotalMoney(10000) then
                player:setStorageValue(Storage.TeleportationQuest, 4)
                local oculeth = getNpcCid()
                addEvent(function()    doCreatureSay(oculeth, 'Wonderful. I will attune you right now. Stand still for a moment..', TALKTYPE_PRIVATE_NP, true, cid) end, 1000)
                addEvent(function()    player:getPosition():sendMagicEffect(CONST_ME_YALAHARIGHOST) end, 5000)   
                addEvent(function()    doCreatureSay(oculeth, 'Almost done, stop fidgetting.', TALKTYPE_PRIVATE_NP, true, cid) end, 9000)
                addEvent(function()    player:getPosition():sendMagicEffect(CONST_ME_YALAHARIGHOST) end, 12000)
                addEvent(function()       player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) end, 15000)
                addEvent(function()   doCreatureSay(oculeth,'There! You are attuned. You will be able to access the major leyline downstairs....', TALKTYPE_PRIVATE_NP, true, cid) end, 16000)
                addEvent(function()   doCreatureSay(oculeth,'Uhh, It\'s natural to feel a bit ..lighter.. for a short time after the attunement process.', TALKTYPE_PRIVATE_NP, true, cid) end, 20000)
                npcHandler.topic[cid]= 0
 

Similar threads

Back
Top