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

NPC shows items to sell that the player doesn't have in their backpack

Azerty

Active Member
Joined
Apr 15, 2022
Messages
316
Solutions
4
Reaction score
32
Good morning, NPC Yaman shows items to sell that the player doesn't have. Any solution?

image.JPG

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Yaman" script="Yaman.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="103" />
    <parameters>
        <parameter key="module_shop" value="1" />
        <parameter key="shop_buyable" value="
            dragon necklace, 2201, 1000,200;
            dwarven ring, 2213, 2000;
            energy ring, 2167, 2000;
            life ring, 2168, 900;
            might ring, 2164, 5000,20;
            protection amulet, 2200, 700,250;
            ring of healing, 2216, 2000;
            silver amulet, 2170, 100,200;
            strange talisman, 2161, 100,200;
            time ring, 2169, 2000" />
        <parameter key="shop_sellable" value="
            ankh, 2327, 100;
            dragon necklace, 2201,100;
            dwarven ring, 2213, 100;
            energy ring, 2167, 100;
            glacial rod, 18412, 6500;
            hailstorm rod, 2183, 3000;
            life ring, 2168, 50;
            might ring, 2164, 250;
            moonlight rod, 2186, 200;
            muck rod, 18411, 6000;
            mysterious fetish, 2194, 50;
            necrotic rod, 2185, 1000;
            northwind rod, 8911, 1500;
            protection amulet, 2200, 100;
            ring of healing, 2216, 100;
            silver amulet, 2170, 50;
            snakebite rod, 2182, 100;
            springsprout rod, 8912, 3600;
            strange talisman, 2161, 30;
            terra rod, 2181, 2000;
            time ring, 2169, 100;
            underworld rod, 8910, 4400" />
    </parameters>
</npc>

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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if isInArray({"enchanted chicken wing", "boots of haste", "Enchanted Chicken Wing", "Boots of Haste"}, msg) then
        npcHandler:say('Do you want to trade Boots of haste for Enchanted Chicken Wing?', cid)
        npcHandler.topic[cid] = 1
    elseif isInArray({"warrior sweat", "warrior helmet", "Warrior Sweat", "Warrior Helmet"}, msg) then
        npcHandler:say('Do you want to trade 4 Warrior Helmet for Warrior Sweat?', cid)
        npcHandler.topic[cid] = 2
    elseif isInArray({"fighting spirit", "royal helmet", "Fighting Spirit", "Royal Helmet"}, msg) then
        npcHandler:say('Do you want to trade 2 Royal Helmet for Fighting Spirit', cid)
        npcHandler.topic[cid] = 3
    elseif isInArray({"magic sulphur", "fire sword", "Magic Sulphur", "Fire Sword"}, msg) then
        npcHandler:say('Do you want to trade 3 Fire Sword for Magic Sulphur', cid)
        npcHandler.topic[cid] = 4
    elseif isInArray({"job", "items", "Items", "Job"}, msg) then
        npcHandler:say('I trade Enchanted Chicken Wing for Boots of Haste, Warrior Sweat for 4 Warrior Helmets, Fighting Spirit for 2 Royal Helmet Magic Sulphur for 3 Fire Swords', cid)
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'cookie') then
        if player:getStorageValue(Storage.WhatAFoolishQuest.Questline) == 31
                and player:getStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn) ~= 1 then
            npcHandler:say('You brought cookies! How nice of you! Can I have one?', cid)
            npcHandler.topic[cid] = 5
        end
    elseif msgcontains(msg,'yes') then
        if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
            local trade = {
                    { NeedItem = 2195, Ncount = 1, GiveItem = 5891, Gcount = 1}, -- Enchanted Chicken Wing
                    { NeedItem = 2475, Ncount = 4, GiveItem = 5885, Gcount = 1}, -- Flask of Warrior's Sweat
                    { NeedItem = 2498, Ncount = 2, GiveItem = 5884, Gcount = 1}, -- Spirit Container
                    { NeedItem = 2392, Ncount = 3, GiveItem = 5904, Gcount = 1}  -- Magic Sulphur
            }

            if player:getItemCount(trade[npcHandler.topic[cid]].NeedItem) >= trade[npcHandler.topic[cid]].Ncount then
                player:removeItem(trade[npcHandler.topic[cid]].NeedItem, trade[npcHandler.topic[cid]].Ncount)
                player:addItem(trade[npcHandler.topic[cid]].GiveItem, trade[npcHandler.topic[cid]].Gcount)
                return npcHandler:say('Here you are.', cid)
            else
                npcHandler:say('Sorry but you don\'t have the item.', cid)
            end
        elseif npcHandler.topic[cid] == 5 then
            if not player:removeItem(8111, 1) then
                npcHandler:say('You have no cookie that I\'d like.', cid)
                npcHandler.topic[cid] = 0
                return true
            end

            player:setStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn, 1)
            if player:getCookiesDelivered() == 10 then
                player:addAchievement('Allow Cookies?')
            end

            Npc():getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
            npcHandler:say('You see, good deeds like this will ... YOU ... YOU SPAWN OF EVIL! I WILL MAKE SURE THE MASTER LEARNS ABOUT THIS!', cid)
            npcHandler:releaseFocus(cid)
            npcHandler:resetNpc(cid)
        end
    elseif msgcontains(msg,'no') then
        if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
            npcHandler:say('Ok then.', cid)
            npcHandler.topic[cid] = 0
        elseif npcHandler.topic[cid] == 5 then
            npcHandler:say('I see.', cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

local function onTradeRequest(cid)
    local player = Player(cid)
    
    if player:getStorageValue(Storage.DjinnWar.EfreetFaction.Mission03) ~= 3 then
        npcHandler:say('I\'m sorry, but you don\'t have Malor\'s permission to trade with me.', cid)
        return false
    end

    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Be greeted, human |PLAYERNAME|. How can a humble djinn be of service?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, human.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, human.")
npcHandler:setMessage(MESSAGE_SENDTRADE, 'At your service, just browse through my wares.')

npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

local focusModule = FocusModule:new()
focusModule:addGreetMessage('hi')
focusModule:addGreetMessage('hello')
focusModule:addGreetMessage('djanni\'hah')
npcHandler:addModule(focusModule)
 
You have show all items checked in the picture, it looks like it is functioning correctly from what I can tell.. because the items you DO have aren't greyed out.. or am I missing something?

Edit: I am dumb I see it now, you have nothing equipped and no inventory.. let me review

Try this

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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if isInArray({"enchanted chicken wing", "boots of haste", "Enchanted Chicken Wing", "Boots of Haste"}, msg) then
        npcHandler:say('Do you want to trade Boots of haste for Enchanted Chicken Wing?', cid)
        npcHandler.topic[cid] = 1
    elseif isInArray({"warrior sweat", "warrior helmet", "Warrior Sweat", "Warrior Helmet"}, msg) then
        npcHandler:say('Do you want to trade 4 Warrior Helmet for Warrior Sweat?', cid)
        npcHandler.topic[cid] = 2
    elseif isInArray({"fighting spirit", "royal helmet", "Fighting Spirit", "Royal Helmet"}, msg) then
        npcHandler:say('Do you want to trade 2 Royal Helmet for Fighting Spirit', cid)
        npcHandler.topic[cid] = 3
    elseif isInArray({"magic sulphur", "fire sword", "Magic Sulphur", "Fire Sword"}, msg) then
        npcHandler:say('Do you want to trade 3 Fire Sword for Magic Sulphur', cid)
        npcHandler.topic[cid] = 4
    elseif isInArray({"job", "items", "Items", "Job"}, msg) then
        npcHandler:say('I trade Enchanted Chicken Wing for Boots of Haste, Warrior Sweat for 4 Warrior Helmets, Fighting Spirit for 2 Royal Helmet Magic Sulphur for 3 Fire Swords', cid)
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'cookie') then
        if player:getStorageValue(Storage.WhatAFoolishQuest.Questline) == 31
                and player:getStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn) ~= 1 then
            npcHandler:say('You brought cookies! How nice of you! Can I have one?', cid)
            npcHandler.topic[cid] = 5
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
            local trade = {
                { NeedItem = 2195, Ncount = 1, GiveItem = 5891, Gcount = 1 }, -- Enchanted Chicken Wing
                { NeedItem = 2475, Ncount = 4, GiveItem = 5885, Gcount = 1 }, -- Flask of Warrior's Sweat
                { NeedItem = 2498, Ncount = 2, GiveItem = 5884, Gcount = 1 }, -- Spirit Container
                { NeedItem = 2392, Ncount = 3, GiveItem = 5904, Gcount = 1 } -- Magic Sulphur
            }

            if player:getItemCount(trade[npcHandler.topic[cid]].NeedItem) >= trade[npcHandler.topic[cid]].Ncount then
                player:removeItem(trade[npcHandler.topic[cid]].NeedItem, trade[npcHandler.topic[cid]].Ncount)
                player:addItem(trade[npcHandler.topic[cid]].GiveItem, trade[npcHandler.topic[cid]].Gcount)
                return npcHandler:say('Here you are.', cid)
            else
                npcHandler:say('Sorry, but you don\'t have the required item.', cid)
            end
        elseif npcHandler.topic[cid] == 5 then
            if not player:removeItem(8111, 1) then
                npcHandler:say('You have no cookie that I\'d like.', cid)
                npcHandler.topic[cid] = 0
                return true
            end

            player:setStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn, 1)
            if player:getCookiesDelivered() == 10 then
                player:addAchievement('Allow Cookies?')
            end

            Npc():getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
            npcHandler:say('You see, good deeds like this will ... YOU ... YOU SPAWN OF EVIL! I WILL MAKE SURE THE MASTER LEARNS ABOUT THIS!', cid)
            npcHandler:releaseFocus(cid)
            npcHandler:resetNpc(cid)
        end
    elseif msgcontains(msg, 'no') then
        if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
            npcHandler:say('Ok then.', cid)
            npcHandler.topic[cid] = 0
        elseif npcHandler.topic[cid] == 5 then
            npcHandler:say('I see.', cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

local function onTradeRequest(cid)
    local player = Player(cid)

    if player:getStorageValue(Storage.DjinnWar.EfreetFaction.Mission03) ~= 3 then
        npcHandler:say('I\'m sorry, but you don\'t have Malor\'s permission to trade with me.', cid)
        return false
    end

    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Be greeted, human |PLAYERNAME|. How can a humble djinn be of service?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, human.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, human.")
npcHandler:setMessage(MESSAGE_SENDTRADE, 'At your service, just browse through my wares.')

npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

local focusModule = FocusModule:new()
focusModule:addGreetMessage('hi')
focusModule:addGreetMessage('hello')
focusModule:addGreetMessage('djanni\'hah')
npcHandler:addModule(focusModule)
 
You have show all items checked in the picture, it looks like it is functioning correctly from what I can tell.. because the items you DO have aren't greyed out.. or am I missing something?

Edit: I am dumb I see it now, you have nothing equipped and no inventory.. let me review
I discovered that this is only happening with items that have "charges". But I still haven't found a solution.
I noticed that if I remove the line <attribute key="charges" value="200" /> it apparently works 100%, but when I purchase the amulet, it only comes with 1 charge. So I don't know how to solve this. There may be a problem with the TFS 1.5 source
XML:
    <item id="2201" article="a" name="dragon necklace">
        <attribute key="weight" value="630" />
        <attribute key="slotType" value="necklace" />
        <attribute key="charges" value="200" />
        <attribute key="showcharges" value="1" />
        <attribute key="absorbPercentFire" value="8" />
        <attribute key="showattributes" value="1" />
    </item>
 
I discovered that this is only happening with items that have "charges". But I still haven't found a solution.
I noticed that if I remove the line <attribute key="charges" value="200" /> it apparently works 100%, but when I purchase the amulet, it only comes with 1 charge. So I don't know how to solve this. There may be a problem with the TFS 1.5 source
XML:
    <item id="2201" article="a" name="dragon necklace">
        <attribute key="weight" value="630" />
        <attribute key="slotType" value="necklace" />
        <attribute key="charges" value="200" />
        <attribute key="showcharges" value="1" />
        <attribute key="absorbPercentFire" value="8" />
        <attribute key="showattributes" value="1" />
    </item>
Lua:
<parameter key="shop_buyable" value="
            dragon necklace, 2201,100, 1000,200;

What happens if you do this?
Much as when you create a item on GM with charges, you need to specify item id and how many charges, so in this case 2201,100

*Not tested

I am on TFS1.4 and if I add a dragon necklace into NPC shot it buys it with 200 charges by default.. hmm
 
Last edited:
Lua:
<parameter key="shop_buyable" value="
            dragon necklace, 2201,100, 1000,200;

What happens if you do this?
Much as when you create a item on GM with charges, you need to specify item id and how many charges, so in this case 2201,100

*Not tested
Didnt work
Post automatically merged:

Lua:
<parameter key="shop_buyable" value="
            dragon necklace, 2201,100, 1000,200;

What happens if you do this?
Much as when you create a item on GM with charges, you need to specify item id and how many charges, so in this case 2201,100

*Not tested

I am on TFS1.4 and if I add a dragon necklace into NPC shot it buys it with 200 charges by default.. hmm

I downloaded the TFS 1.5 source again and compiled it. With the new engine and folders the error also appears
Capturar.JPG
 
Last edited:
Didnt work
Post automatically merged:



I downloaded the TFS 1.5 source again and compiled it. With the new engine and folders the error also appears
View attachment 78866
That is really weird to me, I never did anything fancy to make it appear with charges (my server doesn't use charges) but it works just fine I add something in the shop with charges..

What if you take

Lua:
<parameter key="shop_buyable" value="
            dragon necklace, 2201, 1000,200;

And make it this
Code:
<parameter key="shop_buyable" value="
            dragon necklace, 2201, 1000;

That is removing the "charges" to see what happens, I guess.. originally we were just trying to add another line to see if it could add additional charges
 
Last edited:
Good morning, NPC Yaman shows items to sell that the player doesn't have. Any solution?

View attachment 78828

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Yaman" script="Yaman.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="103" />
    <parameters>
        <parameter key="module_shop" value="1" />
        <parameter key="shop_buyable" value="
            dragon necklace, 2201, 1000,200;
            dwarven ring, 2213, 2000;
            energy ring, 2167, 2000;
            life ring, 2168, 900;
            might ring, 2164, 5000,20;
            protection amulet, 2200, 700,250;
            ring of healing, 2216, 2000;
            silver amulet, 2170, 100,200;
            strange talisman, 2161, 100,200;
            time ring, 2169, 2000" />
        <parameter key="shop_sellable" value="
            ankh, 2327, 100;
            dragon necklace, 2201,100;
            dwarven ring, 2213, 100;
            energy ring, 2167, 100;
            glacial rod, 18412, 6500;
            hailstorm rod, 2183, 3000;
            life ring, 2168, 50;
            might ring, 2164, 250;
            moonlight rod, 2186, 200;
            muck rod, 18411, 6000;
            mysterious fetish, 2194, 50;
            necrotic rod, 2185, 1000;
            northwind rod, 8911, 1500;
            protection amulet, 2200, 100;
            ring of healing, 2216, 100;
            silver amulet, 2170, 50;
            snakebite rod, 2182, 100;
            springsprout rod, 8912, 3600;
            strange talisman, 2161, 30;
            terra rod, 2181, 2000;
            time ring, 2169, 100;
            underworld rod, 8910, 4400" />
    </parameters>
</npc>

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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if isInArray({"enchanted chicken wing", "boots of haste", "Enchanted Chicken Wing", "Boots of Haste"}, msg) then
        npcHandler:say('Do you want to trade Boots of haste for Enchanted Chicken Wing?', cid)
        npcHandler.topic[cid] = 1
    elseif isInArray({"warrior sweat", "warrior helmet", "Warrior Sweat", "Warrior Helmet"}, msg) then
        npcHandler:say('Do you want to trade 4 Warrior Helmet for Warrior Sweat?', cid)
        npcHandler.topic[cid] = 2
    elseif isInArray({"fighting spirit", "royal helmet", "Fighting Spirit", "Royal Helmet"}, msg) then
        npcHandler:say('Do you want to trade 2 Royal Helmet for Fighting Spirit', cid)
        npcHandler.topic[cid] = 3
    elseif isInArray({"magic sulphur", "fire sword", "Magic Sulphur", "Fire Sword"}, msg) then
        npcHandler:say('Do you want to trade 3 Fire Sword for Magic Sulphur', cid)
        npcHandler.topic[cid] = 4
    elseif isInArray({"job", "items", "Items", "Job"}, msg) then
        npcHandler:say('I trade Enchanted Chicken Wing for Boots of Haste, Warrior Sweat for 4 Warrior Helmets, Fighting Spirit for 2 Royal Helmet Magic Sulphur for 3 Fire Swords', cid)
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'cookie') then
        if player:getStorageValue(Storage.WhatAFoolishQuest.Questline) == 31
                and player:getStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn) ~= 1 then
            npcHandler:say('You brought cookies! How nice of you! Can I have one?', cid)
            npcHandler.topic[cid] = 5
        end
    elseif msgcontains(msg,'yes') then
        if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
            local trade = {
                    { NeedItem = 2195, Ncount = 1, GiveItem = 5891, Gcount = 1}, -- Enchanted Chicken Wing
                    { NeedItem = 2475, Ncount = 4, GiveItem = 5885, Gcount = 1}, -- Flask of Warrior's Sweat
                    { NeedItem = 2498, Ncount = 2, GiveItem = 5884, Gcount = 1}, -- Spirit Container
                    { NeedItem = 2392, Ncount = 3, GiveItem = 5904, Gcount = 1}  -- Magic Sulphur
            }

            if player:getItemCount(trade[npcHandler.topic[cid]].NeedItem) >= trade[npcHandler.topic[cid]].Ncount then
                player:removeItem(trade[npcHandler.topic[cid]].NeedItem, trade[npcHandler.topic[cid]].Ncount)
                player:addItem(trade[npcHandler.topic[cid]].GiveItem, trade[npcHandler.topic[cid]].Gcount)
                return npcHandler:say('Here you are.', cid)
            else
                npcHandler:say('Sorry but you don\'t have the item.', cid)
            end
        elseif npcHandler.topic[cid] == 5 then
            if not player:removeItem(8111, 1) then
                npcHandler:say('You have no cookie that I\'d like.', cid)
                npcHandler.topic[cid] = 0
                return true
            end

            player:setStorageValue(Storage.WhatAFoolishQuest.CookieDelivery.Djinn, 1)
            if player:getCookiesDelivered() == 10 then
                player:addAchievement('Allow Cookies?')
            end

            Npc():getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
            npcHandler:say('You see, good deeds like this will ... YOU ... YOU SPAWN OF EVIL! I WILL MAKE SURE THE MASTER LEARNS ABOUT THIS!', cid)
            npcHandler:releaseFocus(cid)
            npcHandler:resetNpc(cid)
        end
    elseif msgcontains(msg,'no') then
        if npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 4 then
            npcHandler:say('Ok then.', cid)
            npcHandler.topic[cid] = 0
        elseif npcHandler.topic[cid] == 5 then
            npcHandler:say('I see.', cid)
            npcHandler.topic[cid] = 0
        end
    end
    return true
end

local function onTradeRequest(cid)
    local player = Player(cid)
   
    if player:getStorageValue(Storage.DjinnWar.EfreetFaction.Mission03) ~= 3 then
        npcHandler:say('I\'m sorry, but you don\'t have Malor\'s permission to trade with me.', cid)
        return false
    end

    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Be greeted, human |PLAYERNAME|. How can a humble djinn be of service?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, human.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, human.")
npcHandler:setMessage(MESSAGE_SENDTRADE, 'At your service, just browse through my wares.')

npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

local focusModule = FocusModule:new()
focusModule:addGreetMessage('hi')
focusModule:addGreetMessage('hello')
focusModule:addGreetMessage('djanni\'hah')
npcHandler:addModule(focusModule)
Any solution to this? From my observation it looks like when you add the same amulet to the shop_buyable and shop_sellable it will lead to such problems. In the 'sell' window section I see charges set as an amount. When I delete item from the shop_sellable list it will work fine in sell section. Looks like they can't be in both sections at the same time.
 
Any solution to this? From my observation it looks like when you add the same amulet to the shop_buyable and shop_sellable it will lead to such problems. In the 'sell' window section I see charges set as an amount. When I delete item from the shop_sellable list it will work fine in sell section. Looks like they can't be in both sections at the same time.
I recommend LUA over XML; it performed well when tested in parallel on two sections simultaneously. Hence, it's preferable to solely utilize LUA.

npc.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="XXX" script="XXXX.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="132" head="20" body="39" legs="45" feet="7" addons="0"/>
    <parameters>
        
        
    </parameters>
</npc>


npc.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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)

---------------------------------------- SELL ----------------------------------------
shopModule:addSellableItem({'heart backpack'}, 11115, 10000, 1, 'heart backpack')
shopModule:addSellableItem({'dark purple backpack'}, 12652, 10000, 1, 'dark purple backpack')
shopModule:addSellableItem({'green camouflage backpack'}, 11397, 10000, 1, 'green camouflage backpack')
shopModule:addSellableItem({'expedition backpack'}, 11235, 10000, 1, 'expedition backpack')
shopModule:addSellableItem({'lizard backpack'}, 11237, 10000, 1, 'lizard backpack')



shopModule:addSellableItem({'wand of vortex', 'vortex'}, 2190, 100, 'wand of vortex')
shopModule:addSellableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 200, 'wand of dragonbreath')
shopModule:addSellableItem({'wand of plague', 'plague'}, 2188, 1000, 'wand of plague')
shopModule:addSellableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 2000, 'wand of cosmic energy')
shopModule:addSellableItem({'wand of inferno', 'inferno'}, 2187, 3000, 'wand of inferno')

shopModule:addSellableItem({'snakebite rod', 'snakebite'}, 2182, 100, 'snakebite rod')
shopModule:addSellableItem({'moonlight rod', 'moonlight'}, 2186, 200, 'moonlight rod')
shopModule:addSellableItem({'volcanic rod', 'volcanic'}, 2185, 1000, 'volcanic rod')
shopModule:addSellableItem({'quagmire rod', 'quagmire'}, 2181, 2000, 'quagmire rod')
shopModule:addSellableItem({'tempest rod', 'tempest'}, 2183, 3000, 'tempest rod')


---------------------------------------- BUY ----------------------------------------
shopModule:addBuyableItem({'heart backpack'}, 11115, 10000, 1, 'heart backpack')
shopModule:addBuyableItem({'dark purple backpack'}, 12652, 10000, 1, 'dark purple backpack')
shopModule:addBuyableItem({'green camouflage backpack'}, 11397, 10000, 1, 'green camouflage backpack')
shopModule:addBuyableItem({'expedition backpack'}, 11235, 10000, 1, 'expedition backpack')
shopModule:addBuyableItem({'lizard backpack'}, 11237, 10000, 1, 'lizard backpack')
shopModule:addBuyableItem({'minotaur backpack'}, 11238, 10000, 1, 'minotaur backpack')
shopModule:addBuyableItem({'nike backpack'}, 11394, 10000, 1, 'nike backpack')
shopModule:addBuyableItem({'red camouflage backpack'}, 11396, 10000, 1, 'red camouflage backpack')


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I recommend LUA over XML; it performed well when tested in parallel on two sections simultaneously. Hence, it's preferable to solely utilize LUA.

npc.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="XXX" script="XXXX.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="132" head="20" body="39" legs="45" feet="7" addons="0"/>
    <parameters>
       
       
    </parameters>
</npc>


npc.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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)

---------------------------------------- SELL ----------------------------------------
shopModule:addSellableItem({'heart backpack'}, 11115, 10000, 1, 'heart backpack')
shopModule:addSellableItem({'dark purple backpack'}, 12652, 10000, 1, 'dark purple backpack')
shopModule:addSellableItem({'green camouflage backpack'}, 11397, 10000, 1, 'green camouflage backpack')
shopModule:addSellableItem({'expedition backpack'}, 11235, 10000, 1, 'expedition backpack')
shopModule:addSellableItem({'lizard backpack'}, 11237, 10000, 1, 'lizard backpack')



shopModule:addSellableItem({'wand of vortex', 'vortex'}, 2190, 100, 'wand of vortex')
shopModule:addSellableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 200, 'wand of dragonbreath')
shopModule:addSellableItem({'wand of plague', 'plague'}, 2188, 1000, 'wand of plague')
shopModule:addSellableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 2000, 'wand of cosmic energy')
shopModule:addSellableItem({'wand of inferno', 'inferno'}, 2187, 3000, 'wand of inferno')

shopModule:addSellableItem({'snakebite rod', 'snakebite'}, 2182, 100, 'snakebite rod')
shopModule:addSellableItem({'moonlight rod', 'moonlight'}, 2186, 200, 'moonlight rod')
shopModule:addSellableItem({'volcanic rod', 'volcanic'}, 2185, 1000, 'volcanic rod')
shopModule:addSellableItem({'quagmire rod', 'quagmire'}, 2181, 2000, 'quagmire rod')
shopModule:addSellableItem({'tempest rod', 'tempest'}, 2183, 3000, 'tempest rod')


---------------------------------------- BUY ----------------------------------------
shopModule:addBuyableItem({'heart backpack'}, 11115, 10000, 1, 'heart backpack')
shopModule:addBuyableItem({'dark purple backpack'}, 12652, 10000, 1, 'dark purple backpack')
shopModule:addBuyableItem({'green camouflage backpack'}, 11397, 10000, 1, 'green camouflage backpack')
shopModule:addBuyableItem({'expedition backpack'}, 11235, 10000, 1, 'expedition backpack')
shopModule:addBuyableItem({'lizard backpack'}, 11237, 10000, 1, 'lizard backpack')
shopModule:addBuyableItem({'minotaur backpack'}, 11238, 10000, 1, 'minotaur backpack')
shopModule:addBuyableItem({'nike backpack'}, 11394, 10000, 1, 'nike backpack')
shopModule:addBuyableItem({'red camouflage backpack'}, 11396, 10000, 1, 'red camouflage backpack')


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks for the response. I tried to adapt to your suggestion.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions
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)

shopModule:addBuyableItem({'dwarven ring'},2213,1500)
shopModule:addBuyableItem({'axe ring'},2208,500)
shopModule:addBuyableItem({'club ring'},2209,500)
shopModule:addBuyableItem({'sword ring'},2207,500)
shopModule:addBuyableItem({'power ring'},2166,500)
shopModule:addBuyableItem({'energy ring'},2167,600)
shopModule:addBuyableItem({'might ring'},2164,3000, 20)
shopModule:addBuyableItem({'life ring'},2168,800)
shopModule:addBuyableItem({'time ring'},2169,1500)
shopModule:addBuyableItem({'stealth ring'},2165,1500)
shopModule:addBuyableItem({'silver amulet'},2170,200, 100)
shopModule:addBuyableItem({'ring of healing'},2214,2000)
shopModule:addBuyableItem({'stone skin amulet'},2197,3500, 5)
shopModule:addBuyableItem({'bonfire amulet'},10218,5000, 5)
shopModule:addBuyableItem({'sacred tree amulet'},10219,5000, 5)
shopModule:addBuyableItem({'shockwave amulet'},10221,5000, 5)
shopModule:addBuyableItem({'leviathans amulet'},10220,5000, 5)
shopModule:addBuyableItem({'terra amulet'},7887,3000, 200)
shopModule:addBuyableItem({'magma amulet'},7890,3000, 200)
shopModule:addBuyableItem({'lightning pendant'},7889,3000, 200)
shopModule:addBuyableItem({'glacier amulet'},7888,3000, 200)
shopModule:addBuyableItem({'protection amulet'},2200,400, 200)
shopModule:addBuyableItem({'garlic necklace'},2199,500, 200)

shopModule:addSellableItem({'axe ring'},2208,100)
shopModule:addSellableItem({'bronze amulet'},2172,50)
shopModule:addSellableItem({'bonfire amulet'},10218,3000)
shopModule:addSellableItem({'club ring'},2209,100)
shopModule:addSellableItem({'stealth ring'},2165,200)
shopModule:addSellableItem({'stone skin amulet'},2197,500)
shopModule:addSellableItem({'sword ring'},2207,100)
shopModule:addSellableItem({'elven amulet'},2198,100)
shopModule:addSellableItem({'garlic necklace'},2199,50)
shopModule:addSellableItem({'dragon necklace'},2201,100)
shopModule:addSellableItem({'dwarven ring'},2213,100)
shopModule:addSellableItem({'energy ring'},2167,100)
shopModule:addSellableItem({'life ring'},2168,50)
shopModule:addSellableItem({'mighty ring'},2164,250)
shopModule:addSellableItem({'ring of healing'},2214,100)
shopModule:addSellableItem({'silver amulet'},2170,50)
shopModule:addSellableItem({'strange talisman'},2161,30)
shopModule:addSellableItem({'time ring'},2169,100)
shopModule:addSellableItem({'protection amulet'},2200,100)
shopModule:addSellableItem({'ring of blue plasma'},26185,8000)
shopModule:addSellableItem({'ring of green plasma'},26187,8000)
shopModule:addSellableItem({'ring of red plasma'},26189,8000)
shopModule:addSellableItem({'collar of blue plasma'},26198,6000)
shopModule:addSellableItem({'collar of green plasma'},26199,6000)
shopModule:addSellableItem({'collar of red plasma'},26200,6000)
shopModule:addSellableItem({'glacier amulet'},7888,1500)
shopModule:addSellableItem({'lightning pendant'},7889,1500)
shopModule:addSellableItem({"leviathan's amulet"},10220,3000)
shopModule:addSellableItem({'magma amulet'},7890,1500)
shopModule:addSellableItem({'sacred tree amulet'},10219,3000)
shopModule:addSellableItem({'terra amulet'},7887,1500)
shopModule:addSellableItem({'shockwave amulet'},10221,3000)
shopModule:addSellableItem({'necklace of the deep'},15403,3000)

keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Now it is |TIME|."})

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


function creatureSayCallback(cid, type, msg)
    if (not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if msgcontains(msg, 'help') then
        selfSay('You can here change 2 life crystal for {life ring}, or buy some other rings.?', cid)
    elseif msgcontains(msg, 'life ring') then
        if getPlayerItemCount(cid, 2177) >= 2 then
            selfSay('Did you bring me 2 life crystals?', cid)
            talk_state = 1
        else
            selfSay('I need a 2 life crystal, to give you life ring. Come back when you have them.', cid)
            talk_state = 0
        end
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
        talk_state = 0
        if getPlayerItemCount(cid, 2177) >= 2 then
            if doPlayerRemoveItem(cid, 2177, 2) == TRUE then
                doPlayerAddItem(cid, 2205, 1)
                selfSay('Here u are.', cid)
            end
        else
            selfSay(havent_item)
        end
    elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 6) then
        selfSay('Ok than.')
        talk_state = 0
    end
    return true
end

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

With given code problem didn't disappear. As you can see my character is pretty empty:
1706268331006.png
Looks like my 'invisible' items amount is the same as charges (max 100).
1706268513527.png
I will post my npc modules as an attachment.

Thanks in advance for help!
 

Attachments

Thanks in advance for help!
I have observed that your modules are designed for TFS 1.x, whereas the script you have shared pertains to TFS 0.4, an older version. Consequently, I took the initiative to convert all elements to TFS 1.x in a meticulous manner. Subsequently, rigorous testing has been conducted, ensuring the absence of any bugs. Notably, for users without items, their presence in the trade window remains discreet. Conversely, should items be present in the inventory and subsequently appear for sale, this functionality is deemed operational. I encourage you to assess the updated version and provide feedback accordingly.

Did I change anything? See here if it is correct: shopModule:addBuyableItem({'dwarven ring'}, 2213, 1500, 'dwarven ring') instead of shopModule:addBuyableItem({'dwarven ring'}, 2213, 1500).


see the GIF, how it works.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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)

---------------------------------------- Buy ----------------------------------------
shopModule:addBuyableItem({'dwarven ring'}, 2213, 1500, "dwarven ring")
shopModule:addBuyableItem({'axe ring'}, 2208, 500, 'axe ring')
shopModule:addBuyableItem({'club ring'}, 2209, 1500, 'club ring')
shopModule:addBuyableItem({'sword ring'}, 2207, 500, 'sword ring')
shopModule:addBuyableItem({'power ringk'}, 2166, 500, 'power ringk')
shopModule:addBuyableItem({'energy ring'}, 2167, 600, 'energy ring')
shopModule:addBuyableItem({'might ring'}, 2164, 3000, 'might ring')
shopModule:addBuyableItem({'life ring'}, 2168, 800, 'life ring')
shopModule:addBuyableItem({'time ring'}, 2169, 1500, 'time ring')
shopModule:addBuyableItem({'stealth ring'}, 2165, 1500, 'stealth ring')
shopModule:addBuyableItem({'ring of healing'}, 2214, 2000, 'ring of healing')
shopModule:addBuyableItem({'stone skin amulet'}, 2197, 3500, 'stone skin amulet')
shopModule:addBuyableItem({'bonfire amulet'}, 10218, 5000, 'time ring')
shopModule:addBuyableItem({'sacred tree amulet'}, 10219, 5000, 'sacred tree amulet')
shopModule:addBuyableItem({'shockwave amulet'}, 10221, 5000, 'shockwave amulet')
shopModule:addBuyableItem({'leviathans amulet'}, 10220, 5000, 'leviathans amulet')
shopModule:addBuyableItem({'terra amulet'}, 7887, 3000, 'terra amulet')
shopModule:addBuyableItem({'magma amulet'}, 7890, 3000, 'magma amulet')
shopModule:addBuyableItem({'lightning pendant'}, 7889, 3000, 'lightning pendant')
shopModule:addBuyableItem({'glacier amulet'}, 7888, 3000, 'glacier amulet')
shopModule:addBuyableItem({'protection amulet'} ,2200, 400, 'protection amulet')
shopModule:addBuyableItem({'garlic necklace'}, 2199, 500, 'garlic necklace')


---------------------------------------- SELL ----------------------------------------
shopModule:addSellableItem({'bronze amulet'}, 2172, 50, "bronze amulet")
shopModule:addSellableItem({'axe ring'}, 2208, 500, 'axe ring')
shopModule:addSellableItem({'bonfire amulet'}, 10218, 3000, 'bonfire amulet')
shopModule:addSellableItem({'club ring'}, 2209, 1500, 'club ring')
shopModule:addSellableItem({'stealth ring'}, 2165, 200, 'stealth ring')
shopModule:addSellableItem({'stone skin amulet'}, 2197, 500, 'stone skin amulet')
shopModule:addSellableItem({'sword ring'}, 2207, 100, 'sword ring')
shopModule:addSellableItem({'elven amulet'}, 2198, 100, 'elven amulet')
shopModule:addSellableItem({'garlic necklace'}, 2199, 50, 'garlic necklace')
shopModule:addSellableItem({'dragon necklace'}, 2201, 200, 'dragon necklace')
shopModule:addSellableItem({'dwarven ring'}, 2213, 100, "dwarven ring")
shopModule:addSellableItem({'energy ring'}, 2167, 100, 'energy ring')
shopModule:addSellableItem({'life ring'}, 2168, 50, 'life ring')
shopModule:addSellableItem({'might ring'}, 2164, 250, 'might ring')
shopModule:addSellableItem({'ring of healing'}, 2214, 100, 'ring of healing')
shopModule:addSellableItem({'silver amulet'}, 2170, 50, 'silver amulet')
shopModule:addSellableItem({'strange talisman'}, 2161, 30, 'strange talisman')
shopModule:addSellableItem({'time ring'}, 2169, 100, 'time ring')
shopModule:addSellableItem({'protection amulet'}, 2200, 100, 'protection amulet')
shopModule:addSellableItem({'ring of blue plasma'}, 26185, 8000, 'ring of blue plasma')
shopModule:addSellableItem({'ring of green plasma'}, 26187, 8000, 'ring of green plasma')
shopModule:addSellableItem({'ring of red plasma'}, 26189, 8000, 'ring of red plasma')
shopModule:addSellableItem({'collar of blue plasma'}, 26198, 8000, 'collar of blue plasma')
shopModule:addSellableItem({'collar of green plasma'}, 26199, 8000, 'collar of green plasma')
shopModule:addSellableItem({'collar of red plasma'}, 26200, 6000, 'collar of red plasma')
shopModule:addSellableItem({'glacier amulet'}, 7888, 1500, 'glacier amulet')
shopModule:addSellableItem({'lightning pendant'}, 7889, 3000, 'lightning pendant')
shopModule:addSellableItem({'leviathan\'s amulet'}, 10220, 3000, 'leviathan\'s amulet')
shopModule:addSellableItem({'magma amulet'}, 7890, 1500, 'magma amulet')
shopModule:addSellableItem({'sacred tree amulet'}, 10219, 3000, 'sacred tree amulet')
shopModule:addSellableItem({'terra amulet'}, 7887, 1500, 'terra amulet')
shopModule:addSellableItem({'shockwave amulet'}, 10221, 3000, 'shockwave amulet')
shopModule:addSellableItem({'necklace of the deep'}, 15403, 3000, 'necklace of the deep')
--------------------------------THE END----------------------------------------------------


keywordHandler:addKeyword({'time'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Now it is |TIME|."})

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


function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
  
    if not npcHandler:isFocused(cid) then
        return false
    end
  
    if msgcontains(msg, 'help') then
        selfSay('You can change 2 life crystals for a {life ring}, or buy some other rings.?', cid)
  
    elseif msgcontains(msg, 'life ring') then
        if player:getItemCount(2177) >= 2 then
            selfSay('Did you bring me 2 life crystals?', cid)
            talk_state = 1
        else
            selfSay('I need 2 life crystals to give you a life ring. Come back when you have them.', cid)
            talk_state = 0
        end
  
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
        talk_state = 0
        if player:getItemCount(2177) >= 2 then
            if player:removeItem(2177, 2) == true then
                player:addItem(2205, 1)
                selfSay('Here you are.', cid)
            end
        else
            selfSay('You do not have the required items.', cid)
        end
  
    elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 6) then
        selfSay('Ok then.')
        talk_state = 0
    end
  
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
@Mateus Robeerto Thank you very much, as you said it works now. My problem was migrating from 0.3.4 to Nekiro Downagrade 1.5. When I found this thread I kinda lost that direction in a bug research. I think that your response should be marked as a solution.
Thanks once again for fast help :D 👍
 
Back
Top