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

Problem : 'Then' expected near '='

Hypocryte

Member
Joined
Dec 4, 2017
Messages
30
Reaction score
5
Hello guys, could someone help me with my script? It is my first npc ever, so dont be rude :D

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

firstpromotionlevel    = 'You have to be at least 30 level to become warrior! Come back when you got stronger.'
cantskippromo        = 'You specialize in something else, Bye!'

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, "Warrior") then
        selfSay("So you want to know more about us? Okay! We specialize in close combat battle, our weapon are swords, axes or clubs. Warriors are always in the first line in battle. To become one of us you have to be tough and brave. Are you intrested about joining us?", cid)
        talkState[talkUser] = 1
    else if msgcontains(msg,"yes") and talkState[talkUser] == 1 and player:getLevel() < promolevel than
        selfSay(firstpromotionlevel, cid)
        talkState[talkUser] = 2
        return false
    else if msgcontains(msg, "Warrior") and talkState[talkUser] == 2 then
        selfSay("So you got stronger, i see your fighting spirit, you remaind me of myself from young ages. Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    else if msgcontains(msg,"yes") and talkState[talkUser] == 3 then
        selfSay("So, from now on you are one of us, wear this outfit with proud.",cid)
        doPlayerAddOutfit(cid, getPlayerSex(cid) == 0 and 134 or 142, 2)
        player:setVocation(2)
        talkState[talkUser] = 4
    else if msgcontains(msg,"no") and talkState[talkUser] == 1 than
        selfSay("So i hope that you will find specialization that suits you. Good Luck !", cid)
        talkState[talkUser] = 0
    else if msgcontains(msg,"no") and talkState[talkUser] == 3
        selfSay("Okay, take your time, come back when you be ready !", cid)
        talkState[talkUser] = 2
    else if msgcontains(msg,"Warrior") and talkState[talkUser] == 4 than
        selfSay("I hope that you feel good among us, my friend", cid)
        return false
    else if msgcontains(msg,"yes") and player:getVocation():getId() == 5 or player:getVocation():getId() == 8 or player:getVocation():getId() == 11 than
        selfSay(cantskippromo, cid)
        return false
    end
end
       
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Engine message :
ZeEGqDc.png
 
Solution
Firstly, thanks very much for your effort.

For now after :

" So you want to know more about us? Okay! ..." when i say " no" he normaly say : "So i hope that you will find specialization". But when i say " Yes " he do not react.

i delated locals :
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()...
also change "else if" to "elseif" :p

-- edit
also
"firstpromotionlevel" & "cantskippromo"
put "local" in front of them.

This way it's contained within the script, and can't interfere with other scripts.
 
Last edited:
I made changes that you guys suggested, npc works now, i can spawn him, but after saying line : "So you want to know more about us? Okay! ....." he do not react to any other words :( HELP !

Code:
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
firstpromotionlevel    = 'You have to be at least 30 level to become warrior! Come back when you got stronger.'
cantskippromo        = 'You specialize in something else, Bye!'

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, "Warrior") then
        selfSay("So you want to know more about us? Okay! We specialize in close combat battle, our weapon are swords, axes or clubs. Warriors are always in the first line in battle. To become one of us you have to be tough and brave. Are you intrested about joining us?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 and player:getLevel() < promolevel then
        selfSay(firstpromotionlevel, cid)
        talkState[talkUser] = 2
        return false
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 then
        selfSay("Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "Warrior") and talkState[talkUser] == 2 then
        selfSay("So you got stronger, i see your fighting spirit, you remaind me of myself from young ages. Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 3 then
        selfSay("So, from now on you are one of us, wear this outfit with proud.",cid)
        doPlayerAddOutfit(cid, getPlayerSex(cid) == 0 and 134 or 142, 2)
        player:setVocation(2)
        talkState[talkUser] = 4
    elseif msgcontains(msg,"no") and talkState[talkUser] == 1 then
        selfSay("So i hope that you will find specialization that suits you. Good Luck !", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg,"no") and talkState[talkUser] == 3 then
        selfSay("Okay, take your time, come back when you be ready !", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"Warrior") and talkState[talkUser] == 4 then
        selfSay("I hope that you feel good among us, my friend", cid)
        return false
    elseif msgcontains(msg,"yes") and player:getVocation():getId() == 5 or player:getVocation():getId() == 8 or player:getVocation():getId() == 11 then
        selfSay(cantskippromo, cid)
        return false
    end
end
      
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I made changes that you guys suggested, npc works now, i can spawn him, but after saying line : "So you want to know more about us? Okay! ....." he do not react to any other words :( HELP !

Code:
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
firstpromotionlevel    = 'You have to be at least 30 level to become warrior! Come back when you got stronger.'
cantskippromo        = 'You specialize in something else, Bye!'

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, "Warrior") then
        selfSay("So you want to know more about us? Okay! We specialize in close combat battle, our weapon are swords, axes or clubs. Warriors are always in the first line in battle. To become one of us you have to be tough and brave. Are you intrested about joining us?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 and player:getLevel() < promolevel then
        selfSay(firstpromotionlevel, cid)
        talkState[talkUser] = 2
        return false
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 then
        selfSay("Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "Warrior") and talkState[talkUser] == 2 then
        selfSay("So you got stronger, i see your fighting spirit, you remaind me of myself from young ages. Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 3 then
        selfSay("So, from now on you are one of us, wear this outfit with proud.",cid)
        doPlayerAddOutfit(cid, getPlayerSex(cid) == 0 and 134 or 142, 2)
        player:setVocation(2)
        talkState[talkUser] = 4
    elseif msgcontains(msg,"no") and talkState[talkUser] == 1 then
        selfSay("So i hope that you will find specialization that suits you. Good Luck !", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg,"no") and talkState[talkUser] == 3 then
        selfSay("Okay, take your time, come back when you be ready !", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"Warrior") and talkState[talkUser] == 4 then
        selfSay("I hope that you feel good among us, my friend", cid)
        return false
    elseif msgcontains(msg,"yes") and player:getVocation():getId() == 5 or player:getVocation():getId() == 8 or player:getVocation():getId() == 11 then
        selfSay(cantskippromo, cid)
        return false
    end
end
     
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Do you get an error after the first message?
Which TFS are you using?
 

Added the talkstate thing near the top.
Fixed up the locals near the top
removed the capitals from your msgcontains

Should work
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 firstpromotionlevel = "You have to be at least 30 level to become warrior! Come back when you got stronger."
local cantskippromo = "You specialize in something else, Bye!"

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, "warrior") then
        selfSay("So you want to know more about us? Okay! We specialize in close combat battle, our weapon are swords, axes or clubs. Warriors are always in the first line in battle. To become one of us you have to be tough and brave. Are you intrested about joining us?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 and player:getLevel() < promolevel then
        selfSay(firstpromotionlevel, cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 then
        selfSay("Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "warrior") and talkState[talkUser] == 2 then
        selfSay("So you got stronger, i see your fighting spirit, you remaind me of myself from young ages. Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 3 then
        selfSay("So, from now on you are one of us, wear this outfit with proud.",cid)
        doPlayerAddOutfit(cid, getPlayerSex(cid) == 0 and 134 or 142, 2)
        player:setVocation(2)
        talkState[talkUser] = 4
    elseif msgcontains(msg,"no") and talkState[talkUser] == 1 then
        selfSay("So i hope that you will find specialization that suits you. Good Luck !", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg,"no") and talkState[talkUser] == 3 then
        selfSay("Okay, take your time, come back when you be ready !", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"warrior") and talkState[talkUser] == 4 then
        selfSay("I hope that you feel good among us, my friend", cid)
    elseif msgcontains(msg,"yes") and player:getVocation():getId() == 5 or player:getVocation():getId() == 8 or player:getVocation():getId() == 11 then
        selfSay(cantskippromo, cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Firstly, thanks very much for your effort.

For now after :

" So you want to know more about us? Okay! ..." when i say " no" he normaly say : "So i hope that you will find specialization". But when i say " Yes " he do not react.

i delated locals :
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
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, "warrior") then
        selfSay("So you want to know more about us? Okay! We specialize in close combat battle, our weapon are swords, axes or clubs. Warriors are always in the first line in battle. To become one of us you have to be tough and brave. Are you intrested about joining us?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 and player:getLevel() < 30 then
        selfSay("You have to be at least 30 level to become warrior! Come back when you got stronger.", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 then
        selfSay("Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "warrior") and talkState[talkUser] == 2 then
        selfSay("So you got stronger, i see your fighting spirit, you remaind me of myself from young ages. Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 3 then
        selfSay("So, from now on you are one of us, wear this outfit with proud.",cid)
        doPlayerAddOutfit(cid, getPlayerSex(cid) == 0 and 134 or 142, 2)
        player:setVocation(2)
        talkState[talkUser] = 4
    elseif msgcontains(msg,"no") and talkState[talkUser] == 1 then
        selfSay("So i hope that you will find specialization that suits you. Good Luck !", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg,"no") and talkState[talkUser] == 3 then
        selfSay("Okay, take your time, come back when you be ready !", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"warrior") and talkState[talkUser] == 4 then
        selfSay("I hope that you feel good among us, my friend", cid)
    elseif msgcontains(msg,"yes") and player:getVocation():getId() == 5 or player:getVocation():getId() == 8 or player:getVocation():getId() == 11 then
        selfSay("You are specialized in something else. Bye !", cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

wLw1BNo.png
 
Last edited:
Firstly, thanks very much for your effort.

For now after :

" So you want to know more about us? Okay! ..." when i say " no" he normaly say : "So i hope that you will find specialization". But when i say " Yes " he do not react.

i delated locals :
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
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, "warrior") then
        selfSay("So you want to know more about us? Okay! We specialize in close combat battle, our weapon are swords, axes or clubs. Warriors are always in the first line in battle. To become one of us you have to be tough and brave. Are you intrested about joining us?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 and player:getLevel() < 30 then
        selfSay("You have to be at least 30 level to become warrior! Come back when you got stronger.", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 1 then
        selfSay("Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "warrior") and talkState[talkUser] == 2 then
        selfSay("So you got stronger, i see your fighting spirit, you remaind me of myself from young ages. Are you ready for becoming warrior?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg,"yes") and talkState[talkUser] == 3 then
        selfSay("So, from now on you are one of us, wear this outfit with proud.",cid)
        doPlayerAddOutfit(cid, getPlayerSex(cid) == 0 and 134 or 142, 2)
        player:setVocation(2)
        talkState[talkUser] = 4
    elseif msgcontains(msg,"no") and talkState[talkUser] == 1 then
        selfSay("So i hope that you will find specialization that suits you. Good Luck !", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg,"no") and talkState[talkUser] == 3 then
        selfSay("Okay, take your time, come back when you be ready !", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg,"warrior") and talkState[talkUser] == 4 then
        selfSay("I hope that you feel good among us, my friend", cid)
    elseif msgcontains(msg,"yes") and player:getVocation():getId() == 5 or player:getVocation():getId() == 8 or player:getVocation():getId() == 11 then
        selfSay("You are specialized in something else. Bye !", cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

wLw1BNo.png
Reading from other npc examples.. it seems you want to add
Lua:
local player = Player(cid)
just above this
Lua:
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
Solution
Back
Top