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

[NPC] Problem with doNPCTalkALot

Glecko

Veteran OT User
Joined
Aug 21, 2007
Messages
1,054
Reaction score
270
Location
Spain
I have been using the function doNpcTalkAlot, but I have stummbled upon two problems.
The first one is that if I walk away, the NPC will continue talking.
The second one, everytime the NPC talks, every player in talking range (3 sqm) recieves the message in the NPC window instead of just the player it is inteded to.

If anybody could help me, I would apreciate it a lot :)

Here are the functions I have in npchandler.lua and npc.lua

Code:
function doCreatureSayWithDelay(cid,text,type,delay,e,pcid)
        if delay<=0 then
                doCreatureSay(cid,text,type, false,pcid)
        else
                local func=function(pars)
                        doCreatureSay(pars.cid,pars.text,pars.type, false,pars.pcid)
                        pars.e.done=TRUE
                end
                e.done=FALSE
                e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e,pcid=pcid})
        end
end

function doNPCTalkALot(msgs,interval,pcid)
        local e={}
        local ret={}
        if interval==nil then interval=10000 end --10 seconds is default time between messages
                for aux=1,table.getn(msgs) do
                e[aux]={}
                doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_FROM_NPC,(aux-1)*interval,e[aux],pcid)
                table.insert(ret,e[aux])
        end
        return(ret)
end
 
Bumpers gonna bump

You should make it another way upper functions are sux.

Solution:

Code:
Add in your script for example 1 msg:
local a = {npc = getNpcCid()}
eMsg1 = addEvent(Msg1,2000,a)
--- remember to use different msg names like eMsg1,eMsg2,eMsg3 even in another npc always.

Also use stopevent when someone walk away from npc or saying bye example:

function Msg1(a)
doCreatureSay(a.npc,"All right then, human. Have you ever heard of the 'Tears of Daraman'? ...",1)
end

npcHandler:setCallback(CALLBACK_FAREWELL, NpcWalkAway)

function NpcWalkAway(cid)
 stopEvent(eMsg1)
 return 1
end
 
Isn't there any way to 'repair' doNPCtalkalot? I have already made 100+ NPCs, and they all use donpctalkalot. By using your function i would need to re-script all of them.
 
Back
Top