• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Delay for npcs talking, and more.

tarjei

Necronian Engineer
Joined
May 25, 2008
Messages
505
Reaction score
126
Location
Poland
-------------------------------------------------
Hello there. I didnt see any threads about this type of "delay" anymore, but maybe somebody still needs that.

It is little sucky, but its working for sure. Unless you dont get what is under PM me ;]

USAGE:
If you have 2 npcs and you want put disconect function in both of them you HAVE to do like that:
In FIRST npc you put
Code:
	function disconect[B]1[/B](param)
        (REST OF CODE THERE)
        function delayedDisconect[B]1[/B](cid, delay)
        (REST OF CODE THERE)
Likewise in second
Code:
	function disconect[B]2[/B](param)
        (REST OF CODE THERE)
        function delayedDisconect[B]2[/B](cid, delay)
        (REST OF CODE THERE)

Instead 1 and 2 you can put whatever you want but I have to warn you that if you won't do this like I showed you this might couse some side effects; ( I think you remember that another random npc was talking instead that which we wanted to talk :p )

I hope you got what I mean ^^

(SOMETHING LIKE 'bye' keyword but without words usage :p)
Code:
		function disconect(param)
			npcHandler:releaseFocus(param.cid)
		end
		
		function delayedDisconect(cid, delay)
			if(not npcHandler:isFocused(cid)) then
      	    		  return FALSE
			 else
				local delay = delay or 0
				local cid = cid or 0
	
				local param = {cid = cid}
				addEvent(disconect1, delay, param)
			end
		end
----------------------------------------------
----------------------------------------------
DELAYED NPC TALKING ( I MEAN LONG STORIES FOR EXAMPLE)
Code:
         function say(param)
            npcHandler:say(param.text,param.cid)
         end
	function delayedSay(text, delay, cid)
	if(not npcHandler:isFocused(cid)) then
      	      return FALSE
	 else
         local param = {cid = cid, text = text}
			local delay = delay or 0
			local cid = cid or 0
			local nid = getNpcCid()
			addEvent(say, delay, param)


		end
	end
--------------------------------------------
----------------------------------------------

DELAYED ITEM RECIEVING
Code:
	function item(param)
	if(not npcHandler:isFocused(cid)) then

      	item = doCreateItemEx(param.id,param.subtype)
	doPlayerAddItemEx(param.cid, item, 1)	     
			
		end
  	 
return FALSE
 end

		function additem(cid, id, count, delay, subtype)
local param = {cid = cid, id = id}
			local delay = delay or 0
			local cid = cid or 0
			local nid = getNpcCid()
			local count = count or 0
			local subtype = subtype or 0
			addEvent(item, delay, param)
			
		end
----------------------------------------------
DELAYED TALK_STATE SET (IN STORAGE VALUE)
Code:
		function talk_sstate(param)
      	      			setPlayerStorageValue(param.cid,param.key,param.value)
			
		end

	function delayedts(value, key, delay, cid)
	if(not npcHandler:isFocused(cid)) then
      	      return FALSE
	 else
local param = {cid = cid, value = value, key = key}
			local delay = delay or 0
			local cid = cid or 0
			local nid = getNpcCid()
			local key = key or 0
			addEvent(talk_sstate, delay, param)


		end
	end
---------------------------------------------
 
Why, there isn't any replies? xD
Someone can tell is it working to him ? :p
 
I need help, I cant put it to work

PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end


function creatureSayCallback(cid, type, msg)



     if msgcontains(msg, 'history') then

     selfSay('part1')
     selfSay('part2')     
     selfSay('part3')
     selfSay('part4')


     end


     elseif msgcontains(msg, 'quest') then
             if getPlayerStorageValue(cid, 5001) == -1 then
                    setPlayerStorageValue(cid, 5001, 1)
                    selfSay('You must kill 30 rats and then come here again for a reward')
                           
             elseif getPlayerStorageValue(cid, 5001) == 2 then
					setPlayerStorageValue(cid, 5001, 3)
					doPlayerAddItem(cid,5887,1)
					selfSay('GRATZ')
              else
                    selfSay('I dont have anymore quests for you. ')
                  
             end
   
     end

return true
end


local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'health potion'},			7618, 45,	'health potion')-------------------------------
shopModule:addBuyableItem({'mana potion'},			7620, 50,	'mana potion')----------------------------------------
shopModule:addBuyableItem({'heavy magic missile'},		2311, 150, 10,	'heavy magic missile rune')
shopModule:addBuyableItem({'blank', 'rune'},				2260, 10,	'blank rune')
shopModule:addBuyableItem({'spellbook'}, 				2175, 150,	'spellbook')
shopModule:addBuyableItemContainer({'bp hmm'}, 2001, 2311, 2500, 10, 'backpack of heavy magic missile')


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
OK I test like this and it didn't work like I suppose

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end


function say1(param)
            npcHandler:say(param.text,param.cid)
end

function delayedSay1(text, delay, cid)
	if(not npcHandler:isFocused(cid)) then
      	      return FALSE
	 else
         local param = {cid = cid, text = text}
			local delay = delay
			local cid = cid
			local nid = getNpcCid()
			addEvent(say1, delay, param)


		end
end

function creatureSayCallback(cid, type, msg)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
	

     if msgcontains(msg, 'quest') then
             if getPlayerStorageValue(cid, 10004) == -1 then
                    setPlayerStorageValue(cid, 10004, 1)
                    selfSay('You must kill 50 wolfs and then come here again for a reward')
                           
             elseif getPlayerStorageValue(cid, 10004) == 2 then
					setPlayerStorageValue(cid, 10004, 3)
					doPlayerAddItem(cid,5886,1)
					selfSay('GRATZ')
              else
                    
					delayedSay1('you allready have done all my quests',15,cid)
					delayedSay1('so you need to find other things to do',30,cid)
			

                  
             end
   
     end

return true
end






local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)




shopModule:addBuyableItem({'health potion'},			7618, 45,	'health potion')-------------------------------


shopModule:addBuyableItem({'mana potion'},			7620, 50,	'mana potion')----------------------------------------

shopModule:addBuyableItem({'heavy magic missile'},		2311, 150, 10,	'heavy magic missile rune')

shopModule:addBuyableItem({'blank', 'rune'},				2260, 10,	'blank rune')
shopModule:addBuyableItem({'spellbook'}, 				2175, 150,	'spellbook')

shopModule:addBuyableItemContainer({'bp hmm'}, 2001, 2311, 2500, 10, 'backpack of heavy magic missile')


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I tested the delayed npc talk function and receive this error

Code:
[16/04/2009 18:23:35] Lua Script Error: [Npc interface] 
[16/04/2009 18:23:35] data/npc/scripts/talk.lua:onCreatureSay

[16/04/2009 18:23:35] data/lib/function.lua:853: attempt to index global 'npcHandler' (a nil value)
[16/04/2009 18:23:35] stack traceback:
[16/04/2009 18:23:35] 	data/lib/function.lua:853: in function 'delayedSay'
[16/04/2009 18:23:35] 	data/npc/scripts/talk.lua:16: in function 'callback'
[16/04/2009 18:23:35] 	data/npc/lib/npcsystem/npchandler.lua:384: in function 'onCreatureSay'
[16/04/2009 18:23:35] 	data/npc/scripts/talk.lua:7: in function <data/npc/scripts/talk.lua:7>

Btw: line 853 is this row

Code:
if(not npcHandler:isFocused(cid)) then

Here is how i tryed to use it

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                         npcHandler:onThink() end  
  
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return FALSE
	end

	if msgcontains(msg, 'quest') then
					delayedSay('msg1',15,cid)
					delayedSay('msg2',30,cid)


		end
end

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



Anyone know how i can solve this error? :p

//Massen
 
Last edited:
Code:
--------------------------------------
DELAYED NPC TALKING ( I MEAN LONG STORIES FOR EXAMPLE)
Code:

		
         function say(param)
            npcHandler:say(param.text,param.cid)
         end
	function delayedSay(text, delay, cid)
	if(not npcHandler:isFocused(cid)) then
      	      return FALSE
	 else
         local param = {cid = cid, text = text}
			local delay = delay or 0
			local cid = cid or 0
			local nid = getNpcCid()
			addEvent(say, delay, param)


		end
	end
--------------------------------------------

mensage random npc ... How to solve?:confused:
 
Back
Top