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

Solved How to stop NPC from executing function2 inside function1 and vice versa?

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
my code:

Lua:
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

local function greetCallback(cid)
    local player = Player(cid)
 
    npcHandler:say("Hello, activate {test1} or {test2}. Thank you.", cid)
    npcHandler:addFocus(cid)
    return false
end

local function test1(cid)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    print("test 1 has been executed! You should NOT be able to type 'test2' now and execute another function.")
    return true
end

local function test2(cid)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    print("test 2 has been executed! You should NOT be able to type 'test1' now and execute another function.")
    return true
end
 


local test1 = keywordHandler:addKeyword({"test1"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Are you sure you want to execute test1?"})
    test1:addChildKeyword({"yes"}, test1, {})
    test1:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "OK, test1 has NOT been executed", reset = true})

local test2 = keywordHandler:addKeyword({"test2"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Are you sure you want to execute test2?"})
    test2:addChildKeyword({"yes"}, test2, {})
    test2:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "OK, test2 has NOT been executed", reset = true})
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())

I am using tfs 1.0

EDIT -- FIXED

Just use this function:

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

with topic cids:

npcHandler.topic[cid] = 0/1/2/3/4/5 etc.
 
Last edited:
Back
Top