• 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.2] NPC Selling items with 1 charge

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,391
Solutions
7
Reaction score
550
Does anyone know how to fix this problem? Testing on Haroun

Haroun.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Haroun" script="Haroun.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="80" />
    <parameters>
        <parameter key="module_shop" value="1" />
        <parameter key="shop_buyable" value="
            axe ring, 2208, 500;
            club ring, 2209, 500;
            power ring, 2166, 100;
            stealth ring, 2165, 5000;
            sword ring, 2207, 500;
            bronze amulet, 2172, 100;
            garlic necklace, 2199, 100;
            elven amulet, 2198, 500;
            stone skin amulet, 2197, 5000;
            magic light wand, 2162, 120 " />
        <parameter key="shop_sellable" value="
            axe ring, 2208, 100;
            club ring, 2209, 100;
            power ring, 2166, 50;
            stealth ring, 2165, 200;
            sword ring, 2207, 100;
            bronze amulet, 2172, 50;
            garlic necklace, 2199, 50;
            elven amulet, 2198, 100;
            stone skin amulet, 2197, 500, 5;      <<<<<<<<<<<< Tried defining charges like this without success. 
            wand of cosmic energy, 2189, 2000;
            wand of decay, 2188, 1000;
            wand of defiance, 18390, 6500;
            wand of everblazing, 18409, 6000;
            wand of dragonbreath, 2191, 200;
            wand of inferno, 2187, 3000;
            wand of vortex, 2190, 100;
            wand of draconia, 8921, 1500;
            wand of starstorm, 8920, 3600;
            wand of voodoo, 8922, 4400;
            magic light wand, 2162, 35;
            life crystal, 4851, 50;
            mind stone, 2178, 100;
            orb, 2176, 750 " />
    </parameters>
</npc>


Code:
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"}, 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"}, 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"}, 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"}, msg) then
        npcHandler:say('Do you want to trade 3 Fire Sword for Magic Sulphur', cid)
        npcHandler.topic[cid] = 4
    elseif isInArray({"job", "items"}, 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,'yes') and npcHandler.topic[cid] <= 4 and npcHandler.topic[cid] >= 1 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 msgcontains(msg,'no') and (npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 5) then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
    end
    return true
end

--local function onTradeRequest(cid)
    --if Player(cid):getStorageValue(Storage.DjinnWar.MaridFaction.Mission03) ~= 3 then
        --npcHandler:say('I\'m sorry, human. But you need Gabel\'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! May the serene light of the enlightened one rest shine on your travels.")
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)
npcHandler:addModule(FocusModule:new())
 
Are u sure that in items.xml u have 5 charges?

Indeed.
Code:
    <item id="2197" article="a" name="stone skin amulet">
        <attribute key="weight" value="700" />
        <attribute key="slotType" value="necklace" />
        <attribute key="charges" value="5" />
        <attribute key="showcharges" value="1" />
        <attribute key="absorbPercentPhysical" value="80" />
        <attribute key="absorbPercentDeath" value="80" />
        <attribute key="showattributes" value="1" />
    </item>
 
Code:
player:addItem(itemId[, count = 1[, canDropOnMap = true[, subType = 1[, slot = CONST_SLOT_WHEREEVER]]]])
 
How about posting the code and a screen shot of the error?

Heres code
Code:
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"}, 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"}, 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"}, 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"}, msg) then
        npcHandler:say('Do you want to trade 3 Fire Sword for Magic Sulphur', cid)
        npcHandler.topic[cid] = 4
    elseif isInArray({"job", "items"}, 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,'yes') and npcHandler.topic[cid] <= 4 and npcHandler.topic[cid] >= 1 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(itemId[, count = 1[, canDropOnMap = true[, subType = 1[, slot = CONST_SLOT_WHEREEVER]]]])
            return npcHandler:say('Here you are.', cid)
        else
            npcHandler:say('Sorry but you don\'t have the item.', cid)
        end
    elseif msgcontains(msg,'no') and (npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 5) then
        npcHandler:say('Ok then.', cid)
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
    end
    return true
end

--local function onTradeRequest(cid)
    --if Player(cid):getStorageValue(Storage.DjinnWar.MaridFaction.Mission03) ~= 3 then
        --npcHandler:say('I\'m sorry, human. But you need Gabel\'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! May the serene light of the enlightened one rest shine on your travels.")
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)
npcHandler:addModule(FocusModule:new())

The error was legitimately that though lol
Kcpp21W.jpg


I also tried changing the shop module to this but it didn't add the charges either :'(

Code:
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'spellbook'}, 2197, 500,5, 'stone skin amulet')
 
Code:
player:addItem(itemId[, count = 1[, canDropOnMap = true[, subType = 1[, slot = CONST_SLOT_WHEREEVER]]]])
Sigh... this is an explanation on how the function works and its default parameters.

If you see a parameter starting with [ followed by a comma, this means the following parameters are optional.

Please read this tutorial completely, it will help you understand the code your looking at.
http://www.tutorialspoint.com/lua/
 
I never used attribute charges, I have my own custom way how to handle them But try this:
local item = player:addItem(itemID, count)
if charges > 1 then
item:setAttribute(ITEM_ATTRIBUTE_CHARGES, charges)
end

itemID = should be the itemID of what item you want to give to player
count = how many of these items you want to give.
charges = how many charges item should have
 
FYI My loot seller is working fine.. there is something in the .lua thats stopping it but i cant see it gahH!!

lootseller.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Loot Seller" script="lootseller.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100" />
    <look type="129" head="58" body="68" legs="101" feet="95" addons="0" />
    <parameters>
        <parameter key="module_shop" value="1" />
        <parameter key="shop_buyable" value="
            stone skin amulet, 2197, 500, 5;"
            />
        <parameter key="shop_sellable" value="
            stone skin amulet, 2197, 500, 5;"
            />
    </parameters>
</npc>

lootseller.lua
Code:
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

local lastSound = 0
function onThink()
    if lastSound < os.time() then
        lastSound = (os.time() + 5)
        if math.random(100) < 25 then
            Npc():say("Sell your loot to me!", TALKTYPE_SAY)
        end
    end
    npcHandler:onThink()
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Oh, please come in, |PLAYERNAME|. What do you need?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just browse through my wares.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Fixed. That awkward moment when you put the charges in the sell instead of the buy.
 
Back
Top