• 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.5 Nekiro 772 sell empty vial in npc

Gover

Member
Joined
Sep 3, 2009
Messages
41
Reaction score
6
Helo,
I have a question about selling empty flasks to npc's (like Xodet).
In this protocol the buy function need a item subType, which is for example equals 7 for mana fluid.

LUA:
shopModule:addBuyableItem({'mf', 'mana fluid', 'manafluid'}, 2006, 55, 7, 'mana fluid')

And buying is working great, but selling the empty vials, is not working with item subType.
LUA:
shopModule:addSellableItem({'vial', 'flask'}, 2006, 5, 'empty vial', 0)
The above will buy the item 2006 from player regardless of the subType (it will buy full mana fluids, empty fluids and any of the item 2006, empty or not).
This "0" at the end of the line is ignored I think.
self:addSellableItem(nil, itemid, cost, realName, subType)

Thanks in advance for help with this :)
 
Solution
I had trouble with this and ended up making a new "used vial" item that is stackable and sellable to NPCs. You either need to modify addSellableItem enough to make it work with empty vials (I did not get this working), or do something like I did.
I had trouble with this and ended up making a new "used vial" item that is stackable and sellable to NPCs. You either need to modify addSellableItem enough to make it work with empty vials (I did not get this working), or do something like I did.
 
Solution
here are some hints, figure it out



 
Thank you both for help.
@boiga - followed your advice and created a new item for empty flask. It is working great.

For those who find this interesting here is a corrected fluids.lua from actions/scripts: (it needs to be reviewed/tested, i did not test all kind of fluid containers)
I corrected the magic effect (because originally it was not working), add a local distillery to repair using flasks on ground or other player and corrected the item:transform(5095, FLUID_NONE). 5095 is the new itemid (need to be created in itemeditor and then in items.xml).

LUA:
local drunk = Condition(CONDITION_DRUNK)
drunk:setParameter(CONDITION_PARAM_TICKS, 60000)

local poison = Condition(CONDITION_POISON)
poison:setParameter(CONDITION_PARAM_DELAYED, true)
poison:setParameter(CONDITION_PARAM_MINVALUE, -50)
poison:setParameter(CONDITION_PARAM_MAXVALUE, -120)
poison:setParameter(CONDITION_PARAM_STARTVALUE, -5)
poison:setParameter(CONDITION_PARAM_TICKINTERVAL, 4000)
poison:setParameter(CONDITION_PARAM_FORCEUPDATE, true)

local fluidMessage = {
        [FLUID_BEER] = "Aah...",
        [FLUID_SLIME] = "Urgh!",
        [FLUID_LEMONADE] = "Mmmh.",
        [FLUID_MANA] = "Aaaah...",
        [FLUID_LIFE] = "Aaaah...",
        [FLUID_OIL] = "Urgh!",
        [FLUID_URINE] = "Urgh!",
        [FLUID_WINE] = "Aah...",
        [FLUID_MUD] = "Urgh!",
        [FLUID_RUM] = "Aah...",
        [FLUID_MEAD] = "Aaaah..."
}

local distillery = {[5513] = 5469, [5514] = 5470}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        local targetItemType = ItemType(target.itemid)
        if targetItemType and targetItemType:isFluidContainer() then
                if target.type == FLUID_NONE and item.type ~= FLUID_NONE then
                        target:transform(target:getId(), item.type)
                        item:transform(item:getId(), FLUID_NONE)
                        return true
                elseif target.type ~= FLUID_NONE and item.type == FLUID_NONE then
                        item:transform(item:getId(), target.type)
                        target:transform(target:getId(), FLUID_NONE)
                        return true
                end
        end

        if target.itemid == 1 then
                if item.type == FLUID_NONE then
                        player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
                elseif target.uid == player.uid then
                        if table.contains({FLUID_BEER, FLUID_WINE, FLUID_MEAD}, item.type) then
                                player:addCondition(drunk)
                        elseif item.type == FLUID_SLIME then
                                player:addCondition(poison)
                        elseif item.type == FLUID_MANA then
                                player:addMana(math.random(50, 150))
                                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                        elseif item.type == FLUID_LIFE then
                                player:addHealth(60)
                                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                        end
                        player:say(fluidMessage[item.type] or "Gulp.", TALKTYPE_MONSTER_SAY)
                        if item.type == FLUID_MANA or item.type == FLUID_LIFE then
                        item:transform(5095, FLUID_NONE)
                        else
                        item:transform(item:getId(), FLUID_NONE)
                        end
                else
                        Game.createItem(2016, item.type, toPosition):decay()
                        if item.type == FLUID_MANA or item.type == FLUID_LIFE then
                        item:transform(5095, FLUID_NONE)
                        else
                        item:transform(item:getId(), FLUID_NONE)
                        end
                end
        else
                local fluidSource = targetItemType and targetItemType:getFluidSource() or FLUID_NONE
                if fluidSource ~= FLUID_NONE then
                        item:transform(item:getId(), fluidSource)
                elseif table.contains(distillery, target.itemid) then
                        local tmp = distillery[target.itemid]
                        if tmp then
                                item:transform(item:getId(), FLUID_NONE)
                        else
                                player:sendCancelMessage("You have to process the bunch into the distillery to get rum.")
                        end
                elseif item.type == FLUID_NONE then
                        player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
                else
                        if toPosition.x == CONTAINER_POSITION then
                                toPosition = player:getPosition()
                        end
                        Game.createItem(2016, item.type, toPosition):decay()
                        if item.type == FLUID_MANA or item.type == FLUID_LIFE then
                        item:transform(5095, FLUID_NONE)
                        else
                        item:transform(item:getId(), FLUID_NONE)
                        end
                end
        end
        return true
end

@Azakelis i believe in the lines which you provided is the root cause of this issue, but im not that much skilled to correct such functions.

But this walkaround is working good for my needs :)
 
Last edited:
Back
Top