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

Lua TFS 1.2 8.0 Distro problem with vials

Roni123

Hardstyle Never Die < 3 !!!
Joined
Aug 31, 2010
Messages
152
Solutions
1
Reaction score
18
Good Morning,

Dears,

I have problem with sell and exchange potions in 8.0 distro, cuz there all of vials have ID 2006 and next "prefix" e.g mana fluid /i 2006,7 , life fluid /i 2006,2, so when I want to exchange potions in Sandra for lottery ticket from below function, then she don't count any vials and give lottery ticket for free

Lua:
            npcHandler.topic[cid] = 2
        elseif npcHandler.topic[cid] == 2 then
            npcHandler:say("Great! I've signed you up for our bonus system. From now on, you will have the chance to win the potion belt addon!", cid)
            player:setStorageValue(1060, 1)
            player:setStorageValue(1033, 1) --this for default start of Outfit and Addon Quests
            npcHandler.topic[cid] = 0
        elseif npcHandler.topic[cid] == 3 then
            if player:removeItem(2006, 0, 100) then
                npcHandler:say("Ok heretake this lottery ticket!", cid)
                player:addItem(5957, 1)
                npcHandler.topic[cid] = 0
            else
                npcHandler:say("You don't have 100 empty vials.", cid)
                npcHandler.topic[cid] = 0
            end
        elseif npcHandler.topic[cid] == 4 then
            if player:getStorageValue(1060) == 1 and player:removeItem(5958, 1) then
                npcHandler:say("Congratulations! Here, from now on you can wear our lovely potion belt as accessory.", cid)
                player:setStorageValue(1060, 2)
                player:addOutfitAddon(138, 1)
                player:addOutfitAddon(133, 1)
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            else
                npcHandler:say("You don't have any prize to claim!", cid)
            end
            npcHandler.topic[cid] = 0
        end
        return true
    end
end

and when I change line on below, then she count vials but all of them e.g empty+mana fluid+life fluid to 100 PCS,
Lua:
if player:removeItem(2006, 100) then

Similar problem are in npc when I want to sell potions with below script then NPC count all types of vials e.g empty+mana fluid+life fluid
Lua:
shopModule:addSellableItem({'vial'}, 2006, 5, 'vial')

and when I change on this, then NPC writes nonsense...
Lua:
shopModule:addSellableItem({'vial'}, 2006, 0, 5, 'vial')

Thanks in advance !
 
Good Morning,

Dears,

I have problem with sell and exchange potions in 8.0 distro, cuz there all of vials have ID 2006 and next "prefix" e.g mana fluid /i 2006,7 , life fluid /i 2006,2, so when I want to exchange potions in Sandra for lottery ticket from below function, then she don't count any vials and give lottery ticket for free

Lua:
            npcHandler.topic[cid] = 2
        elseif npcHandler.topic[cid] == 2 then
            npcHandler:say("Great! I've signed you up for our bonus system. From now on, you will have the chance to win the potion belt addon!", cid)
            player:setStorageValue(1060, 1)
            player:setStorageValue(1033, 1) --this for default start of Outfit and Addon Quests
            npcHandler.topic[cid] = 0
        elseif npcHandler.topic[cid] == 3 then
            if player:removeItem(2006, 0, 100) then
                npcHandler:say("Ok heretake this lottery ticket!", cid)
                player:addItem(5957, 1)
                npcHandler.topic[cid] = 0
            else
                npcHandler:say("You don't have 100 empty vials.", cid)
                npcHandler.topic[cid] = 0
            end
        elseif npcHandler.topic[cid] == 4 then
            if player:getStorageValue(1060) == 1 and player:removeItem(5958, 1) then
                npcHandler:say("Congratulations! Here, from now on you can wear our lovely potion belt as accessory.", cid)
                player:setStorageValue(1060, 2)
                player:addOutfitAddon(138, 1)
                player:addOutfitAddon(133, 1)
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            else
                npcHandler:say("You don't have any prize to claim!", cid)
            end
            npcHandler.topic[cid] = 0
        end
        return true
    end
end

and when I change line on below, then she count vials but all of them e.g empty+mana fluid+life fluid to 100 PCS,
Lua:
if player:removeItem(2006, 100) then

Similar problem are in npc when I want to sell potions with below script then NPC count all types of vials e.g empty+mana fluid+life fluid
Lua:
shopModule:addSellableItem({'vial'}, 2006, 5, 'vial')

and when I change on this, then NPC writes nonsense...
Lua:
shopModule:addSellableItem({'vial'}, 2006, 0, 5, 'vial')

Thanks in advance !
Solved Sandra !
If someone will have the same problem with Sandra then need to use below lua,

Lua:
if player:removeItem(2006, 100, 0) then
Post automatically merged:

I think that with sellable function can be something wrong in modules.lua can someone take look on it ? I add in attachment all file.

When I try to add below lua into this function function ShopModule:addSellableItem(names, itemid, cost, realName, itemSubType), then I have much errors in NPC's,
Code:
subType = itemSubType or 1
 

Attachments

Last edited:
Solved Sandra !
If someone will have the same problem with Sandra then need to use below lua,

Lua:
if player:removeItem(2006, 100, 0) then
Post automatically merged:

I think that with sellable function can be something wrong in modules.lua can someone take look on it ? I add in attachment all file.

When I try to add below lua into this function function ShopModule:addSellableItem(names, itemid, cost, realName, itemSubType), then I have much errors in NPC's,
Code:
subType = itemSubType or 1
Ok, Problem has been solved ! Many Thanks for esigma94 its a master of LUA :)

Steps to do it:

1) Need to add subType = itemSubType in modules.lua below ShopModule:addSellableItem where are local parameters
Lua:
local parameters = {
    itemid = itemid,
    cost = cost,
    eventType = SHOPMODULE_SELL_ITEM,
    module = self,
    realName = realName or ItemType(itemid):getName(),
    subType = itemSubType
}

2) Go to data/npc/lib/npc.lua and check two function of doPlayerTakeItem and doPlayerSellItem if they are the same or similar like below code:
then change this function on:
Lua:
function doPlayerTakeItem(cid, itemid, count, subtype)
    if getPlayerItemCount(cid, itemid, subtype) < count then
        return false
    end

    while count > 0 do
        local tempcount = 0
        if isItemStackable(itemid) then
            tempcount = math.min (100, count)
        else
            tempcount = 1
        end

        local ret = doPlayerRemoveItem(cid, itemid, tempcount, subtype)
        if ret ~= false then
            count = count - tempcount
        else
            return false
        end
    end

    if count ~= 0 then
        return false
    end
    return true
end

function doPlayerSellItem(cid, itemid, count, cost, subtype)
    if doPlayerTakeItem(cid, itemid, count, subtype) == true then
        if not doPlayerAddMoney(cid, cost) then
            error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
        end
        return true
    end
    return false
end

3) Find this line local ret = doPlayerSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_cost[cid] * shop_amount[cid]) in modules.lua and change for this,
Lua:
local ret = doPlayerSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_cost[cid] * shop_amount[cid], shop_subtype[cid])

4) And now you can sell only empty vials with below function in NPC,
Lua:
shopModule:addSellableItem({'vial', 'fluid'}, 2006, 5, 'empty vial', 0)
 
Last edited:
Tried your script, and it works great for vials.
But for some odd reason it stops working on for example the NPC Tom in rookgaard to sell dead rats and such.

Any idea why?

This is from Tom.lua

Lua:
shopModule:addSellableItem({'rat'}, 2813, 2, 'dead rat')

When I greet the NPC and say sell dead rat, he just reply that I do not have any to sell (even tho I have).
Not really sure what parameter is wrong here
-- Update --

Ok I found that you are using SHOPMODULE_MODE_TRADE. But on for instance client version 7.72, the trade window was not implemented. So need to use SHOPMODULE_MODE_TALK, so need to work with that instead.
 
Last edited:
Tried your script, and it works great for vials.
But for some odd reason it stops working on for example the NPC Tom in rookgaard to sell dead rats and such.

Any idea why?

This is from Tom.lua

Lua:
shopModule:addSellableItem({'rat'}, 2813, 2, 'dead rat')

When I greet the NPC and say sell dead rat, he just reply that I do not have any to sell (even tho I have).
Not really sure what parameter is wrong here
-- Update --

Ok I found that you are using SHOPMODULE_MODE_TRADE. But on for instance client version 7.72, the trade window was not implemented. So need to use SHOPMODULE_MODE_TALK, so need to work with that instead.
Sorted this out myself, change this in modules.lua :

search for ShopModule:addBuyableItem on around line 800 (depending on your files.
Change it to :

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

Then on NPC Sandra for example, (sandra.lua) you need to specify what fluids you want her to sell like this :

Lua:
shopModule:addBuyableItem({'manafluid', 'mana'}, 2006, 55, 'vial of manafluid', 7)
shopModule:addBuyableItem({'lifefluid', 'life'}, 2006, 60, 'vial of lifefluid', 10)
shopModule:addBuyableItem({'water'}, 2006, 8, 'vial of water', 1)
shopModule:addBuyableItem({'slime'}, 2006, 12, 'slime', 12)
 
Seems like a nice fix for a moment but this completely breaks selling items to npc. Even when applying what Hayvosh.
Only thing I am able to sell is vials now. Anyone know alternative fix for this? Appreciated.
 
I did that and it worked on the vial issue, but now the other npcs now it thinks every item has a subtype and do not buy any items, Anyone know alternative fix for this? Please.
 
Back
Top