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

A problem with npc

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
870
Solutions
2
Reaction score
49
Hello,
so i did my first working npc script which works just fine but there is one weird problem that i cant figure out how to fix it
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 config = { 
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Sorry if code structure is terrible since im newbie. So there problem is when i type "no" it sends "Oh, well then not!" but it doesnt cancel npc basically i can flood that "no" keyword and it will flood "Oh, well then not!" as well.
TFS 1.2
 
Solution
Hello,
so i did my first working npc script which works just fine but there is one weird problem that i cant figure out how to fix it
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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function...
Hello,
so i did my first working npc script which works just fine but there is one weird problem that i cant figure out how to fix it
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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Sorry if code structure is terrible since im newbie. So there problem is when i type "no" it sends "Oh, well then not!" but it doesnt cancel npc basically i can flood that "no" keyword and it will flood "Oh, well then not!" as well.
TFS 1.2
You can add "topics" to the npc script and if you dont have the right topic id then the npc would ignore the msg

here is an example how i use to do it, whit some comments to explain it roughly.
The rest is up to you to design you npc, you can add as many topic ids as you like

I didnt remove your code from the script just to make it easier for you to see my changes i made
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    Topic[cid] = nil    -- make sure to clear the table when the player disapears from the npc
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                        end

local Topic = {}    -- Stores all the topics in a table
local config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    --[[if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
    end]]

    -- using Topics example by Mummrik
    if msgcontains(msg, 'teleport') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to teleport?", cid)
            Topic[cid] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
        end
    elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
        npcHandler:say("Oh, well then not!", cid)
        Topic[cid] = nil    -- clear the topic
    end

    return true
end

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

Edit:
Btw nice that you use string.format() to get the "config.minLevel" value when you arent high level enough, thats the right way to do it ;)
instead of hardcode the msg string
 
Last edited:
Solution
You can add "topics" to the npc script and if you dont have the right topic id then the npc would ignore the msg

here is an example how i use to do it, whit some comments to explain it roughly.
The rest is up to you to design you npc, you can add as many topic ids as you like

I didnt remove your code from the script just to make it easier for you to see my changes i made
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    Topic[cid] = nil    -- make sure to clear the table when the player disapears from the npc
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                        end

local Topic = {}    -- Stores all the topics in a table
local config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    --[[if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
    end]]

    -- using Topics example by Mummrik
    if msgcontains(msg, 'teleport') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to teleport?", cid)
            Topic[cid] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
        end
    elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
        npcHandler:say("Oh, well then not!", cid)
        Topic[cid] = nil    -- clear the topic
    end

    return true
end

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

Edit:
Btw nice that you use string.format() to get the "config.minLevel" value when you arent high level enough, thats the right way to do it ;)
instead of hardcode the msg string
I though about something like this but wasn't able to figure it out how to apply it. Thanks buddy and appreciate it :)
 
35905
Just noticed in console and for some reason you can skip key word "protect" and just say "hi" "yes" which is a problem to
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    Topic[cid] = nil    -- make sure to clear the table when the player disapears from the npc
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                        end

local Topic = {}    -- Stores all the topics in a table
local config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    -- using Topics example by Mummrik
    if msgcontains(msg, 'protect') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to help?", cid)
            Topic[cid] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
        end
    elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
        npcHandler:say("Very well!", cid)
        doTeleportThing(cid, config.pos)
    elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
        npcHandler:say("Oh, well then not!", cid)
        Topic[cid] = nil    -- clear the topic
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Hello,
so i did my first working npc script which works just fine but there is one weird problem that i cant figure out how to fix it
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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Sorry if code structure is terrible since im newbie. So there problem is when i type "no" it sends "Oh, well then not!" but it doesnt cancel npc basically i can flood that "no" keyword and it will flood "Oh, well then not!" as well.
TFS 1.2
use this
Lua:
npcHandler:releaseFocus(cid)

Here the full 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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
        npcHandler:releaseFocus(cid) --release focus
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
use this
Lua:
npcHandler:releaseFocus(cid)

Here the full 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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if config.minLevel and config.minLevel > 0 and player:getLevel() < config.minLevel then
        npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
    elseif(msgcontains(msg, 'yes')) then
        npcHandler:say("Okay then!", cid)
        doTeleportThing(cid, config.pos)
    elseif(msgcontains(msg, 'no')) then
        npcHandler:say("Oh, well then not!", cid)
        npcHandler:releaseFocus(cid) --release focus
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Why did you removed? I didnt said that it need to be removed :D
if msgcontains(msg, 'protect') then

Just noticed in console and for some reason you can skip key word "protect" and just say "hi" "yes" which is a problem to
 
Why did you removed? I didnt said that it need to be removed :D
if msgcontains(msg, 'protect') then

Just noticed in console and for some reason you can skip key word "protect" and just say "hi" "yes" which is a problem to
In you first script dont have key word "Protect"
If you need, use the talkstate correctly.
 
Thats the problem how to use it correctly -_-
Teste this please:
Lua:
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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    -- using Topics example by Mummrik
    if msgcontains(msg, 'protect') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to help?", cid)
            talkState[talkUser] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
            talkState[talkUser] = nil
            npcHandler:releaseFocus(cid) --optional
        end
    end   
    if talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
            npcHandler:say("Very well!", cid)
            doTeleportThing(cid, config.pos)
        elseif msgcontains(msg, 'no') then
            npcHandler:say("Oh, well then not!", cid)
            talkState[talkUser] = nil
            npcHandler:releaseFocus(cid) --optional
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Teste this please:
Lua:
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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    -- using Topics example by Mummrik
    if msgcontains(msg, 'protect') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to help?", cid)
            talkState[talkUser] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
            talkState[talkUser] = nil
            npcHandler:releaseFocus(cid) --optional
        end
    end  
    if talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
            npcHandler:say("Very well!", cid)
            doTeleportThing(cid, config.pos)
        elseif msgcontains(msg, 'no') then
            npcHandler:say("Oh, well then not!", cid)
            talkState[talkUser] = nil
            npcHandler:releaseFocus(cid) --optional
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Nop still same, so if you talk with npc first time it works but if you talk with him second time it doesnt you can skip "protect" part.
 
test this please and show me screen server

Lua:
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 config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    -- using Topics example by Mummrik
    if msgcontains(msg, 'protect') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to help?", cid)
            talkState[talkUser] = 5    -- assign a topic id to the player
            print(talkState[talkUser])
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
            talkState[talkUser] = nil
           
            npcHandler:releaseFocus(cid) --optional
        end
    end  
    if talkState[talkUser] == 5 then
        if msgcontains(msg, 'yes') then
            npcHandler:say("Very well!", cid)
            doTeleportThing(cid, config.pos)
        elseif msgcontains(msg, 'no') then
            npcHandler:say("Oh, well then not!", cid)
            talkState[talkUser] = nil
            npcHandler:releaseFocus(cid) --optional
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
show the xml file of npc
 
Nop still same, so if you talk with npc first time it works but if you talk with him second time it doesnt you can skip "protect" part.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}    -- Stores all the topics in a table
local config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    Topic[cid] = nil    -- make sure to clear the table when the player disapears from the npc
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                        end

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    -- using Topics example by Mummrik
    if msgcontains(msg, 'protect') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to help?", cid)
            Topic[cid] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
        end
    elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
        npcHandler:say("Very well!", cid)
        doTeleportThing(cid, config.pos)
        Topic[cid] = nil    -- clear the topic
    elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
        npcHandler:say("Oh, well then not!", cid)
        Topic[cid] = nil    -- clear the topic
    end

    return true
end

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

Test this i just added this line Topic[cid] = nil inside the 'yes' i forgot to add it when i made the script the first time

i did also change the location of the table's to the top of the script since it didnt seem to work to clear it whit the oncreaturedisappear function
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}    -- Stores all the topics in a table
local config = {
    minLevel = 350,
    pos = {x = 1007, y = 1160, z = 7},
}

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)
    Topic[cid] = nil    -- make sure to clear the table when the player disapears from the npc
    npcHandler:onCreatureDisappear(cid)
end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                        end

function creatureSayCallback(cid, type, msg)
    local player = Player(cid)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    -- using Topics example by Mummrik
    if msgcontains(msg, 'protect') then
        if player:getLevel() >= config.minLevel then
            npcHandler:say("Are you sure you want to help?", cid)
            Topic[cid] = 1    -- assign a topic id to the player
        else
            npcHandler:say(string.format("You don't have %s level.", config.minLevel), cid)
        end
    elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
        npcHandler:say("Very well!", cid)
        doTeleportThing(cid, config.pos)
        Topic[cid] = nil    -- clear the topic
    elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
        npcHandler:say("Oh, well then not!", cid)
        Topic[cid] = nil    -- clear the topic
    end

    return true
end

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

Test this i just added this line Topic[cid] = nil inside the 'yes' i forgot to add it when i made the script the first time

i did also change the location of the table's to the top of the script since it didnt seem to work to clear it whit the oncreaturedisappear function
perfect
 
Back
Top