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

Lua NPC tell story, give item and teleport TFS 1.3

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
464
Solutions
1
Reaction score
58
Hi guys,

I would like a npc script that the player can talk to him, like:

Player: Hi
NPC: Hello |PLAYERNAME|. Do you wanna know about WAR? Or do you want me to tell the STORY of the city? Or maybe you want to learn where you can BUY potion?
Player: war
NPC: There's a war going on for x years...
Player: story
NPC: this city was build by King Arthur, I will teleport you to his museum. (NPC teleport player to position x,y,z)
Player: buy
NPC: You can buy potion to the west. I see you new here, take this with you. (NPC give a health potion to player)

I tried to do it by myself but the npc didn't even talk to me... I would be glad if someone can help me with that.
 
Solution
I tried the first opition and ain't working. No errors on TFS.

npc.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="The Divine" script="The Divine.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="1138"/>
    <parameters>
        <parameter key="message_greet" value="You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your memory and  break the immortal spell I cast upon you. You need to ask me about memory so you can start to learn everything again." />
    </parameters>
</npc>

script.lua

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)...
post what u have done here
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 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, 'memory') then
        selfSay('Close your eyes and I will teleport you to inside your mind. You will remember the first time we meet, I teached you to mine, harvest, cook, fish and craft itens.', cid)
        talkState[talkUser] = 1
    end
end

At this part I was trying to make just the NPC talk to me.
 
local hiddenKingdom = {x = 1577, y = 808, z = 8} -- Coordinates of the Hidden Kingdom


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

local hiddenKingdom = {x = 1577, y = 808, z = 8}

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'memory') then
        selfSay('Hello |PLAYERNAME|. Do you want to know about the {WAR}? Or would you like me to tell you the {HISTORY} of the city? Or perhaps you want to know where to buy {potions}?', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then

        if msgcontains(msg, 'war') then
            selfSay("There's a war going on for x years...", cid)

        elseif msgcontains(msg, 'history') or msgcontains(msg, 'stories') then
            selfSay('This city was built by King Arthur. I can teleport you to his museum.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, hiddenKingdom)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You have been teleported to King Arthur's museum. Enjoy your visit!", cid)
        end
        talkState[talkUser] = 0


    elseif msgcontains(msg, 'buy') or msgcontains(msg, 'potion') then
        selfSay('You can buy a potion to the west. I see you are new here, take this with you.', cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
        if getPlayerItemCount(cid, 2160) >= 50 then
            doPlayerRemoveItem(cid, 2160, 50)
            doPlayerAddItem(cid, 6527, 100)
            selfSay('Here is the potion for you.', cid)
        else
            selfSay('You don\'t have enough money.', cid)
        end
        talkState[talkUser] = 0
    end

    return true
end

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

or

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

local hiddenKingdom = {x = 1577, y = 808, z = 8} -- Coordinates of the Hidden Kingdom

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'memory') then
        selfSay('Hello |PLAYERNAME|. Do you want to know about the WAR? Or would you like me to tell you the HISTORY of the city? Or perhaps you want to know where to buy potions?', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then

        if msgcontains(msg, 'war') then
            selfSay("There's a war going on for x years...", cid)

        elseif msgcontains(msg, 'history') or msgcontains(msg, 'stories') then
            selfSay('This city was built by King Arthur. I can teleport you to his museum.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, hiddenKingdom)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
             doPlayerAddItem(cid, 6527, 100)
            selfSay("You have been teleported to King Arthur's museum. Enjoy your visit!", cid)
        end
        talkState[talkUser] = 0
    end
   
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local hiddenKingdom = {x = 1577, y = 808, z = 8}

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'memory') then
        selfSay('Hello |PLAYERNAME|. Do you want to know about the {WAR}? Or would you like me to tell you the {HISTORY} of the city? Or perhaps you want to know where to buy {potions}?', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then

        if msgcontains(msg, 'war') then
            selfSay("There's a war going on for x years...", cid)

        elseif msgcontains(msg, 'history') or msgcontains(msg, 'stories') then
            selfSay('This city was built by King Arthur. I can teleport you to his museum.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, hiddenKingdom)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You have been teleported to King Arthur's museum. Enjoy your visit!", cid)
        end
        talkState[talkUser] = 0


    elseif msgcontains(msg, 'buy') or msgcontains(msg, 'potion') then
        selfSay('You can buy a potion to the west. I see you are new here, take this with you.', cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
        if getPlayerItemCount(cid, 2160) >= 50 then
            doPlayerRemoveItem(cid, 2160, 50)
            doPlayerAddItem(cid, 6527, 100)
            selfSay('Here is the potion for you.', cid)
        else
            selfSay('You don\'t have enough money.', cid)
        end
        talkState[talkUser] = 0
    end

    return true
end

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

or

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

local hiddenKingdom = {x = 1577, y = 808, z = 8} -- Coordinates of the Hidden Kingdom

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'memory') then
        selfSay('Hello |PLAYERNAME|. Do you want to know about the WAR? Or would you like me to tell you the HISTORY of the city? Or perhaps you want to know where to buy potions?', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then

        if msgcontains(msg, 'war') then
            selfSay("There's a war going on for x years...", cid)

        elseif msgcontains(msg, 'history') or msgcontains(msg, 'stories') then
            selfSay('This city was built by King Arthur. I can teleport you to his museum.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, hiddenKingdom)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
             doPlayerAddItem(cid, 6527, 100)
            selfSay("You have been teleported to King Arthur's museum. Enjoy your visit!", cid)
        end
        talkState[talkUser] = 0
    end
  
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
I tried the first opition and ain't working. No errors on TFS.

npc.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="The Divine" script="The Divine.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="1138"/>
    <parameters>
        <parameter key="message_greet" value="You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your memory and  break the immortal spell I cast upon you. You need to ask me about memory so you can start to learn everything again." />
    </parameters>
</npc>

script.lua

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

local reinoOculto = {x = 123, y = 77, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your {MEMORY} and  break the immortal spell I cast upon you.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'memory') then
            selfSay("Yeah, we can't give up, you need to train more, become stronger and {LEARN} everything you forgot, so you can face him again, it won't be easy and I can't do more than give you eternal life, but Tukson is counting on you...", cid)
        elseif msgcontains(msg, 'learn') then
            selfSay('You need to close your eyes and I will bring your essence inside your own mind so you can remember the first time we did this process before. Are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You went through a extrange journey inside your own mind!", cid)
        end

    end

    return true
end

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

18:32 The Divine: You failed again Character Teste. You were defeated again by Zynthir. It seems that he has a spell that erases all your memory and break the immortal spell I cast upon you. You need to ask me about memory so you can start to learn everything again.
18:34 Character Teste [1]: memory

I change up a little bit the script for what I actually need, but when I talk to the npc, he just send the message that it's on default in .xml
Post automatically merged:

This script is for the beginning of a custom server. The player wake up at a grave without memory, just a npc in front of him. He talks to npc and the npc tells him a little story. They continue to talk and the NPC teleports him to other place. Thats first NPC:

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

local reinoOculto = {x = 123, y = 77, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your {MEMORY} and  break the immortal spell I cast upon you.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'memory') then
            selfSay("Yeah, we can't give up, you need to train more, become stronger and {LEARN} everything you forgot, so you can face him again, it won't be easy and I can't do more than give you eternal life, but Tukson is counting on you...", cid)
        elseif msgcontains(msg, 'learn') then
            selfSay('You need to close your eyes and I will bring your essence inside your own mind so you can remember the first time we did this process before. Are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You went through a extrange journey inside your own mind!", cid)
        end

    end

    return true
end

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

At the second location he meets the second NPC. They will talk, npc will give him item for him to create (learning the server systems). He creates the itens, goes back to npc, talk again, receive more itens, create more itens, and that until he craft backpack, weapon, food and potion. Then the npc teleports him to the next location. The second NPC script:

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

local reinoOculto = {x = 123, y = 102, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('Hello |PLAYERNAME|. People call me The Divine, and you were dead. The world is at war and you were choosen to be the first crusader. To even things out I will cast a spell to make you immortal and you can die as much as you want and you be brought back to life. Now its time for you to learn whats new in the world. Its important for you to learn about {SKINNING}, {CRAFTING}, {COOKING} and {ALCHEMY}.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'skinning') then
            doPlayerAddItem(cid, 27851, 5)
            selfSay("Beside those creatures that you see, you will be able to skin most creatures you face. When you skin creatures you have a chance to get some leather. Leather is very important to crafting. You need a backpack to carry things around and to craft a backpack you need to learn about skinning. Take this leather and make a backpack at the anvil to the left.", cid)
        elseif msgcontains(msg, 'craft') then
            doPlayerAddItem(cid, 27871, 5)
            doPlayerAddItem(cid, 11370, 10)
            doPlayerAddItem(cid, 4843, 1)
            selfSay('Everything can be done throught craft, but to craft you need materials that you can get by mining stones, chopping wood, refining materials and skinning creatures. A crusader need to learn to adapt, so you need to know how to use at least 9 types of weapons. Unfortunantely I only have materials for you to create either a sword, or an axe, or an dagger or a club. Here it is the materials for you to do your weapon at the anvil to the left and remember that you can always gather more materials and do other types of weapons.', cid)
            talkState[talkUser] = 2
        elseif msgcontains(msg, 'cooking') then
            doPlayerAddItem(cid, 27905, 2)
            selfSay('You are imortal again, however wounds dont heal by themselfs they need nutrients to heal and regenerate just like for you to fill your mana. To cook meals you can harvest plants, fish at any type of water and combine then in the oven to have a decent meal. Here it is the ingredients for you to do meal at the oven to the south.', cid)
        elseif msgcontains(msg, 'alchemy') then
            doPlayerAddItem(cid, 27911, 2)
            doPlayerAddItem(cid, 2670, 10)
            selfSay('You wont survive long in yout adventure just eating food. Strong creatures deal a lot of damage and even though you are imortal, you can sucumbe and lost your consciousness but with potions you might survive. However you need to know that the big potions store might not be the best place for you to get potions, their focus is money, so they create terrible potions and charge a lot of money. The best potions are the ones you create. Here it is the ingredients for you to craft some potions. If you have a backpack, weapon, potion and a meal, then we should go to our {NEXT} memomry.', cid)
 end   
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'next') then
           doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You to get the hang of this extrange journey inside your own mind!", cid)
        end

    end

    return true
end

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

At the third location they talk, NPC tells him a story, then teleport him to main city. Third NPC script:

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

local reinoOculto = {x = 1070, y = 1082, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('So thats our last stop and here you need to learn about {ARCHEOLOGY}.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'archeology') then
            selfSay("Ages ago there were a war between the 7 gods and the mages that serve them and everything end badly, elemental e poewrful essences were spread all over the world. All over the map you will find those stones and if you use an archeology kit you may be able to find some stuff to enhance your weapons and equipments. Now we're {DONE}.", cid)
        elseif msgcontains(msg, 'done') then
            selfSay('Yeah, the rest you need to learn on your own. I will teleport you Tukson, are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You've been teleported to Tukson Temple. Enjoy your adventurer, Crusader!", cid)
        end

    end

    return true
end

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

I don't know if all my edits are right.
 
Last edited:
I tried the first opition and ain't working. No errors on TFS.

npc.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="The Divine" script="The Divine.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="1138"/>
    <parameters>
        <parameter key="message_greet" value="You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your memory and  break the immortal spell I cast upon you. You need to ask me about memory so you can start to learn everything again." />
    </parameters>
</npc>

script.lua

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

local reinoOculto = {x = 123, y = 77, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your {MEMORY} and  break the immortal spell I cast upon you.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'memory') then
            selfSay("Yeah, we can't give up, you need to train more, become stronger and {LEARN} everything you forgot, so you can face him again, it won't be easy and I can't do more than give you eternal life, but Tukson is counting on you...", cid)
        elseif msgcontains(msg, 'learn') then
            selfSay('You need to close your eyes and I will bring your essence inside your own mind so you can remember the first time we did this process before. Are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You went through a extrange journey inside your own mind!", cid)
        end

    end

    return true
end

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



I change up a little bit the script for what I actually need, but when I talk to the npc, he just send the message that it's on default in .xml
Post automatically merged:

This script is for the beginning of a custom server. The player wake up at a grave without memory, just a npc in front of him. He talks to npc and the npc tells him a little story. They continue to talk and the NPC teleports him to other place. Thats first NPC:

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

local reinoOculto = {x = 123, y = 77, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('You failed again |PLAYERNAME|. You were defeated again by Zynthir. It seems that he has a spell that erases all your {MEMORY} and  break the immortal spell I cast upon you.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'memory') then
            selfSay("Yeah, we can't give up, you need to train more, become stronger and {LEARN} everything you forgot, so you can face him again, it won't be easy and I can't do more than give you eternal life, but Tukson is counting on you...", cid)
        elseif msgcontains(msg, 'learn') then
            selfSay('You need to close your eyes and I will bring your essence inside your own mind so you can remember the first time we did this process before. Are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You went through a extrange journey inside your own mind!", cid)
        end

    end

    return true
end

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

At the second location he meets the second NPC. They will talk, npc will give him item for him to create (learning the server systems). He creates the itens, goes back to npc, talk again, receive more itens, create more itens, and that until he craft backpack, weapon, food and potion. Then the npc teleports him to the next location. The second NPC script:

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

local reinoOculto = {x = 123, y = 102, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('Hello |PLAYERNAME|. People call me The Divine, and you were dead. The world is at war and you were choosen to be the first crusader. To even things out I will cast a spell to make you immortal and you can die as much as you want and you be brought back to life. Now its time for you to learn whats new in the world. Its important for you to learn about {SKINNING}, {CRAFTING}, {COOKING} and {ALCHEMY}.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'skinning') then
            doPlayerAddItem(cid, 27851, 5)
            selfSay("Beside those creatures that you see, you will be able to skin most creatures you face. When you skin creatures you have a chance to get some leather. Leather is very important to crafting. You need a backpack to carry things around and to craft a backpack you need to learn about skinning. Take this leather and make a backpack at the anvil to the left.", cid)
        elseif msgcontains(msg, 'craft') then
            doPlayerAddItem(cid, 27871, 5)
            doPlayerAddItem(cid, 11370, 10)
            doPlayerAddItem(cid, 4843, 1)
            selfSay('Everything can be done throught craft, but to craft you need materials that you can get by mining stones, chopping wood, refining materials and skinning creatures. A crusader need to learn to adapt, so you need to know how to use at least 9 types of weapons. Unfortunantely I only have materials for you to create either a sword, or an axe, or an dagger or a club. Here it is the materials for you to do your weapon at the anvil to the left and remember that you can always gather more materials and do other types of weapons.', cid)
            talkState[talkUser] = 2
        elseif msgcontains(msg, 'cooking') then
            doPlayerAddItem(cid, 27905, 2)
            selfSay('You are imortal again, however wounds dont heal by themselfs they need nutrients to heal and regenerate just like for you to fill your mana. To cook meals you can harvest plants, fish at any type of water and combine then in the oven to have a decent meal. Here it is the ingredients for you to do meal at the oven to the south.', cid)
        elseif msgcontains(msg, 'alchemy') then
            doPlayerAddItem(cid, 27911, 2)
            doPlayerAddItem(cid, 2670, 10)
            selfSay('You wont survive long in yout adventure just eating food. Strong creatures deal a lot of damage and even though you are imortal, you can sucumbe and lost your consciousness but with potions you might survive. However you need to know that the big potions store might not be the best place for you to get potions, their focus is money, so they create terrible potions and charge a lot of money. The best potions are the ones you create. Here it is the ingredients for you to craft some potions. If you have a backpack, weapon, potion and a meal, then we should go to our {NEXT} memomry.', cid)
 end 
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'next') then
           doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You to get the hang of this extrange journey inside your own mind!", cid)
        end

    end

    return true
end

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

At the third location they talk, NPC tells him a story, then teleport him to main city. Third NPC script:

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

local reinoOculto = {x = 1070, y = 1082, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
        selfSay('So thats our last stop and here you need to learn about {ARCHEOLOGY}.', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'archeology') then
            selfSay("Ages ago there were a war between the 7 gods and the mages that serve them and everything end badly, elemental e poewrful essences were spread all over the world. All over the map you will find those stones and if you use an archeology kit you may be able to find some stuff to enhance your weapons and equipments. Now we're {DONE}.", cid)
        elseif msgcontains(msg, 'done') then
            selfSay('Yeah, the rest you need to learn on your own. I will teleport you Tukson, are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You've been teleported to Tukson Temple. Enjoy your adventurer, Crusader!", cid)
        end

    end

    return true
end

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

I don't know if all my edits are right.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local reinoOculto = {x = 123, y = 77, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'memory') then
        selfSay("Yeah, we can't give up, you need to train more, become stronger and {LEARN} everything you forgot, so you can face him again, it won't be easy and I can't do more than give you eternal life, but Tukson is counting on you...", cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'learn') then
            selfSay('You need to close your eyes and I will bring your essence inside your own mind so you can remember the first time we did this process before. Are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You went through a strange journey inside your own mind!", cid)
        end
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

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

local reinoOculto = {x = 123, y = 102, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'skinning') and talkState[talkUser] ~= 1 then
        selfSay("Beside those creatures that you see, you will be able to skin most creatures you face. When you skin creatures you have a chance to get some leather. Leather is very important to crafting. You need a backpack to carry things around and to craft a backpack you need to learn about skinning. Take this leather and make a backpack at the anvil to the left.", cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 and msgcontains(msg, 'skinning') then
        doPlayerAddItem(cid, 27851, 5)
        selfSay("You've already received the leather. Beside those creatures that you see, you will be able to skin most creatures you face. When you skin creatures you have a chance to get some leather. Leather is very important to crafting. You need a backpack to carry things around and to craft a backpack you need to learn about skinning.", cid)
    elseif talkState[talkUser] == 1 and msgcontains(msg, 'craft') then
        doPlayerAddItem(cid, 27871, 5)
        doPlayerAddItem(cid, 11370, 10)
        doPlayerAddItem(cid, 4843, 1)
        selfSay('Everything can be done through crafting, but to craft you need materials that you can get by mining stones, chopping wood, refining materials, and skinning creatures. A crusader needs to learn to adapt, so you need to know how to use at least 9 types of weapons. Unfortunately, I only have materials for you to create either a sword, an axe, a dagger, or a club. Here are the materials for you to craft your weapon at the anvil to the left, and remember that you can always gather more materials and craft other types of weapons.', cid)
        talkState[talkUser] = 2
    elseif talkState[talkUser] == 2 and msgcontains(msg, 'cooking') then
        doPlayerAddItem(cid, 27905, 2)
        selfSay('You are immortal again, however, wounds don\'t heal by themselves; they need nutrients to heal and regenerate, just like for you to refill your mana. To cook meals, you can harvest plants, fish at any type of water, and combine them in the oven to have a decent meal. Here are the ingredients for you to make a meal at the oven to the south.', cid)
    elseif talkState[talkUser] == 2 and msgcontains(msg, 'alchemy') then
        doPlayerAddItem(cid, 27911, 2)
        doPlayerAddItem(cid, 2670, 10)
        selfSay('You won\'t survive long in your adventure just eating food. Strong creatures deal a lot of damage, and even though you are immortal, you can succumb and lose your consciousness. But with potions, you might survive. However, you need to know that the big potions store might not be the best place for you to get potions; their focus is money, so they create terrible potions and charge a lot of money. The best potions are the ones you create. Here are the ingredients for you to craft some potions. If you have a backpack, weapon, potion, and a meal, then we should go to our {NEXT} memory.', cid)
    elseif talkState[talkUser] == 2 and msgcontains(msg, 'next') then
        doTeleportThing(cid, reinoOculto)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        selfSay("You are getting the hang of this strange journey inside your own mind!", cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

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

local reinoOculto = {x = 1070, y = 1082, z = 7} -- Hidden Kingdom Coordinates

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid)
end

function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg:lower())
end

function onThink()
    npcHandler:onThink()
end

local talkState = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

    if msgcontains(msg, 'archeology') and talkState[talkUser] == nil then
        selfSay("Ages ago there was a war between the 7 gods and the mages that served them, and everything ended badly. Elemental and powerful essences were spread all over the world. All over the map you will find those stones, and if you use an archeology kit, you may be able to find some stuff to enhance your weapons and equipment. Now we're {DONE}.", cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'done') then
            selfSay('Yeah, the rest you need to learn on your own. I will teleport you to Tukson, are you ready?.', cid)
            talkState[talkUser] = 2
        end
    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
            doTeleportThing(cid, reinoOculto)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            selfSay("You've been teleported to Tukson Temple. Enjoy your adventure, Crusader!", cid)
        end
    end

    return true
end

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

I fixed all NPCs, they are now working correctly. If there is a solution, please mark as resolved.
 
Last edited:
Solution
local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local reinoOculto = {x = 1070, y = 1082, z = 7} -- Hidden Kingdom Coordinates function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg:lower()) end function onThink() npcHandler:eek:nThink() end local talkState = {} function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end local talkUser = cid if msgcontains(msg, 'archeology') and talkState[talkUser] == nil then selfSay("Ages ago there was a war between the 7 gods and the mages that served them, and everything ended badly. Elemental and powerful essences were spread all over the world. All over the map you will find those stones, and if you use an archeology kit, you may be able to find some stuff to enhance your weapons and equipment. Now we're {DONE}.", cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if msgcontains(msg, 'done') then selfSay('Yeah, the rest you need to learn on your own. I will teleport you to Tukson, are you ready?.', cid) talkState[talkUser] = 2 end elseif talkState[talkUser] == 2 then if msgcontains(msg, 'yes') then doTeleportThing(cid, reinoOculto) doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT) selfSay("You've been teleported to Tukson Temple. Enjoy your adventure, Crusader!", cid) end end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
It's working as fine as I intended, but everytime I talk to the npc I receive the item. How could I put it to receive just once?
 
Back
Top