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

TFS 1.X+ [TFS 1.5] buy without having to say "buy" to an npc

Shoorkill

Active Member
Joined
Dec 17, 2018
Messages
153
Reaction score
25
Good evening friends, my server is based on another server that I already had for a while, an evolutions 7.92, and there we bought it without having to say buy, for example: hi 10 meat yes, and received the product, instead of say hi buy 10 meat yes... which way to make this change to remove the word "buy"? any willing soul?
 
Good evening friends, my server is based on another server that I already had for a while, an evolutions 7.92, and there we bought it without having to say buy, for example: hi 10 meat yes, and received the product, instead of say hi buy 10 meat yes... which way to make this change to remove the word "buy"? any willing soul?

Commit or remove this line
 
Last edited:
i think i got it to work but i changed so much in the modules.lua, i dont recommend it. xD

but to get both cases to work, you have to modify addBuyable function but also TradeItem function so that the NPC will respond when you say "sell item".
 
i think i got it to work but i changed so much in the modules.lua, i dont recommend it. xD

but to get both cases to work, you have to modify addBuyable function but also TradeItem function so that the NPC will respond when you say "sell item".
I see where to modify addBuyableItem to remove the "buy" keyword, but I don't see what changes to make to tradeItem. I assumed I would just have to change the order so it checks sell before buy, but it already does that. Do you remember how you got this working? Thanks!
 
I see where to modify addBuyableItem to remove the "buy" keyword, but I don't see what changes to make to tradeItem. I assumed I would just have to change the order so it checks sell before buy, but it already does that. Do you remember how you got this working? Thanks!
try my functions and see if it works for you (TFS 1.5). Owner of thread should mark this as the solution if it works.

addbuyableItem function:


LUA:
function ShopModule:addBuyableItem(names, itemid, cost, itemSubType, realName)
    itemSubType = itemSubType or 1
    local it = ItemType(itemid)
   
    if it:getId() == 0 then
        return -- Invalid item ID, simply return
    end

    local shopItem = self:getShopItem(itemid, itemSubType)
    if shopItem == nil then
        self.npcHandler.shopItems[#self.npcHandler.shopItems + 1] = {
            id = itemid,
            buy = cost,
            sell = -1,
            subType = itemSubType,
            name = realName or it:getName()
        }
    else
        shopItem.buy = cost
    end

    if names and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE then
        for _, name in pairs(names) do
            local parameters = {
                itemid = itemid,
                cost = cost,
                module = self,
                realName = realName or it:getName(),
                subType = itemSubType or 1
            }

            local keywords = {name}
            local node = self.npcHandler.keywordHandler:addKeyword(keywords, function(cid, message)
                if string.match(message:lower(), "^sell") then
                    parameters.eventType = SHOPMODULE_SELL_ITEM
                    local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                    if shopItem and shopItem.sell > 0 then
                        parameters.cost = shopItem.sell
                        ShopModule.tradeItem(cid, message, keywords, parameters, node)
                    else
                        --self.npcHandler:say("I cannot buy this item from you.", cid)
                    end
                else
                    parameters.eventType = SHOPMODULE_BUY_ITEM
                    local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                    if shopItem and shopItem.buy > 0 then
                        parameters.cost = shopItem.buy
                        ShopModule.tradeItem(cid, message, keywords, parameters, node)
                    else
                        self.npcHandler:say("I don't sell this item.", cid)
                    end
                end
            end, parameters)

            node:addChildKeywordNode(self.yesNode)
            node:addChildKeywordNode(self.noNode)
        end
    end
end

and tradeItem function:


Code:
function ShopModule.tradeItem(cid, message, keywords, parameters, node)
    local module = parameters.module
    if not module.npcHandler:isFocused(cid) then
        return false
    end

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

    local count = module:getCount(message)
    module.amount = count

    shop_amount[cid] = module.amount
    shop_cost[cid] = parameters.cost
    shop_rlname[cid] = parameters.realName
    shop_itemid[cid] = parameters.itemid
    shop_container[cid] = parameters.container
    shop_npcuid[cid] = getNpcCid()
    shop_eventtype[cid] = parameters.eventType
    shop_subtype[cid] = parameters.subType

    local parseInfo = {
        [TAG_PLAYERNAME] = Player(cid):getName(),
        [TAG_ITEMCOUNT] = shop_amount[cid],
        [TAG_TOTALCOST] = shop_cost[cid] * shop_amount[cid],
        [TAG_ITEMNAME] = shop_rlname[cid]
    }

    if shop_eventtype[cid] == SHOPMODULE_SELL_ITEM then
        local msg = module.npcHandler:getMessage(MESSAGE_SELL)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)

    elseif shop_eventtype[cid] == SHOPMODULE_BUY_ITEM then
        local msg = module.npcHandler:getMessage(MESSAGE_BUY)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)

        -- Dynamically create `yes` and `no` nodes
        local confirmNode = KeywordNode:new(SHOP_YESWORD, ShopModule.onConfirm, {module = module})
        local declineNode = KeywordNode:new(SHOP_NOWORD, ShopModule.onDecline, {module = module})

        if node then
            node:addChildKeywordNode(confirmNode)
            node:addChildKeywordNode(declineNode)
        else
            -- If `node` is nil, create a fallback temporary node
            local tempNode = module.npcHandler.keywordHandler:addKeyword({"yes"}, ShopModule.onConfirm, {module = module})
            tempNode:addChildKeywordNode(declineNode)
        end

    elseif shop_eventtype[cid] == SHOPMODULE_BUY_ITEM_CONTAINER then
        local msg = module.npcHandler:getMessage(MESSAGE_BUY)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)
    end
    return true
end
 
try my functions and see if it works for you (TFS 1.5). Owner of thread should mark this as the solution if it works.

addbuyableItem function:


LUA:
function ShopModule:addBuyableItem(names, itemid, cost, itemSubType, realName)
    itemSubType = itemSubType or 1
    local it = ItemType(itemid)
  
    if it:getId() == 0 then
        return -- Invalid item ID, simply return
    end

    local shopItem = self:getShopItem(itemid, itemSubType)
    if shopItem == nil then
        self.npcHandler.shopItems[#self.npcHandler.shopItems + 1] = {
            id = itemid,
            buy = cost,
            sell = -1,
            subType = itemSubType,
            name = realName or it:getName()
        }
    else
        shopItem.buy = cost
    end

    if names and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE then
        for _, name in pairs(names) do
            local parameters = {
                itemid = itemid,
                cost = cost,
                module = self,
                realName = realName or it:getName(),
                subType = itemSubType or 1
            }

            local keywords = {name}
            local node = self.npcHandler.keywordHandler:addKeyword(keywords, function(cid, message)
                if string.match(message:lower(), "^sell") then
                    parameters.eventType = SHOPMODULE_SELL_ITEM
                    local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                    if shopItem and shopItem.sell > 0 then
                        parameters.cost = shopItem.sell
                        ShopModule.tradeItem(cid, message, keywords, parameters, node)
                    else
                        --self.npcHandler:say("I cannot buy this item from you.", cid)
                    end
                else
                    parameters.eventType = SHOPMODULE_BUY_ITEM
                    local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                    if shopItem and shopItem.buy > 0 then
                        parameters.cost = shopItem.buy
                        ShopModule.tradeItem(cid, message, keywords, parameters, node)
                    else
                        self.npcHandler:say("I don't sell this item.", cid)
                    end
                end
            end, parameters)

            node:addChildKeywordNode(self.yesNode)
            node:addChildKeywordNode(self.noNode)
        end
    end
end

and tradeItem function:


Code:
function ShopModule.tradeItem(cid, message, keywords, parameters, node)
    local module = parameters.module
    if not module.npcHandler:isFocused(cid) then
        return false
    end

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

    local count = module:getCount(message)
    module.amount = count

    shop_amount[cid] = module.amount
    shop_cost[cid] = parameters.cost
    shop_rlname[cid] = parameters.realName
    shop_itemid[cid] = parameters.itemid
    shop_container[cid] = parameters.container
    shop_npcuid[cid] = getNpcCid()
    shop_eventtype[cid] = parameters.eventType
    shop_subtype[cid] = parameters.subType

    local parseInfo = {
        [TAG_PLAYERNAME] = Player(cid):getName(),
        [TAG_ITEMCOUNT] = shop_amount[cid],
        [TAG_TOTALCOST] = shop_cost[cid] * shop_amount[cid],
        [TAG_ITEMNAME] = shop_rlname[cid]
    }

    if shop_eventtype[cid] == SHOPMODULE_SELL_ITEM then
        local msg = module.npcHandler:getMessage(MESSAGE_SELL)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)

    elseif shop_eventtype[cid] == SHOPMODULE_BUY_ITEM then
        local msg = module.npcHandler:getMessage(MESSAGE_BUY)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)

        -- Dynamically create `yes` and `no` nodes
        local confirmNode = KeywordNode:new(SHOP_YESWORD, ShopModule.onConfirm, {module = module})
        local declineNode = KeywordNode:new(SHOP_NOWORD, ShopModule.onDecline, {module = module})

        if node then
            node:addChildKeywordNode(confirmNode)
            node:addChildKeywordNode(declineNode)
        else
            -- If `node` is nil, create a fallback temporary node
            local tempNode = module.npcHandler.keywordHandler:addKeyword({"yes"}, ShopModule.onConfirm, {module = module})
            tempNode:addChildKeywordNode(declineNode)
        end

    elseif shop_eventtype[cid] == SHOPMODULE_BUY_ITEM_CONTAINER then
        local msg = module.npcHandler:getMessage(MESSAGE_BUY)
        msg = module.npcHandler:parseMessage(msg, parseInfo)
        module.npcHandler:say(msg, cid)
    end
    return true
end

Yes thanks, your code works! I modified addBuyableItem slightly because we are using TFS 1.4:

LUA:
function ShopModule:addBuyableItem(names, itemid, cost, itemSubType, realName)
    if SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK then
        if itemSubType == nil then
            itemSubType = 1
        end

        local shopItem = self:getShopItem(itemid, itemSubType)
        if shopItem == nil then
            self.npcHandler.shopItems[#self.npcHandler.shopItems + 1] = {id = itemid, buy = cost, sell = -1, subType = itemSubType, name = realName or ItemType(itemid):getName()}
        else
            shopItem.buy = cost
        end
    end

    if names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE then
        for i = 1, #names do
            local parameters = {
                    itemid = itemid,
                    cost = cost,
                    --eventType = SHOPMODULE_BUY_ITEM,
                    module = self,
                    realName = realName or ItemType(itemid):getName(),
                    subType = itemSubType or 1
                }

            local keywords = {names[i]}
            local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
            if string.match(names[i]:lower(), "^sell") then
                parameters.eventType = SHOPMODULE_SELL_ITEM
                local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                if shopItem and shopItem.sell > 0 then
                    parameters.cost = shopItem.sell
                    ShopModule.tradeItem(cid, names[i], keywords, parameters, node)
                else
                    --self.npcHandler:say("I cannot buy this item from you.", cid)
                end
            else
                parameters.eventType = SHOPMODULE_BUY_ITEM
                local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                if shopItem and shopItem.buy > 0 then
                    parameters.cost = shopItem.buy
                    ShopModule.tradeItem(cid, message, keywords, parameters, node)
                else
                    self.npcHandler:say("I don't sell this item.", cid)
                end
            end
            
            node:addChildKeywordNode(self.yesNode)
            node:addChildKeywordNode(self.noNode)
        end
    end
end

For addBuyableItemContainer I just commented out the line
LUA:
keywords[#keywords + 1] = "buy"
 
Yes thanks, your code works! I modified addBuyableItem slightly because we are using TFS 1.4:

LUA:
function ShopModule:addBuyableItem(names, itemid, cost, itemSubType, realName)
    if SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK then
        if itemSubType == nil then
            itemSubType = 1
        end

        local shopItem = self:getShopItem(itemid, itemSubType)
        if shopItem == nil then
            self.npcHandler.shopItems[#self.npcHandler.shopItems + 1] = {id = itemid, buy = cost, sell = -1, subType = itemSubType, name = realName or ItemType(itemid):getName()}
        else
            shopItem.buy = cost
        end
    end

    if names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE then
        for i = 1, #names do
            local parameters = {
                    itemid = itemid,
                    cost = cost,
                    --eventType = SHOPMODULE_BUY_ITEM,
                    module = self,
                    realName = realName or ItemType(itemid):getName(),
                    subType = itemSubType or 1
                }

            local keywords = {names[i]}
            local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
            if string.match(names[i]:lower(), "^sell") then
                parameters.eventType = SHOPMODULE_SELL_ITEM
                local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                if shopItem and shopItem.sell > 0 then
                    parameters.cost = shopItem.sell
                    ShopModule.tradeItem(cid, names[i], keywords, parameters, node)
                else
                    --self.npcHandler:say("I cannot buy this item from you.", cid)
                end
            else
                parameters.eventType = SHOPMODULE_BUY_ITEM
                local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
                if shopItem and shopItem.buy > 0 then
                    parameters.cost = shopItem.buy
                    ShopModule.tradeItem(cid, message, keywords, parameters, node)
                else
                    self.npcHandler:say("I don't sell this item.", cid)
                end
            end
           
            node:addChildKeywordNode(self.yesNode)
            node:addChildKeywordNode(self.noNode)
        end
    end
end

For addBuyableItemContainer I just commented out the line
LUA:
keywords[#keywords + 1] = "buy"

terrific! best of luck!
my live ot is zamonia77 should you want to check it out or support. :)

//Zeke
 
Back
Top