• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Headhunter! Silver token exchanger!

tommy91

Member
Joined
Oct 27, 2010
Messages
269
Solutions
1
Reaction score
21
Location
Sweden
Heya! I have a Npc that exchange creature products for Silver Tokens! But he is bugged in a way that when i want to exchange he will say that i dont have the stuff.

Please help!



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

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) end
function onThink() npcHandler:eek:nThink() end

local item = 'I\'m sorry, but you do not have the required items for this trade.'
local done = 'Here you are, thank you for your business.'

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

if msg == 'creature products' then
npcHandler:say('I am interested in {frazzle skins}, {red dragon scales}, {draken sulphurs}, {demonic essences}, {soul orbs}, {snake skins}, {compound eyes} and {wyrm scales}', cid)
elseif msgcontains(msg, 'frazzle skins') then
if getPlayerItemCount(cid,22533) >= 40 then
npcHandler:say('Did you bring me the 40 frazzle skins?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {40 frazzle skins}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,22533) >= 40 then
if doPlayerRemoveItem(cid,22533, 40) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'red dragon scales') then
if getPlayerItemCount(cid,5882) >= 20 then
npcHandler:say('Did you bring me the 20 red dragon scales?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {20 red dragon scales}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,5882) >= 20 then
if doPlayerRemoveItem(cid,5882, 20) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'draken sulphurs') then
if getPlayerItemCount(cid,12614) >= 30 then
npcHandler:say('Did you bring me the 30 draken sulphurs?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {30 draken sulphurs}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,12614) >= 30 then
if doPlayerRemoveItem(cid,22533, 30) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'demonic essences') then
if getPlayerItemCount(cid,6500) >= 50 then
npcHandler:say('Did you bring me the 50 demonic essences?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {50 demonic essences}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,6500) >= 50 then
if doPlayerRemoveItem(cid,6500, 50) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'soul orbs') then
if getPlayerItemCount(cid,5944) >= 100 then
npcHandler:say('Did you bring me the 100 soul orbs?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {100 soul orbs}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,5944) >= 100 then
if doPlayerRemoveItem(cid,5944, 100) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'snake skins') then
if getPlayerItemCount(cid,10611) >= 30 then
npcHandler:say('Did you bring me the 30 snake skins?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {30 snake skins}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,10611) >= 30 then
if doPlayerRemoveItem(cid,10611, 30) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'compound eyes') then
if getPlayerItemCount(cid,15486) >= 100 then
npcHandler:say('Did you bring me the 100 compound eyes?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {100 compound eyes}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,15486) >= 100 then
if doPlayerRemoveItem(cid,15486, 100) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'wyrm scales') then
if getPlayerItemCount(cid,10582) >= 100 then
npcHandler:say('Did you bring me the 100 wyrm scales?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {100 wyrm scales}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,10582) >= 100 then
if doPlayerRemoveItem(cid,10582, 100) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
else
npcHandler:say(item, cid)
end
if msgcontains(msg, 'no') and npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 15 then
npcHandler:say('Well, then leave.')
npcHandler.topic[cid] = 0
end

return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
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 item = 'I\'m sorry, but you do not have the required items for this trade.'
local done = 'Here you are, thank you for your business.'

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

if msg == 'creature products' then
npcHandler:say('I am interested in {frazzle skins}, {red dragon scales}, {draken sulphurs}, {demonic essences}, {soul orbs}, {snake skins}, {compound eyes} and {wyrm scales}', cid)
elseif msgcontains(msg, 'frazzle skins') then
if getPlayerItemCount(cid,22533) >= 40 then
npcHandler:say('Did you bring me the 40 frazzle skins?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {40 frazzle skins}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,22533) >= 40 then
if doPlayerRemoveItem(cid,22533, 40) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'red dragon scales') then
if getPlayerItemCount(cid,5882) >= 20 then
npcHandler:say('Did you bring me the 20 red dragon scales?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {20 red dragon scales}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,5882) >= 20 then
if doPlayerRemoveItem(cid,5882, 20) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'draken sulphurs') then
if getPlayerItemCount(cid,12614) >= 30 then
npcHandler:say('Did you bring me the 30 draken sulphurs?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {30 draken sulphurs}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,12614) >= 30 then
if doPlayerRemoveItem(cid,22533, 30) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'demonic essences') then
if getPlayerItemCount(cid,6500) >= 50 then
npcHandler:say('Did you bring me the 50 demonic essences?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {50 demonic essences}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,6500) >= 50 then
if doPlayerRemoveItem(cid,6500, 50) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'soul orbs') then
if getPlayerItemCount(cid,5944) >= 100 then
npcHandler:say('Did you bring me the 100 soul orbs?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {100 soul orbs}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,5944) >= 100 then
if doPlayerRemoveItem(cid,5944, 100) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'snake skins') then
if getPlayerItemCount(cid,10611) >= 30 then
npcHandler:say('Did you bring me the 30 snake skins?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {30 snake skins}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,10611) >= 30 then
if doPlayerRemoveItem(cid,10611, 30) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'compound eyes') then
if getPlayerItemCount(cid,15486) >= 100 then
npcHandler:say('Did you bring me the 100 compound eyes?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {100 compound eyes}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,15486) >= 100 then
if doPlayerRemoveItem(cid,15486, 100) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
elseif msgcontains(msg, 'wyrm scales') then
if getPlayerItemCount(cid,10582) >= 100 then
npcHandler:say('Did you bring me the 100 wyrm scales?', cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('I need {100 wyrm scales}. Please come back when you have them.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 0
if getPlayerItemCount(cid,10582) >= 100 then
if doPlayerRemoveItem(cid,10582, 100) == TRUE then
npcHandler:say(done, cid)
doPlayerAddItem(cid, 21399, 1)
end
else
npcHandler:say(item, cid)
end
else
npcHandler:say(item, cid)
end
if msgcontains(msg, 'no') and npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 15 then
npcHandler:say('Well, then leave.')
npcHandler.topic[cid] = 0
end

return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Do you get any error in the console?
 
I dont get an error message, all he says is;
17:12 Headhunter: I'm sorry, but you do not have the required items for this trade.
 
Ive got another error!


Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Headhunter.lua:onCreatureSay
NpcScriptInterface::luagetDistanceTo(). Thing not found
stack traceback:
        [C]: in function 'getDistanceTo'
        data/npc/lib/npcsystem/npchandler.lua:560: in function 'isInRange'
        data/npc/lib/npcsystem/npchandler.lua:401: in function 'onCreatureSay'
        data/npc/scripts/Headhunter.lua:7: in function <data/npc/scripts/Headhun
ter.lua:7>
 
I would start by checking
data\npc\lib\npcsystem\npchandler.lua

This function:

Code:
        -- Handles onCreatureSay events. If you with to handle this yourself, please use the CALLBACK_CREATURE_SAY callback.
        function NpcHandler:onCreatureSay(creature, msgtype, msg)
                local cid = creature:getId()
                local callback = self:getCallback(CALLBACK_CREATURE_SAY)
                if callback == nil or callback(cid, msgtype, msg) then
                        if self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, msgtype, msg) then
                                if not self:isInRange(cid) then
                                        return
                                end

                                if self.keywordHandler ~= nil then
                                        if self:isFocused(cid) and msgtype == TALKTYPE_PRIVATE_PN or not self:isFocused(cid) then
                                                local ret = self.keywordHandler:processMessage(cid, msg)
                                                if(not ret) then
                                                        local callback = self:getCallback(CALLBACK_MESSAGE_DEFAULT)
                                                        if callback ~= nil and callback(cid, msgtype, msg) then
                                                                self.talkStart[cid] = os.time()
                                                        end
                                                else
                                                        self.talkStart[cid] = os.time()
                                                end
                                        end
                                end
                        end
                end
        end


And this function:

Code:
        -- Returns true if cid is within the talkRadius of this npc.
        function NpcHandler:isInRange(cid)
                local distance = Player(cid) ~= nil and getDistanceTo(cid) or -1
                if distance == -1 then
                        return false
                end

                return distance <= self.talkRadius
        end

Can you post yours? And when you post code can you put it in this format?
[...code]
Your code here
[/...code]
 
Here ye go!

Code:
    -- Handles onCreatureSay events. If you with to handle this yourself, please use the CALLBACK_CREATURE_SAY callback.
    function NpcHandler:onCreatureSay(creature, msgtype, msg)
        local cid = creature.uid
        local callback = self:getCallback(CALLBACK_CREATURE_SAY)
        if callback == nil or callback(cid, msgtype, msg) then
            if self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, msgtype, msg) then
                if not self:isInRange(cid) then
                    return
                end

                if self.keywordHandler ~= nil then
                    if self:isFocused(cid) and msgtype == TALKTYPE_PRIVATE_PN or not self:isFocused(cid) then
                        local ret = self.keywordHandler:processMessage(cid, msg)
                        if not ret then
                            local callback = self:getCallback(CALLBACK_MESSAGE_DEFAULT)
                            if callback ~= nil and callback(cid, msgtype, msg) then
                                self.talkStart[cid] = os.time()
                            end
                        else
                            self.talkStart[cid] = os.time()
                        end
                    end
                end
            end
        end
    end

Code:
    -- Returns true if cid is within the talkRadius of this npc.
    function NpcHandler:isInRange(cid)
        local distance = Player(cid) ~= nil and getDistanceTo(cid) or -1
        if distance == -1 then
            return false
        end

        return distance <= self.talkRadius
    end
 
Can you try replacing the first function you posted with this one, and tell me what error it gives you?

Code:
        -- Handles onCreatureSay events. If you with to handle this yourself, please use the CALLBACK_CREATURE_SAY callback.
        function NpcHandler:onCreatureSay(creature, msgtype, msg)
                local cid = creature:getId()
                local callback = self:getCallback(CALLBACK_CREATURE_SAY)
                if callback == nil or callback(cid, msgtype, msg) then
                        if self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, msgtype, msg) then
                                if not self:isInRange(cid) then
                                        return
                                end

                                if self.keywordHandler ~= nil then
                                        if self:isFocused(cid) and msgtype == TALKTYPE_PRIVATE_PN or not self:isFocused(cid) then
                                                local ret = self.keywordHandler:processMessage(cid, msg)
                                                if(not ret) then
                                                        local callback = self:getCallback(CALLBACK_MESSAGE_DEFAULT)
                                                        if callback ~= nil and callback(cid, msgtype, msg) then
                                                                self.talkStart[cid] = os.time()
                                                        end
                                                else
                                                        self.talkStart[cid] = os.time()
                                                end
                                        end
                                end
                        end
                end
        end

image.jpg


I didn't receive an error, but I'm using a different version of TFS so I would like to know what it tells you.
 
Sorry for the double post... But you said something about him saying the same thing. At the bottom of your script:

Code:
    else
        npcHandler:say('I'm sorry, but you do not have the required items for this trade.', cid)
    end
 
    if msgcontains(msg, 'no') and npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 15 then
        npcHandler:say('Well, then leave.')
        npcHandler.topic[cid] = 0
    end

    return true
end

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

The line after else... npcHandler:say('I'm sorry, but you do not have the required items for this trade') is what he will return if the player says anything not listed, so if they say help, he will say you don't have the items required.

So I'm not sure if you would like for the player to have to figure out what to say, but this is what you should change in order to make it not always return that you don't have the items.

Example:

Code:
    elseif msg == 'help' then
        npcHandler:say('I am interested in creature products. Ask me about them.', cid)
    else
        npcHandler:say('What do you need?', cid)
    end
 
    if msgcontains(msg, 'no') and npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 15 then
        npcHandler:say('Well, then leave.')
        npcHandler.topic[cid] = 0
    end

    return true
end

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