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

[TFS 1.2] selfSay in addEvent functions makes other npcs to talk

rlx

Well-Known Member
Joined
Feb 25, 2019
Messages
169
Solutions
1
Reaction score
79
Hello,
I'm trying to set a NPC talk with addEvent functions containing selfSay. Unfortunately, it causes other random NPCs on same floor from whole map to say those lines instead of the NPC I'm talking with. Maybe the problem is with talkstates/cid inside addEvent functions?
How it looks when addEvent times are shortened:

npc selfsay.png


The code:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

local node1 = keywordHandler:addKeyword({'promote'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

local node1 = keywordHandler:addKeyword({'promotion'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
    node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
    
keywordHandler:addKeyword({'premium'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy premium by command !buypremium - cost 10k for 2 days.'})



function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
 
    if(msgcontains(msg, 'quest') or msgcontains(msg, 'task') or msgcontains(msg, 'mission') or msgcontains(msg, 'bone key')) then
        if (getPlayerStorageValue(cid,5019)) == 2 then
            selfSay('Ah, I\'m glad you asked. I have hard about your actions in the underground. That inspired me to look farther in my stuff connected with [undeads]..', cid)
            talkState[talkUser] = 1

        elseif getPlayerStorageValue(cid,5019) < 2 then
            selfSay('I think that one day you will become a very strong adventurer. We need people like you, to get rid of endless evil forces which we all are afraid of.', cid)   
        elseif getPlayerStorageValue(cid,5019) > 2 then
            selfSay('Good luck with sending undeads to place, where they truly belong.', cid)
        end
    elseif (msgcontains(msg, 'undead')) then

                selfSay('text1 ', cid)
                addEvent(function()    selfSay('text2', cid) end, 3000)
                addEvent(function()    selfSay('text3', cid) end, 6000)
                addEvent(function()    selfSay('text4', cid) end, 9000)
                addEvent(function()    selfSay('text5', cid) end, 12000)
                addEvent(function() doSetItemActionId(doPlayerAddItem(cid, 2092),301) end, 13000)   
                addEvent(function()    selfSay('text6', cid) end, 15000)
    end
 
 
            talkState[talkUser] = 0

    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I am familiar with this problem. Having the same issue...

If i recall correctly it is because uid data changes of npc's (and items?) every x time?
I haven't tried it out yet but try to use npc's name inside the npc class to get the npc's correct id...

Code:
local cid = Npc("Anifried")

Animera
 
I have found a solution!


Code:
local cid = Npc("Anifried")
This one causes server crash.


Also, I have seen those links before, Evil, and got a core line from here too :)
Here is my solution:
Code:
    elseif (msgcontains(msg, 'undead')) then
local orlan = getNpcCid()  -- this function is the one i didn't see in the tfs 1.2 lua function list and I found it in Evil's link

                selfSay('text1 ')
                addEvent(function()    doCreatureSay(orlan,'text2', TALKTYPE_SAY,true) end, 3000)
                addEvent(function()    doCreatureSay(orlan,'text3.',TALKTYPE_SAY,true) end, 6000)
                addEvent(function()    doCreatureSay(orlan,'text4', TALKTYPE_SAY,true) end, 9000)
                addEvent(function()    doCreatureSay(orlan,'text5', TALKTYPE_SAY,true) end, 12000)
                addEvent(function()    doSetItemActionId(doPlayerAddItem(cid, 2092),301) end, 13000)   
                addEvent(function()    doCreatureSay(orlan,'text6', TALKTYPE_SAY,true) end, 15000)
    end

1580856417883.png

Thanks for your help!
 
Back
Top