• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua NPC questions (8.54)

Tekno92

New Member
Joined
Jun 7, 2011
Messages
15
Reaction score
2
Hi thar. I've got several questions I'd like to ask you about NPCs and the functions.

1. What should I type if I want the NPC to speak on his own (no need to say 'hi')
2. What to do if I want the NPC to react on 'hi' but don't focus on the player (and don't say that I'm rude if I walk away)

All answers will be appreciated!:D
 
1.Heres example of Towncryer that yells on his own ;p
LUA:
 local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
-- 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
 
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:addModule(FocusModule:new())
 
function onThink()
talk = math.random(1,100)
        if talk == 1 then
                doCreatureSay(getNpcCid(), "Hear me! Hear me! The mage Wyrdin in the Edron academy is looking for brave adventurers to undertake a task!", TALKTYPE_YELL)
        elseif talk == 50 then
                doCreatureSay(getNpcCid(), "Hear me! Hear me! The postmaster's guild has open spots for aspiring postmen! Contact Kevin Postner at the post office in the plains south of Kazordoon!", TALKTYPE_YELL)
        elseif talk == 100 then
                doCreatureSay(getNpcCid(), "Hear me! Hear me! The inquisition is looking for daring people to fight evil! Apply at the inquisition headquarters next to the Thaian jail!", TALKTYPE_YELL)
        end
        npcHandler:onThink()
end 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

2. to remove farewell message you can remove this line in the npc's xml file
XML:
        <parameter key="message_farewell" value="Good bye, |PLAYERNAME|!"/>
 
Thanks! There's one more thing, the NPC does not say anything in return but I want him not to focus myself, I would just say Hi and he would answer but without stopping, I'll try to find this like myself, thanks a lot!
 
Back
Top