• 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 TFS 1.3 NPC reward for few ingredients

Berciq

Veteran OT User
Joined
Aug 7, 2018
Messages
236
Reaction score
320
Location
Poland
Hey supprorters, I have dull problem, I just don't know how to connect all 5 requirements for reward in code line
I was always editing script that checks if the item count is higher than 0.
Now when I want 5 items to get one reward I don't know how to make them all work together and remove them after saying Yes.
If anybody could help I would really appreciate that, it is one of last things my server needs to work as I wish
problem is with two last lines, npc says that i "don't have them" and no problem on console is shown

Lua:
local
    keywordHandler:addKeyword({'pirate'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate backpack} for You?'}),  
    boxKeyword = keywordHandler:addKeyword({'pirate backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'Do you have all 4 pieces of pirate set and pirate bag?'})  
    boxKeyword:addChildKeyword({''}, StdModule.say, {npcHandler = npcHandler, text = 'HEY! You don\'t have them!', reset = true})  
    boxKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Here You go! from Your ingredients i\'ll make second one and sell Tom', reset = true},
        function(player) return player:getItemCount ({5462}, {5918}, {5927}, {6095}, {6096}) >0 end,
        function(player) player:removeItem({5462,1}, {5918,1}, {5927,1}, {6095,1}, {6096,1}) player:addItem(5926, 1) end)
 
Solution
Lua:
-- Backpacks
keywordHandler:addKeyword({'backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate}, {fur}, {minotaur} or {expedition} backpack for you?'})

local pirate_items = {5462, 5918, 5927, 6095, 6096}

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'pirate') then
            npcHandler:say('Do you have all 4 pieces of pirate set and pirate bag?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(pirate_items) do
                if player:getItemCount(itemid) < 1 then...
Hey supprorters, I have dull problem, I just don't know how to connect all 5 requirements for reward in code line
I was always editing script that checks if the item count is higher than 0.
Now when I want 5 items to get one reward I don't know how to make them all work together and remove them after saying Yes.
If anybody could help I would really appreciate that, it is one of last things my server needs to work as I wish
problem is with two last lines, npc says that i "don't have them" and no problem on console is shown

Lua:
local
    keywordHandler:addKeyword({'pirate'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate backpack} for You?'}), 
    boxKeyword = keywordHandler:addKeyword({'pirate backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'Do you have all 4 pieces of pirate set and pirate bag?'}) 
    boxKeyword:addChildKeyword({''}, StdModule.say, {npcHandler = npcHandler, text = 'HEY! You don\'t have them!', reset = true}) 
    boxKeyword:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, text = 'Here You go! from Your ingredients i\'ll make second one and sell Tom', reset = true},
        function(player) return player:getItemCount ({5462}, {5918}, {5927}, {6095}, {6096}) >0 end,
        function(player) player:removeItem({5462,1}, {5918,1}, {5927,1}, {6095,1}, {6096,1}) player:addItem(5926, 1) end)
bump
 
I tried splitting this last two lines in 10 separate line each for one item with same function but it doesn't work either :/

Lua:
local function creatureSayCallback(cid, type, msg)
    if msgcontains(msg, 'pirate backpack') then
            if player:getItemCount(5462) > 0 and player:getItemCount(5918) > 0 and player:getItemCount(5927) > 0 and player:getItemCount(6095) > 0 and player:getItemCount(6096) > 0 then
                player:removeItem(5462, 1)
                player:removeItem(5918, 1)
                player:removeItem(5927, 1)
                player:removeItem(6095, 1)
                player:removeItem(6096, 1)                
                player:addItem(5926, 1) 
                npcHandler:say('Here You go! from Your ingredients i\'ll make second one and sell Tom', cid)
            else
                npcHandler:say('HEY! You don\'t have them!', cid)
            end
        end
    return true
end

this one doesn't work either, anyone know how to fix this?
 
Nowhere in your function do you define “player”.

Try placing this above your msgcontains function:
Lua:
local player = Player(cid)

Red
 
nope with this line added and second lua code NPC doesn't even answer, first code worked but removed only one of the 5 items
 
Lua:
local function creatureSayCallback(cid, type, msg)
local player = Player(cid)
keywordHandler:addKeyword({'pirate'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate backpack} for You?'})
boxKeyword = keywordHandler:addKeyword({'pirate backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'Do you have all 4 pieces of pirate set and pirate bag?'}) 
    if msgcontains(msg, 'pirate backpack') then
            if player:getItemCount(5462) > 0 and player:getItemCount(5918) > 0 and player:getItemCount(5927) > 0 and player:getItemCount(6095) > 0 and player:getItemCount(6096) > 0 then
                player:removeItem(5462, 1)
                player:removeItem(5918, 1)
                player:removeItem(5927, 1)
                player:removeItem(6095, 1)
                player:removeItem(6096, 1)               
                player:addItem(5926, 1)
                npcHandler:say('Here You go! I\'ll use Your ingredients to make second backpack and sell it to Tom', cid)
            else
                npcHandler:say('HEY! You don\'t have them!', cid)
            end
        end
    return true
end
 
This is whole NPC code, backpack still doesn't work, it worked once, it checked all 5 ingredients but removed only one...
Please anybody. I know there is something messed in code lines with add and remove items in BACKPACKS. I just don't know what because from other servers code looks like this and wokrs, just not on my server..

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 voices = {
    { text = 'Are you looking for the best tools? Come to my shop!' },
    { text = 'Feeling lost? You can always ask me about general hints!' },
    { text = 'Tools and general equipment at Al Dee\'s!' },
    { text = 'Don\'t head for adventure without a rope and torches! Buy your supplies here!' }
}

-- Greets --
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Those kids today are more and more rud...')
npcHandler:setMessage(MESSAGE_FAREWELL, 'Have a nice day |PLAYERNAME|!')
npcHandler:setMessage(MESSAGE_SENDTRADE, 'Take a look in the trade window to your left.')
npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|. If You have tools, or need one just ask me to {Trade}. We will make a good deal!')

-- Basic Keywords --
keywordHandler:addKeyword({'hint'}, StdModule.rookgaardHints, {npcHandler = npcHandler})
keywordHandler:addKeyword({'sell'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see what I buy from you.'})
keywordHandler:addKeyword({'stuff'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see my offers.'})

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, text = 'If you need general {equipment}, just ask me for a {trade}. I can also provide you with some general {hints} about the game.'})

keywordHandler:addKeyword({'equip'}, StdModule.say, {npcHandler = npcHandler, text = 'As an adventurer, you should always have at least a {backpack}, a {rope}, a {shovel}, a {weapon}, an {armor} and a {shield}.'})

keywordHandler:addKeyword({'how', 'are', 'you'}, StdModule.say, {npcHandler = npcHandler, text = 'I\'m feeling good. I\'m so glad to have you here as my customer.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I\'m a merchant. Just ask me for a {trade} to see my offers.'})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = 'My name is Al Dee, but you can call me Al. Can I interest you in a {trade}.'})

-- Names
keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, text = 'He is just an old monk. However, he can heal you if you are badly injured or poisoned.'})  

-- Backpacks
local function creatureSayCallback(cid, type, msg)
local player = Player(cid)
keywordHandler:addKeyword({'pirate'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate backpack} for You?'})
boxKeyword = keywordHandler:addKeyword({'pirate backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'Do you have all 4 pieces of pirate set and pirate bag?'})
    if msgcontains(msg, 'pirate backpack') then
            if player:getItemCount(5462) > 0 and player:getItemCount(5918) > 0 and player:getItemCount(5927) > 0 and player:getItemCount(6095) > 0 and player:getItemCount(6096) > 0 then
                player:removeItem(5462, 1)
                player:removeItem(5918, 1)
                player:removeItem(5927, 1)
                player:removeItem(6095, 1)
                player:removeItem(6096, 1)              
                player:addItem(5926, 1)
                npcHandler:say('Here You go! I\'ll use Your ingredients to make second backpack and sell it to Tom', cid)
            else
                npcHandler:say('HEY! You don\'t have them!', cid)
            end
        end
    return true
end      

--Citizen first addon backpack--
function playerBuyAddonNPC(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if (parameters.confirm ~= true) and (parameters.decline ~= true) then
        if (getPlayerStorageValue(cid, parameters.storageID) ~= -1) then
            npcHandler:say('You already have backpack addon!', cid)
            npcHandler:resetNpc()
            return true
        end
        local itemsTable = parameters.items
        local items_list = '!!'
        local text = '??'
        if (parameters.cost > 0) and table.maxn(parameters.items) then
            text = items_list .. ' and ' .. parameters.cost .. ' gp'
        elseif (parameters.cost > 0) then
            text = parameters.cost .. ' gp'
        elseif table.maxn(parameters.items) then
            text = items_list
        end
        npcHandler:say('Did you brign me 50 Minotaur leathers and 50 Orc leathers for citizen bakpack addon?', cid)
        return true
    elseif (parameters.confirm == true) then
        local addonNode = node:getParent()
        local addoninfo = addonNode:getParameters()
        local items_number = 0
        if table.maxn(addoninfo.items) > 0 then
            for i = 1, table.maxn(addoninfo.items) do
                local item = addoninfo.items[i]
                if (getPlayerItemCount(cid,item[1]) >= item[2]) then
                    items_number = items_number + 1
                end
            end
        end
        if(getPlayerMoney(cid) >= addoninfo.cost) and (items_number == table.maxn(addoninfo.items)) then
            doPlayerRemoveMoney(cid, addoninfo.cost)
            if table.maxn(addoninfo.items) > 0 then
                for i = 1, table.maxn(addoninfo.items) do
                    local item = addoninfo.items[i]
                    doPlayerRemoveItem(cid,item[1],item[2])
                end
            end
            doPlayerAddOutfit(cid, addoninfo.outfit_male, addoninfo.addon)
            doPlayerAddOutfit(cid, addoninfo.outfit_female, addoninfo.addon)
            setPlayerStorageValue(cid,addoninfo.storageID,1)
            npcHandler:say('You look better now!.', cid)
        else
            npcHandler:say('You do not have enough leathers!', cid)
        end
        npcHandler:resetNpc()
        return true
    elseif (parameters.decline == true) then
        npcHandler:say('Why bothering me then?', cid)
        npcHandler:resetNpc()
        return true
    end
    return false
end

local noNode = KeywordNode:new({'no'}, playerBuyAddonNPC, {decline = true})
local yesNode = KeywordNode:new({'yes'}, playerBuyAddonNPC, {confirm = true})

local outfit_node = keywordHandler:addKeyword({'addon'}, playerBuyAddonNPC, {premium = false, cost = 0, items = {{5878,50}, {12435,50}}, outfit_female = 128, outfit_male = 136, addon = 1, storageID = 10041})
    outfit_node:addChildKeywordNode(yesNode)
    outfit_node:addChildKeywordNode(noNode)

npcHandler:addModule(FocusModule:new())
 
anybody? :/
Let me know how this works:
Lua:
local pirate_items = {5462, 5918, 5927, 6095, 6096}

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, "pirate backpack") then
            npcHandler:say("Do you have all 4 pieces of pirate set and pirate bag?", cid)
            npcHandler.topic[cid] = 1
        elseif msgcontains(msg, "pirate") then
            npcHandler:say("You want me to make {pirate backpack} for you?", cid)
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(pirate_items) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('HEY! You don\'t have them!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(pirate_items) do
                player:removeItem(itemid, 1)
            end
            player:addItem(5926, 1)
            npcHandler:say('Here You go! I\'ll use your ingredients to make second backpack and sell it to Tom.', cid)
        else
            npcHandler:say("Okay then.", cid)   
        end
        npcHandler.topic[cid] = 0
    end
    return true
end
 
Lua:
-- Backpacks
keywordHandler:addKeyword({'backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate}, {fur}, {minotaur} or {expedition} backpack for you?'})

local pirate_items = {5462, 5918, 5927, 6095, 6096}

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'pirate') then
            npcHandler:say('Do you have all 4 pieces of pirate set and pirate bag?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(pirate_items) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('HEY! You don\'t have them!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(pirate_items) do
                player:removeItem(itemid, 1)
            end
            player:addItem(5926, 1)
            npcHandler:say('Here You go! I\'ll use your ingredients to make second backpack and sell it to Tom.', cid)
        else
            npcHandler:say("Okay then.", cid)  
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

Thank You for the answear, I see how you put all this items in one pirate items line, unfortunately npc doesn''t respond.
I thought it may be because of using similar words in different lines {pirate backpack}, {pirate} and {backpack} so I separated them by changing dialogue... it didn't fix respond either. Console still doesn't show any error message...

I don't know, may it be because I'm using some kind of old libaries or idk old code, not proper for tfs 1.3?
That is why I put line with backpack ask, and he replies me correctily

Zo0c6FX.png
 
Last edited:
Lua:
-- Backpacks
keywordHandler:addKeyword({'backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate}, {fur}, {minotaur} or {expedition} backpack for you?'})

local pirate_items = {5462, 5918, 5927, 6095, 6096}

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'pirate') then
            npcHandler:say('Do you have all 4 pieces of pirate set and pirate bag?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(pirate_items) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('HEY! You don\'t have them!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(pirate_items) do
                player:removeItem(itemid, 1)
            end
            player:addItem(5926, 1)
            npcHandler:say('Here You go! I\'ll use your ingredients to make second backpack and sell it to Tom.', cid)
        else
            npcHandler:say("Okay then.", cid)
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

Thank You for the answear, I see how you put all this items in one pirate items line, unfortunately npc doesn''t respond.
I thought it may be because of using similar words in different lines {pirate backpack}, {pirate} and {backpack} so I separated them by changing dialogue... it didn't fix respond either. Console still doesn't show any error message...

I don't know, may it be because I'm using some kind of old libaries or idk old code, not proper for tfs 1.3?
That is why I put line with backpack ask, and he replies me correctily

Zo0c6FX.png
It works fine on my TFS 1.3. Do you have this at the bottom of your npc lua file?
Lua:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

This is what the whole code should look like:
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 pirate_items = {5462, 5918, 5927, 6095, 6096}

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'backpack') then
            npcHandler:say('You want me to make {pirate}, {fur}, {minotaur} or {expedition} backpack for you?', cid)
        elseif msgcontains(msg, 'pirate') then
            npcHandler:say('Do you have all 4 pieces of pirate set and pirate bag?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(pirate_items) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('HEY! You don\'t have them!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(pirate_items) do
                player:removeItem(itemid, 1)
            end
            player:addItem(5926, 1)
            npcHandler:say('Here You go! I\'ll use your ingredients to make second backpack and sell it to Tom.', cid)
        else
            npcHandler:say("Okay then.", cid) 
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Solution
GRRRR! Kill me... Each part of backpacks works separately perfect...
but when combined all together only last backpack local function works...


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 voices = {
    { text = 'Are you looking for the best tools? Come to my shop!' },
    { text = 'Feeling lost? You can always ask me about general hints!' },
    { text = 'Tools and general equipment at Al Dee\'s!' },
    { text = 'Don\'t head for adventure without a rope and torches! Buy your supplies here!' }
}

-- Greets --
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Those kids today are more and more rud...')
npcHandler:setMessage(MESSAGE_FAREWELL, 'Have a nice day |PLAYERNAME|!')
npcHandler:setMessage(MESSAGE_SENDTRADE, 'Take a look in the trade window to your left.')
npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|. If You have tools, or need one just ask me to {Trade}. We will make a good deal!')

-- Basic Keywords --
keywordHandler:addKeyword({'hint'}, StdModule.rookgaardHints, {npcHandler = npcHandler})
keywordHandler:addKeyword({'sell'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see what I buy from you.'})
keywordHandler:addKeyword({'stuff'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see my offers.'})

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, text = 'If you need general {equipment}, just ask me for a {trade}. I can also provide you with some general {hints} about the game.'})

keywordHandler:addKeyword({'equip'}, StdModule.say, {npcHandler = npcHandler, text = 'As an adventurer, you should always have at least a {backpack}, a {rope}, a {shovel}, a {weapon}, an {armor} and a {shield}.'})

keywordHandler:addKeyword({'how', 'are', 'you'}, StdModule.say, {npcHandler = npcHandler, text = 'I\'m feeling good. I\'m so glad to have you here as my customer.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = 'I\'m a merchant. Just ask me for a {trade} to see my offers.'})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = 'My name is Al Dee, but you can call me Al. Can I interest you in a {trade}?'})
keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, text = 'It\'s about |TIME|. I\'m so sorry, I have no watches to sell. Do you want to buy something else?'})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, text = 'If you want to challenge monsters in the {dungeons}, you need some {weapons} and {armor} from the local {merchants}.'})
keywordHandler:addKeyword({'dungeon'}, StdModule.say, {npcHandler = npcHandler, text = 'If you want to explore the dungeons such as the {sewers}, you have to {equip} yourself with the vital stuff I am selling. It\'s {vital} in the deepest sense of the word.'})
keywordHandler:addKeyword({'sewer'}, StdModule.say, {npcHandler = npcHandler, text = 'Oh, our sewer system is very primitive - it\'s so primitive that it\'s overrun by {rats}. But the stuff I sell is safe from them. Just ask me for a {trade} to see it!'})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, text = 'The king encouraged salesmen to travel here, but only I dared to take the risk, and a risk it was!'})
keywordHandler:addKeyword({'bug'}, StdModule.say, {npcHandler = npcHandler, text = 'Bugs plague this isle, but my wares are bug-free, totally bug-free.'})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, text = 'One day I will return to the continent as a rich, a very rich man!'})
keywordHandler:addKeyword({'thais'}, StdModule.say, {npcHandler = npcHandler, text = 'Thais is a crowded town.'})
keywordHandler:addKeyword({'mainland'}, StdModule.say, {npcHandler = npcHandler, text = 'Have you ever wondered what that \'main\' is people are talking about? Well, once you\'ve reached level 8, you should talk to the {oracle}. You can choose a {profession} afterwards and explore much more of Tibia.'})
keywordHandler:addKeyword({'weapon'}, StdModule.say, {npcHandler = npcHandler, text = 'Oh, I\'m sorry, but I don\'t deal with weapons. That\'s {Obi\'s} or {Lee\'Delle\'s} business. I could offer you a {pick} in exchange for a {small axe} if you should happen to own one.'})
keywordHandler:addKeyword({'armor'}, StdModule.say, {npcHandler = npcHandler, text = 'Armor and shields can be bought at {Dixi\'s} or at {Lee\'Delle\'s}. Dixi runs that shop near {Obi\'s}.'})
keywordHandler:addKeyword({'shield'}, StdModule.say, {npcHandler = npcHandler, text = 'Armor and shields can be bought at {Dixi\'s} or at {Lee\'Delle\'s}. Dixi runs that shop near {Obi\'s}.'})
keywordHandler:addKeyword({'cooki'}, StdModule.say, {npcHandler = npcHandler, text = 'I you want to find someone who may want to buy your cookies, you should meet Lily.'})
keywordHandler:addKeyword({'blueberr'}, StdModule.say, {npcHandler = npcHandler, text = 'Blueberries grow on bushes. They\'re quite common in Tibia. Just pick them from a bush if you need a snack!'})
keywordHandler:addKeyword({'potion'}, StdModule.say, {npcHandler = npcHandler, text = 'Sorry, I don\'t sell potions. You should visit {Lily} for that.'})
keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, text = 'Hmm, the best address to look for food might be {Willie} or {Billy}. {Norma} also has some snacks for sale.'})
keywordHandler:addKeyword({'bank'}, StdModule.say, {npcHandler = npcHandler, text = 'A bank is quite useful. You can deposit your money safely there. This way you don\'t have to carry it around with you all the time. You could also invest your money in my {wares}!'})
keywordHandler:addKeyword({'academy'}, StdModule.say, {npcHandler = npcHandler, text = 'The big building in the centre of Rookgaard. They have a library, a training centre, a {bank} and the room of the {oracle}. {Seymour} is the teacher there.'})
keywordHandler:addKeyword({'temple'}, StdModule.say, {npcHandler = npcHandler, text = 'The monk {Cipfried} takes care of our temple. He can heal you if you\'re badly injured or poisoned.'})
keywordHandler:addKeyword({'premium'}, StdModule.say, {npcHandler = npcHandler, text = 'As a premium adventurer you have many advantages. You really should check them out!'})
keywordHandler:addKeyword({'citizen'}, StdModule.say, {npcHandler = npcHandler, text = 'If you tell me the name of a citizen, I\'ll tell you what I know about him or her.'})
keywordHandler:addKeyword({'merchant'}, StdModule.say, {npcHandler = npcHandler, text = 'To view the offers of a merchant, simply talk to him or her and ask for a {trade}. They will gladly show you their offers and also the things they buy from you.'})
keywordHandler:addKeyword({'profession'}, StdModule.say, {npcHandler = npcHandler, text = 'You will learn everything you need to know about professions once you\'ve reached the {Island of Destiny}.'})
keywordHandler:addKeyword({'destiny'}, StdModule.say, {npcHandler = npcHandler, text = 'The Island of Destiny can be reached via the {oracle} once you are level 8. This trip will help you choose your {profession}!'})

keywordHandler:addKeyword({'torch'}, StdModule.say, {npcHandler = npcHandler, text = 'No thank you. I can already overstock the market with torches.'})
keywordHandler:addKeyword({'fishing'}, StdModule.say, {npcHandler = npcHandler, text = 'I sell fishing rods and worms if you want to fish. Simply ask me for a {trade}.'})
keywordHandler:addKeyword({'shovel'}, StdModule.say, {npcHandler = npcHandler, text = 'Yes, I am selling that. Simply ask me for a {trade} to view all my offers.'})

-- Names
keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, text = 'He is just an old monk. However, he can heal you if you are badly injured or poisoned.'})
keywordHandler:addKeyword({'zirella'}, StdModule.say, {npcHandler = npcHandler, text = 'Poor old woman, her son {Tom} never visits her.'})
keywordHandler:addKeyword({'santiago'}, StdModule.say, {npcHandler = npcHandler, text = 'He dedicated his life to welcome newcomers to this island.'})
keywordHandler:addKeyword({'loui'}, StdModule.say, {npcHandler = npcHandler, text = 'No idea who that is.'})
keywordHandler:addKeyword({'al', 'dee'}, StdModule.say, {npcHandler = npcHandler, text = 'Yep, that\'s me. Smart of you to notice that!'})
keywordHandler:addKeyword({'paulie'}, StdModule.say, {npcHandler = npcHandler, text = 'He\'s the local {bank} clerk.'})
keywordHandler:addKeyword({'hyacinth'}, StdModule.say, {npcHandler = npcHandler, text = 'He mostly stays by himself. He\'s a hermit outside of town - good luck finding him.'})
keywordHandler:addKeyword({'dixi'}, StdModule.say, {npcHandler = npcHandler, text = 'She\'s {Obi\'s} granddaughter and deals with {armors} and {shields}. Her shop is south west of town, close to the {temple}.'})
keywordHandler:addKeyword({'obi'}, StdModule.say, {npcHandler = npcHandler, text = 'He sells {weapons}. His shop is south west of town, close to the {temple}.'})
keywordHandler:addKeyword({'lee\'delle'}, StdModule.say, {npcHandler = npcHandler, text = 'If you are a {premium} adventurer, you should check out {Lee\'Delle\'s} shop. She lives in the western part of town, just across the bridge.'})
keywordHandler:addKeyword({'tom'}, StdModule.say, {npcHandler = npcHandler, text = 'He\'s the local tanner. You could try selling fresh corpses or leather to him.'})
keywordHandler:addKeyword({'amber'}, StdModule.say, {npcHandler = npcHandler, text = 'She\'s currently recovering from her travels in the {academy}. It\'s always nice to chat with her!'})
keywordHandler:addKeyword({'oracle'}, StdModule.say, {npcHandler = npcHandler, text = 'You can find the oracle on the top floor of the {academy}, just above {Seymour}. Go there when you are level 8.'})
keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, text = 'Seymour is a teacher running the {academy}. He has many important {information} about Tibia.'})
keywordHandler:addKeyword({'lily'}, StdModule.say, {npcHandler = npcHandler, text = 'She sells health {potions} and antidote potions. Also, she buys {blueberries} and {cookies} in case you find any.'})
keywordHandler:addKeyword({'willie'}, StdModule.say, {npcHandler = npcHandler, text = 'This is a local farmer. If you need fresh {food} to regain your health, it\'s a good place to go. However, many monsters also carry food such as meat or cheese. Or you could simply pick {blueberries}.'})
keywordHandler:addKeyword({'billy'}, StdModule.say, {npcHandler = npcHandler, text = 'This is a local farmer. If you need fresh {food} to regain your health, it\'s a good place to go. He\'s only trading with {premium} adventurers though.'})
keywordHandler:addKeyword({'norma'}, StdModule.say, {npcHandler = npcHandler, text = 'She used to sell equipment, but I think she has opened a small bar now. Talks about changing her name to \'Mary\' and such, strange girl.'})
keywordHandler:addKeyword({'zerbrus'}, StdModule.say, {npcHandler = npcHandler, text = 'Some call him a hero. He protects the town from {monsters}.'})   

-- Backpacks
keywordHandler:addKeyword({'backpack'}, StdModule.say, {npcHandler = npcHandler, text = 'You want me to make {pirate}, {fur}, {minotaur} or {expedition} backpack for you?'})

local piratebp = {5462, 5918, 5927, 6095, 6096}
local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'pirate') then
            npcHandler:say('Do you have all 4 pieces of pirate set and pirate bag?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(piratebp) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('HEY! You don\'t have them!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(piratebp) do
                player:removeItem(itemid, 1)
            end
            player:addItem(5926, 1)
            npcHandler:say('Here You go! I\'ll use your ingredients to make second backpack and sell it to Tom.', cid)
        else
            npcHandler:say("Okay then.", cid)   
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

local minotaurbp = {5878, 12428}
local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'minotaur') then
            npcHandler:say('Do you have both 50 minotaur leathers and horns for the minotaur backpack?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(minotaurbp) do
                if player:getItemCount(itemid) < 50 then
                    npcHandler:say('HEY! You don\'t have what I need!', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(minotaurbp) do
                player:removeItem(itemid, 50)
            end
            player:addItem(11244, 1)
            npcHandler:say('Have it then horny |PLAYERNAME|', cid)
        else
            npcHandler:say("Maybe another time", cid)   
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

local furbp = {5896, 11235, 11212, 11209, 11216}
local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'fur') then
            npcHandler:say('Listen then, I need fur, 10 of each: Bear (could be bear paws), Warwolf, Badger, Winter wolf and Silky fur to sew inside. Do You have them now?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(furbp) do
                if player:getItemCount(itemid) < 10 then
                    npcHandler:say('No, You don\'t', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
            for key, itemid in pairs(furbp) do
                player:removeItem(itemid, 10)
            end
            player:addItem(7342, 1)
            npcHandler:say('Excellent! In cold winter you can throw everything out and use it as a tent! ', cid)
        else
            npcHandler:say("Um, okay..", cid)   
        end
        npcHandler.topic[cid] = 0
    end
    return true
end


local expeditionbp = {11242, 7731, 5710, 2563, 2580, 11421}
local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        if msgcontains(msg, 'expedition') then
            npcHandler:say('I need some example, if You find bring expedition bag. Ow of course You will need also special light tools: matchete, elvenhair rope, light shovel, dwarven pick, pan and.. fishing rod.. You know better to carry than to ask for.. Ow, You already have them?', cid)
            npcHandler.topic[cid] = 1
        end
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            for key, itemid in pairs(expeditionbp) do
                if player:getItemCount(itemid) < 1 then
                    npcHandler:say('Better start looking for all this tools', cid)
                    npcHandler.topic[cid] = 0
                    return true
                end
            end
                do player:removeItem(11242, 1)
            end
            player:addItem(11241, 1)
            npcHandler:say('Sure You do! This backpack is really spacious! I\'m really proud of it, don\'t loose it!', cid)
        else
            npcHandler:say("Whatever..", cid)   
        end
        npcHandler.topic[cid] = 0
    end
    return true
end

--Citizen first addon backpack--
function playerBuyAddonNPC(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if (parameters.confirm ~= true) and (parameters.decline ~= true) then
        if (getPlayerStorageValue(cid, parameters.storageID) ~= -1) then
            npcHandler:say('You already have backpack addon!', cid)
            npcHandler:resetNpc()
            return true
        end
        local itemsTable = parameters.items
        local items_list = '!!'
        local text = '??'
        if (parameters.cost > 0) and table.maxn(parameters.items) then
            text = items_list .. ' and ' .. parameters.cost .. ' gp'
        elseif (parameters.cost > 0) then
            text = parameters.cost .. ' gp'
        elseif table.maxn(parameters.items) then
            text = items_list
        end
        npcHandler:say('Did you bring me 50 Minotaur leathers and 50 Orc leathers for citizen backpack addon?', cid)
        return true
    elseif (parameters.confirm == true) then
        local addonNode = node:getParent()
        local addoninfo = addonNode:getParameters()
        local items_number = 0
        if table.maxn(addoninfo.items) > 0 then
            for i = 1, table.maxn(addoninfo.items) do
                local item = addoninfo.items[i]
                if (getPlayerItemCount(cid,item[1]) >= item[2]) then
                    items_number = items_number + 1
                end
            end
        end
        if(getPlayerMoney(cid) >= addoninfo.cost) and (items_number == table.maxn(addoninfo.items)) then
            doPlayerRemoveMoney(cid, addoninfo.cost)
            if table.maxn(addoninfo.items) > 0 then
                for i = 1, table.maxn(addoninfo.items) do
                    local item = addoninfo.items[i]
                    doPlayerRemoveItem(cid,item[1],item[2])
                end
            end
            doPlayerAddOutfit(cid, addoninfo.outfit_male, addoninfo.addon)
            doPlayerAddOutfit(cid, addoninfo.outfit_female, addoninfo.addon)
            setPlayerStorageValue(cid,addoninfo.storageID,1)
            npcHandler:say('You look better now!.', cid)
        else
            npcHandler:say('You do not have enough leathers!', cid)
        end
        npcHandler:resetNpc()
        return true
    elseif (parameters.decline == true) then
        npcHandler:say('Why bothering me then?', cid)
        npcHandler:resetNpc()
        return true
    end
    return false
end

local noNode = KeywordNode:new({'no'}, playerBuyAddonNPC, {decline = true})
local yesNode = KeywordNode:new({'yes'}, playerBuyAddonNPC, {confirm = true})

local outfit_node = keywordHandler:addKeyword({'addon'}, playerBuyAddonNPC, {premium = false, cost = 0, items = {{5878,50}, {12435,50}}, outfit_female = 128, outfit_male = 136, addon = 1, storageID = 10041})
    outfit_node:addChildKeywordNode(yesNode)
    outfit_node:addChildKeywordNode(noNode)

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

How to fix this :/ I know I could simple give each npc each backpack but that's not the point, I wish one NPC could exchange few types of items...
 
Back
Top