• 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] Very little question

Glecko

Veteran OT User
Joined
Aug 21, 2007
Messages
1,054
Reaction score
270
Location
Spain
EDIT: First Question solved

Second question: How do I make npcs say messages in default when they aren't talking to anyone (speak alone, like Melchior in Ankrahmun)

I know that it works with "voices", but I can't figure out how it works. interval,interval2,margin, what do they change in the voice?

Thanks a lot in advance :)
 
Last edited:
First:
Code:
selfSay({'What? Who are you to imply I need help from a worm like you? ...', 'I don\'t need help. But if you desperately wish to do something to earn the favour of Zathroth, feel free. Don\'t expect any reward though. ...', 'Do you want to help and serve Zathroth out of your own free will, without demanding payment or recognition?'}, cid)
			Topic[cid] = 1

This is the answer of your second question (researching the first one).
Code:
<voices>
<voice text="Come have a drink in the Hard Rock Racing Track." interval2="120" margin="1" yell="no"/>
</voices>
 
PHP:
local keywordHandler = KeywordHandler:new() 
local npcHandler = NpcHandler:new(keywordHandler) 
NpcSystem.parseParameters(npcHandler) 
local talkState = {} 
  
-- OTServ event handling functions start 
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 
-- OTServ event handling functions 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 


function creatureSayCallback(cid, type, msg) 
    if(not npcHandler:isFocused(cid)) then 
        return false 
    end 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid 

    elseif(msgcontains(msg, 'Mission') or msgcontains(msg, 'mission')) then
local msgs={ 
            "blaaaaa. ...", 
            "bla bla bla. ...", 
            "bla bla bla bla bla bla!" 
             } 
      doNPCTalkALot(msgs,6500)

end 
    return TRUE     
end 

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

test this
 
This is the answer of your second question (researching the first one).
Code:
<voices>
<voice text="Come have a drink in the Hard Rock Racing Track." interval2="120" margin="1" yell="no"/>
</voices>


I cannot figure out how this works, the npc keeps spamming the wrong message. What does margin have as a effect?
 
Back
Top