• 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+ Realera 8.0 npcs libraries Help

johnsamir

Advanced OT User
Joined
Oct 13, 2009
Messages
923
Solutions
6
Reaction score
155
Location
Nowhere
Hello

I'm trying to disable the necessity to say of the word buy to get an X item from Npcs.
as you can see i removed the word "BUY" and it worked. But if i say for example sell manafluid the npc will understand it as im buying , because is not taking any prevous word, so my question is : how should i do to disable the requeriment of the word buy to get an item, but working correctly?

so i found at modules.lua this
Lua:
        keywords = {}
                keywords[#keywords + 1] = ""
                --keywords[#keywords + 1] = "buy" 
                keywords[#keywords + 1] = names[i]
                local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
                node:addChildKeywordNode(self.yesNode)
                node:addChildKeywordNode(self.noNode)
            end
        end
 
Solution
Open your modules.lua
Use Ctrl+F to find this line:
Lua:
function ShopModule.tradeItem(cid, message, keywords, parameters, node)

if you find this line, at the beginning of this function write:
Lua:
if msgcontains(message, 'sell') and parameters.eventType==SHOPMODULE_BUY_ITEM then
    return false
end

Restart your ots and repeat dagger test.
1. Comment out following line, as you did with your example.
Lua:
 keywords[#keywords + 1] = ""

2. Do not uncomment following line. You did the right thing removing it.
Lua:
--keywords[#keywords + 1] = "buy"

3. Create an example npc with this code for tests:
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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
--------------------------------------------------------------------------------------
-- NPC BUYS FOLLOWING ITEMS:
shopModule:addSellableItem({'sabre'},2385,12,'sabre')
--------------------------------------------------------------------------------------
-- NPC SELLS FOLLOWING ITEMS:
shopModule:addBuyableItem({'dagger'},2379,5,'dagger')
shopModule:addBuyableItem({'sabre'},2385,25,'sabre')
--------------------------------------------------------------------------------------
function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end
--------------------------------------------------------------------------------------
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

4. Check if Id=2385 is sabre and 2379 is a dagger on your server. If not correct the code above.

5. Perform tests:

hi, buy sabre, yes
hi, sell sabre, yes
hi, buy dagger, yes
hi, sell dagger, yes

Note what npc answers in each case. Print here.
 
Last edited:
Hello

thanks for your reply mate, so i did what you told me

11:29 ADM [27]: hi
11:29 Sam: Hi ADM Pxsturry. Can I do something for you?
11:29 ADM [27]: sabre
11:29 Sam: Do you want to buy 1 sabre for 35 gold coins?
11:29 ADM [27]: sell sabre
11:29 Sam: Do you want to sell 1 sabre for 12 gold coins?
11:29 ADM [27]: yes
11:29 Sam: You don't have so many.
11:29 Sam: Good bye.

but with others like with xodet it doesn't
11:32 Xodet: Oh, please come in, ADM Pxsturry. What do you need?
11:32 ADM Pxsturry [27]: sell manafluid
11:32 Xodet: Do you want to buy 1 manafluid for 100 gold coins?
11:32 ADM Pxsturry [27]: manafluid
11:32 Xodet: Do you want to buy 1 manafluid for 100 gold coins?
what should i change?
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

keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm Xodet, the owner of this shop."})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm sorcerer and trade with all kinds of magic items."})
keywordHandler:addKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "There is a sorcerer guild in Thais. Just go in the east of the town, it is easly to find."})
keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm selling life and mana fluids, runes and spellbooks."})
keywordHandler:addKeyword({'good'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm selling life and mana fluids, runes and spellbooks."})
keywordHandler:addKeyword({'items'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm selling life and mana fluids, runes and spellbooks."})
keywordHandler:addKeyword({'have'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I'm selling life and mana fluids, runes and spellbooks."})

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    local items = {[1] = 2190, [2] = 2182}
    local itemId = items[player:getVocation():getBase():getId()]
    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if player:isMage() then
            if player:getStorageValue(2004) ~= 1 then
                npcHandler:say('So you ask me for a ' .. ItemType(itemId):getName() .. ' to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                npcHandler:say('What? I have already gave you one ' .. ItemType(itemId):getName() .. '!', cid)
            end
        else
            npcHandler:say('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(itemId, 1)
            npcHandler:say('Here you are young adept, take care yourself.', cid)
            player:setStorageValue(2004, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I asked for testing sabre and dagger because as you can see in my testfile an npc sells and buys sabre, but doesn't buy dagger. Please test his response with dagger and post here.
 
I asked for testing sabre and dagger because as you can see in my testfile an npc sells and buys sabre, but doesn't buy dagger. Please test his response with dagger and post here.
Lua:
12:00 ADM [27]: dagger
12:00 Test: Do you want to buy 1 dagger for 5 gold coins?
12:00 ADM [27]: sell dagger
12:00 Test: Do you want to buy 1 dagger for 5 gold coins?
:(
 
Last edited:
Open your modules.lua
Use Ctrl+F to find this line:
Lua:
function ShopModule.tradeItem(cid, message, keywords, parameters, node)

if you find this line, at the beginning of this function write:
Lua:
if msgcontains(message, 'sell') and parameters.eventType==SHOPMODULE_BUY_ITEM then
    return false
end

Restart your ots and repeat dagger test.
 
Solution
now if i say sell the npc just simply does not talk WORKS!!!
Lua:
12:18 Test: Greetings, ADM.
12:18 ADM [27]: sell dagger
12:18 ADM [27]: sell dagger
Lua:
    -- tradeItem callback function. Makes the npc say the message defined by MESSAGE_BUY or MESSAGE_SELL
    function ShopModule.tradeItem(cid, message, keywords, parameters, node)

        if msgcontains(message, 'sell') and parameters.eventType==SHOPMODULE_BUY_ITEM then
    return false
end
        local module = parameters.module
        if(not module.npcHandler:isFocused(cid)) then
            return false
        end

EDIT: that is what was i looking for man ! thanks. Where did you get that piece of code? you are the best<3
 
Last edited:
I undestand it helped.
Did you try with manafluids with your npc?
Yeah, it worked with the whole npc folder i think
Lua:
12:24 Xodet: Oh, please come in, ADM. What do you need?
12:24 ADM [27]: sell manafluid
12:24 ADM [27]: manafluid
12:24 Xodet: Do you want to buy 1 manafluid for 100 gold coins?
 
I'm glad to hear that.
I also want to point out that this solution is not that elegant, but it was best thing I was able to figure out in 10 minutes.
Ok You owe me a beer haha. Take care.

EDIT: that is what was i looking for man ! thanks. Where did you get that piece of code? you are the best<3
I made it.
 
Back
Top