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

When right number then teleport (NPC)

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Reaction score
9
Location
NYC
Hey guys!

I'm looking for the NPC which will make conversation like that:

P - player
N - NPC


P: hi
N: Welcome! I'm guard here. Do you want to enter the Baba's Palace?
P: yes
N: I've got one question for you and you can enter: How many blue crystals did you saw on desert and on the mountains?
P: (here please write the number like 23
N: (if is correct then he will teleport player to position, if not, he will say 'It's a wrong answer. Write the right number like 1,2,3,4,5).

TFS 0.4
 
Once again, I urge you to look at at stuff I've wrote previously, and try to learn.
Need two NPC with missions

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
function greet(cid)   talkState[cid] = 0   return true end

function getNpcName()
   return getCreatureName(getNpcId())
end

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, "job") then
       selfSay("My job is to block people from {entering} the Baba's Palace.", cid)
       
   elseif msgcontains(msg, "name") then
       selfSay("My name is " .. getNpcName() .. ".", cid)

   elseif msgcontains(msg, "enter") and talkState[talkUser] == 1 then
       selfSay("Do you want to enter the Baba's Palace?", cid)
       talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
       selfSay("I've got one question for you and you can enter: How many blue crystals did you saw on desert and on the mountains?", cid)
       talkState[talkUser] = 2
   elseif talkState[talkUser] == 2 then
       talkState[talkUser] = 0
       if msgcontains(msg, "23") then
           selfSay("Correct. You will now be teleported the Baba's Palace.", cid)
           doTeleportThing(cid, {x = 1000, y = 1000, z = 7})
       else
           selfSay("It's a wrong answer. Write the right number like 1,2,3,4,5).", cid)
       end

   end
   return true  
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Once again, I urge you to look at at stuff I've wrote previously, and try to learn.
Need two NPC with missions

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
function greet(cid)   talkState[cid] = 0   return true end

function getNpcName()
   return getCreatureName(getNpcId())
end

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, "job") then
       selfSay("My job is to block people from {entering} the Baba's Palace.", cid)
      
   elseif msgcontains(msg, "name") then
       selfSay("My name is " .. getNpcName() .. ".", cid)

   elseif msgcontains(msg, "enter") and talkState[talkUser] == 1 then
       selfSay("Do you want to enter the Baba's Palace?", cid)
       talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
       selfSay("I've got one question for you and you can enter: How many blue crystals did you saw on desert and on the mountains?", cid)
       talkState[talkUser] = 2
   elseif talkState[talkUser] == 2 then
       talkState[talkUser] = 0
       if msgcontains(msg, "23") then
           selfSay("Correct. You will now be teleported the Baba's Palace.", cid)
           doTeleportThing(cid, {x = 1000, y = 1000, z = 7})
       else
           selfSay("It's a wrong answer. Write the right number like 1,2,3,4,5).", cid)
       end

   end
   return true 
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
It's not working.
10:35 Guard: Oh... sorry but I have the job here
10:35 [GOD] Taki Tam [691]: job
10:35 Guard: My job is to block people from entering the Baba's Palace.
10:35 [GOD] Taki Tam [691]: entering
10:35 [GOD] Taki Tam [691]: enter

And nothing
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic

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

function greet(cid)  
    Topic[cid] = 0  
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)

function creatureSayCallback(cid, type, msg)

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

    local n = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, "job") then
        selfSay("My job is to block people from {entering} the Baba's Palace.", cid)
    elseif msgcontains(msg, "name") then
        selfSay("My name is " .. getCreatureName(getNpcCid()) .. ".", cid)
    elseif msgcontains(msg, "enter") then
        selfSay("Do you want to enter the Baba's Palace?", cid)
        t = 1
    elseif Topic[n] == 1 then
        if msgcontains(msg, "yes") then
            selfSay("I've got one question for you and you can enter: How many blue crystals did you saw on desert and on the mountains?", cid)
            t = 2
        else
            selfSay("Okey then don't.", cid)
        end
    elseif Topic[n] == 2 then
        if msgcontains(msg, "23") then
            selfSay("Correct. You will now be teleported the Baba's Palace.", cid)
            doTeleportThing(cid, {x = 1000, y = 1000, z = 7})
        else
            selfSay("It's a wrong answer. Write the right number like 1,2,3,4,5).", cid)
        end
    end
    Topic[n] = t
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It's not working.


And nothing
sorry.. change this line
Code:
elseif msgcontains(msg, "enter") and talkState[talkUser] == 1 then
elseif msgcontains(msg, "enter") and talkState[talkUser] == 0 then

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic

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

function greet(cid)
    Topic[cid] = 0
    return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)

function creatureSayCallback(cid, type, msg)

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

    local n = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if msgcontains(msg, "job") then
        selfSay("My job is to block people from {entering} the Baba's Palace.", cid)
    elseif msgcontains(msg, "name") then
        selfSay("My name is " .. getCreatureName(getNpcCid()) .. ".", cid)
    elseif msgcontains(msg, "enter") then
        selfSay("Do you want to enter the Baba's Palace?", cid)
        t = 1
    elseif Topic[n] == 1 then
        if msgcontains(msg, "yes") then
           selfSay("I've got one question for you and you can enter: How many blue crystals did you saw on desert and on the mountains?", cid)
            t = 2
        else
            selfSay("Okey then don't.", cid)
        end
    elseif Topic[n] == 2 then
        if msgcontains(msg, "23") then
            selfSay("Correct. You will now be teleported the Baba's Palace.", cid)
            doTeleportThing(cid, {x = 1000, y = 1000, z = 7})
        else
            selfSay("It's a wrong answer. Write the right number like 1,2,3,4,5).", cid)
        end
    end
    Topic[n] = t
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
If you register talkstate without cid multiple people talking to 1 npc would share the talkstate. (I haven't tested your code, I'm just assuming.)

Like if they went like this..
Player 1: hi
Npc: blah1

Player 1: enter
Npc: blah2

Player 1: yes
Npc: blah3

Player 2: hi
Npc: blah1

Player 2: 23
Npc: blah4
-- teleports player

Player 1: 23
Npc: -----
 
Last edited:
Back
Top