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

Solved Npc trade window when greet

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
Hello, I'm here trying making my npcs open the trade window when I say "hi", but I did not find the way....
TFS 1.2
in data/npc/lib/npcsystem/npchandler,lua
I find the function of greet players, then I want to do something to get working what I'm asking for..
Code:
function NpcHandler:greet(cid, message)
        if cid ~= 0  then
            local callback = self:getCallback(CALLBACK_GREET)
            if callback == nil or callback(cid, message) then
                if self:processModuleCallback(CALLBACK_GREET, cid) then
                    local msg = self:getMessage(MESSAGE_GREET)
                    local parseInfo = { [TAG_PLAYERNAME] = Player(cid):getName() }
                    msg = self:parseMessage(msg, parseInfo)
                    self:say(msg, cid, true)
                else
                    return
                end
            else
                return
            end
        end
        self:addFocus(cid)
    end
I don't find the function that call the trade window... :/
thanks
 
check modules.lua (its in the same file as npchandler.lua)

Code:
    -- The words for requesting trade window.
    SHOP_TRADEREQUEST = {"trade"}
 
checked and test, if I put "hi" in the SHOP_TRADEREQUEST don't work, and same saying trade the npc don't open the window
 
changed the

Code:
    -- The word for requesting trade window. For more information look at the top of modules.lua
    SHOP_TRADEREQUEST = {'trade'}

in npcsystem.lua (still same folder)

Worked for me :)
 
already do it...
the npc only open the window if I say "hi" again...
you don't understand what I trying to do...
 
modules.lua

find function FocusModule.onGreet(cid, message, keywords, parameters) and replace with this

Code:
    function FocusModule.onGreet(cid, message, keywords, parameters)
    
        local module = parameters.module

        if not module.npcHandler:onTradeRequest(cid) then
            parameters.module.npcHandler:onGreet(cid)
            return true
        end
        

        local itemWindow = {}
        for i = 1, #module.npcHandler.shopItems do
            itemWindow[#itemWindow + 1] = module.npcHandler.shopItems[i]
        end

        if itemWindow[1] == nil then
            local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
            local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_NOSHOP), parseInfo)
            module.npcHandler:say(msg, cid)
            return true
        end

        local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
        local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_SENDTRADE), parseInfo)
        openShopWindow(cid, itemWindow,
            function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks) end,
            function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks) end)
        module.npcHandler:say(msg, cid)

    
        parameters.module.npcHandler:onGreet(cid)
        return true
    end
 
works with the npcs that have offers to sell/buy, but when I try talk with banker for exemple he say "I'm not offering anything...", so, need to check if the npc have offers or not
 
Yeah it was blocked for npc that doesnt sell anything

Code:
    function FocusModule.onGreet(cid, message, keywords, parameters)
    
        local module = parameters.module

        if not module.npcHandler:onTradeRequest(cid) then
            parameters.module.npcHandler:onGreet(cid)
            return true
        end
        

        local itemWindow = {}
        for i = 1, #module.npcHandler.shopItems do
            itemWindow[#itemWindow + 1] = module.npcHandler.shopItems[i]
        end

        if itemWindow[1] == nil then
            parameters.module.npcHandler:onGreet(cid)
            return true
        end

        local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
        local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_SENDTRADE), parseInfo)
        openShopWindow(cid, itemWindow,
            function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks) end,
            function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks) end)
        module.npcHandler:say(msg, cid)

    
        parameters.module.npcHandler:onGreet(cid)
        return true
    end

I cant check it now, but should work
 
Back
Top