• 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 [Solved] Unable to sell items when trading with NPCs

AdiMit

c(;
Joined
May 2, 2016
Messages
70
Solutions
2
Reaction score
3
Hello,

I'm currently using the
[8.60] The Forgotten Server 0.3.6 (Crying Damson) V8 by Printer, from the thread: [8.60] The Forgotten Server 0.3.6 (Crying Damson) V8;
and I've encountered a problem when interacting(trading) with NPCs, the errorlog is as follows(screenshots):

gui:
ERROR_sell.png
npchandler.lua:265+450:

265.png
450.png

modules.lua:1229+1234+1296:

1234_1229.png
1296.png

I would be ever so grateful if you could provide me with some support on how to fix that issue,
Best regards! :)
 
does this happen with every npc? or just a single one? can you give the .xml/.lua whichever holds the selling list of the causing npc?

It happens with every NPC that can buy items from players. Sure, I'll post two examples below, but first, I have to point out that the option to buy items from NPCs that had the shop module in the .lua file instead of .xml was giving the same error until I moved it to the .xml and now only "selling your items to NPCs" does not work...

.xml_1
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Eryn" nameDescription="Eryn, the rune vendor" script="runes.lua" walkinterval="2000" floorchange="0" skull="white">
    <health now="100" max="100"/>
    <look type="130" head="96" body="86" legs="0" feet="0" addons="1"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I sell runes, potions, wands and rods... {trade} with me if you want. You can also receive your {first rod} or {first wand} from me."/>
        <parameter key="message_decline" value="Is |TOTALCOST| gold coins too much for you? Get out of here!"/>
        <parameter key="module_shop" value="1"/>
        <parameter key="message_farewall" value="Farewell, |PLAYERNAME|!"/>
        <parameter key="message_walkaway" value="You shall not walk away on me!"/>
        <parameter key="shop_sellable" value="empty small potion flask,7636,5;empty strong potion flask,7634,10;empty great potion flask,7635,15;wand of vortex,2190,250;wand of dragonbreath,2191,500;wand of decay,2188,2500;wand of draconia,8921,3750;wand of cosmic energy,2189,5000;wand of inferno,2187,7500;wand of starstorm,8920,9000;wand of voodoo,8922,11000;snakebite rod,2182,250;moonlight rod,2186,500;necrotic rod',2185,2500;northwind rod,8911,3750;terra rod,2181,5000;hailstorm rod,2183,7500;springsprout rod,8912,9000;underworld rod,8910,11000;"/>
        <parameter key="shop_buyable" value="spellbook,2175,150;magic lightwand,2163,400;small health potion,8704,20;health potion,7618,45;mana potion,7620,50;strong health potion,7588,100;strong mana potion,7589,80;great health potion,7591,190;great mana potion,7590,120;great spirit potion,8472,190;ultimate health potion,8473,310;antidote potion,8474,50;intense healing rune,2265,95;ultimate healing rune,2273,175;magic wall rune,2293,350;destroy field rune,2261,45;light magic missile rune,2287,40;heavy magic missile rune,2311,120;great fireball rune,2304,180;explosion rune,2313,250;sudden death rune,2268,350;death arrow rune,2263,300;paralyze rune,2278,700;animate dead rune,2316,375;convince creature rune,2290,80;chameleon rune,2291,210;desintegreate rune,2310,80;blank rune,2260,10;wand of vortex,2190,500;wand of dragonbreath,2191,1000;wand of decay,2188,5000;wand of draconia,8921,7500;wand of cosmic energy,2189,10000;wand of inferno,2187,15000;wand of starstorm,8920,18000;wand of voodoo,8922,22000;snakebite rod,2182,500;moonlight rod,2186,1000;necrotic rod',2185,5000;northwind rod,8911,7500;terra rod,2181,10000;hailstorm rod,2183,15000;springsprout rod,8912,18000;underworld rod,8910,22000;"/>
    </parameters>
</npc>
.lua_1
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 items = {[1] = 2190, [2] = 2182, [5] = 2190, [6] = 2182}
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, 'first rod') or msgcontains(msg, 'first wand')) then
        if(isSorcerer(cid) or isDruid(cid)) then
            if(getPlayerStorageValue(cid, 30002) <= 0) then
                selfSay('So you ask me for a {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '} to begin your advanture?', cid)
                talkState[talkUser] = 1
            else
                selfSay('What? I have already gave you one {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '}!', cid)
            end
        else
            selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif(msgcontains(msg, 'yes')) then
        if(talkState[talkUser] == 1) then
            doPlayerAddItem(cid, items[getPlayerVocation(cid)], 1)
            selfSay('Here you are young adept, take care yourself.', cid)
            setPlayerStorageValue(cid, 30002, 1)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
.xml_2
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Marco" script="default.lua" walkinterval="4000" floorchange="0">
    <health now="150" max="150"/>
    <look type="143" head="97" body="77" legs="96" feet="97" addons="3"/>
    <parameters>
        <parameter key="message_greet" value="Hey |PLAYERNAME|... If you seek a sharp weapon, {trade} with me!"/>
        <parameter key="module_shop" value="1"/>
        <parameter key="message_farewall" value="Bye..."/>
        <parameter key="message_walkaway" value="Pfff!"/>
        <parameter key="shop_sellable" value="two handed sword,2377,335;dagger,2379,3;spike sword,2383,750;rapier,2384,30;sabre,2385,112;magic longsword,2390,300000;fire sword,2392,3000;giant sword,2393,12750;carlin sword,2395,750;ice rapier,2396,750;longsword,2397,37;silver dagger,2402,375;knife,2403,1;combat knife,2404,4;sickle,2405,7;short sword,2406,60;bright sword,2407,2250;warlord sword,2408,75000;serpent sword,2409,675;poison dagger,2411,37;katana,2412,30;broadsword,2413,262;golden sickle,2418,75;scimitar,2419,112;heavy machete,2442,67;epee,2438,75000;bone sword,2450,75;djinn blade,2451,450000;avenger,6528,150000;demonrage sword,7382,7500;relic sword,7383,18750;mystic blade,7384,7500;crimson sword,7385,375;mercenary sword,7386,15000;justice seeker,7390,52500;thaian sword,7391,11250;dragon slayer,7402,11250;assassin dagger,7404,11250;havoc blade,7405,5250;blacksteel sword,7406,1500;haunted blade,7407,7500;wyvern fang,7408,1500;bloody edge,7416,7500;runed sword,7417,7500;nightmare blade,7418,22500;crystal sword,7449,450;emerald sword,8930,225000;jagged sword,8602,60000;golden sword,8931,750000;calamity,8932,52500;war hammer,2391,675;morning star,2394,75;mace,2398,22;staff,2401,18;crowbar,2416,37;battle hammer,2417,112;thunder hammer,2421,225000;iron hammer,2422,37;clerical mace,2423,150;silver mace,2424,75000;dragon hammer,2434,1500;skull staff,2436,4500;daramanian mace,2439,150;hammer of wrath,2444,56000;crystal mace,2445,22500;studded club,2448,26;bone club,2449,37;arcane staff,2453,22500;lich staff,3961,11250;banana staff,3966,750;brutetamers staff,7379,1500;mammoth whopper,7381,300;diamond sceptre,7387,3000;orcish maul,7392,750;sapphire hammer,7437,5250;shadow sceptre,7451,75000;spiked squelcher,7452,375;queens sceptre,7410,1500000;abyss hammer,7414,375000;cranial basher,7415,7500;jade hammer,7422,52500;lunar staff,7424,5250;taurus mace,7425,450;amber staff,7426,6000;chaos mace,7427,7500;dragonbone staff,7430,2250;furry club,7432,375;dark trinity mace,8927,525000;obsidian truncheon,8928,300000;stomper,8929,187500;battle axe,2378,75;hand axe,2380,15;halberd,2381,300;double axe,2387,225;hatchet,2388,18;great axe,2415,15000;obsidian lance,2425,375;naginata,2426,750;guardian halberd,2427,2250;orcish axe,2428,150;barbarian axe,2429,225;knight axe,2430,750;stonecutter axe,2431,400000;fire axe,2432,5250;dwarven axe,2435,750;daramanian waraxe,2440,675;daramanian axe,2441,300;ravagers axe,2443,37500;twin axe,2447,40000;war axe,2454,7500;beastslayer axe,3962,1500;ruthless axe,6553,52500;headchopper,7380,3000;vile axe,7388,40000;heroic axe,7389,11250;relic axe,7411,30000;butchers axe,7412,52500;titan axe,7413,30000;bloodslayer axe,7453,30000;destroyers axe,7454,40000;ice double axe,7455,67500;cursed axe,7433,22500;royal axe,7434,112500;black axe,7435,225000;angelwing axe,7436,150000;"/>
        <parameter key="shop_buyable" value="two handed sword,2377,450;dagger,2379,5;spike sword,2383,1000;rapier,2384,40;sabre,2385,150;magic longsword,2390,600000;fire sword,2392,4000;giant sword,2393,17000;carlin sword,2395,1000;ice rapier,2396,1000;longsword,2397,50;silver dagger,2402,500;knife,2403,3;combat knife,2404,6;sickle,2405,10;short sword,2406,80;bright sword,2407,3000;warlord sword,2408,100000;serpent sword,2409,900;poison dagger,2411,50;katana,2412,40;broadsword,2413,350;golden sickle,2418,100;scimitar,2419,150;heavy machete,2442,90;epee,2438,100000;bone sword,2450,100;djinn blade,2451,600000;avenger,6528,200000;demonrage sword,7382,10000;relic sword,7383,25000;mystic blade,7384,10000;crimson sword,7385,500;mercenary sword,7386,20000;justice seeker,7390,70000;thaian sword,7391,15000;dragon slayer,7402,15000;assassin dagger,7404,15000;havoc blade,7405,7000;blacksteel sword,7406,2000;haunted blade,7407,10000;wyvern fang,7408,2000;bloody edge,7416,10000;runed sword,7417,10000;nightmare blade,7418,30000;crystal sword,7449,600;emerald sword,8930,300000;jagged sword,8602,80000;golden sword,8931,1000000;calamity,8932,70000;war hammer,2391,900;morning star,2394,100;mace,2398,30;staff,2401,25;crowbar,2416,50;battle hammer,2417,150;thunder hammer,2421,300000;iron hammer,2422,50;clerical mace,2423,200;silver mace,2424,100000;dragon hammer,2434,2000;skull staff,2436,6000;daramanian mace,2439,200;hammer of wrath,2444,75000;crystal mace,2445,30000;studded club,2448,35;bone club,2449,50;arcane staff,2453,30000;lich staff,3961,15000;banana staff,3966,1000;brutetamers staff,7379,2000;mammoth whopper,7381,400;diamond sceptre,7387,4000;orcish maul,7392,1000;sapphire hammer,7437,7000;shadow sceptre,7451,100000;spiked squelcher,7452,500;queens sceptre,7410,2000000;abyss hammer,7414,500000;cranial basher,7415,10000;jade hammer,7422,70000;lunar staff,7424,7000;taurus mace,7425,600;amber staff,7426,8000;chaos mace,7427,10000;dragonbone staff,7430,3000;furry club,7432,500;dark trinity mace,8927,700000;obsidian truncheon,8928,400000;stomper,8929,250000;battle axe,2378,100;hand axe,2380,20;halberd,2381,400;double axe,2387,300;hatchet,2388,25;great axe,2415,20000;obsidian lance,2425,500;naginata,2426,1000;guardian halberd,2427,5000;orcish axe,2428,200;barbarian axe,2429,300;knight axe,2430,1000;stonecutter axe,2431,600000;fire axe,2432,7000;dwarven axe,2435,1000;daramanian waraxe,2440,900;daramanian axe,2441,400;ravagers axe,2443,50000;twin axe,2447,60000;war axe,2454,10000;beastslayer axe,3962,2000;ruthless axe,6553,70000;headchopper,7380,4000;vile axe,7388,60000;heroic axe,7389,15000;relic axe,7411,40000;butchers axe,7412,70000;titan axe,7413,40000;bloodslayer axe,7453,40000;destroyers axe,7454,60000;ice double axe,7455,90000;cursed axe,7433,30000;royal axe,7434,150000;black axe,7435,300000;angelwing axe,7436,200000;"/>
    </parameters>
</npc>
.lua_2
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

npcHandler:addModule(FocusModule:new())

^ Here they are :)
 
Okay they are fine..

Can I see the ShopModule.onBuy and ShopModule.onSell functions? should be in modules.lua

Sure :)
Here it is: (modules.lua)

Callback onBuy() function:
Lua:
    -- Callback onBuy() function. If you wish, you can change certain Npc to use your onBuy().
    function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
        local shopItem = nil
        for _, item in ipairs(self.npcHandler.shopItems) do
            if(item.id == itemid and item.subType == subType) then
                shopItem = item
                break
            end
        end

        if(shopItem == nil) then
            error("[ShopModule.onBuy]", "Item not found on shopItems list")
            return false
        end

        if(shopItem.buy == -1) then
            error("[ShopModule.onSell]", "Attempt to purchase an item which only sellable")
            return false
        end

Callback onSell() function:
Lua:
    -- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
    function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
        local shopItem = nil
        for _, item in ipairs(self.npcHandler.shopItems) do
            if(item.id == itemid and item.subType == subType) then
                shopItem = item
                break
            end
        end

        if(shopItem == nil) then
            error("[ShopModule.onBuy]", "Item not found on shopItems list")
            return false
        end

        if(shopItem.sell == -1) then
            error("[ShopModule.onSell]", "Attempt to sell an item which is only buyable")
            return false
        end

#SOLVED thanks to @Thaian Citizen :)
 
Last edited:
Back
Top