• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua TFS 1.2 - Adding "sell all vials"

Eldora

Banned User
Joined
Oct 19, 2009
Messages
604
Reaction score
26
Please help add so that if I say "sell all vials" or "vials" then the NPC will buy all vials (5 gold each).
Post automatically merged:

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
function onPlayerEndTrade(cid)                npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)            npcHandler:onPlayerCloseChannel(cid)        end

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

keywordHandler:addKeyword({'runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: animate dead, blank rune, desintegrate, energy bomb, fireball, magic wall, paralyze, poison bomb, soulfire, stone shower, wild growth, antidote, chamaleon, convince creature, destroy field, energy field, energy wall, explosion, fire bomb, fire field, greate fireball, light magic missile, heavy magic missile, intense healing, poison field, poison wall, stalagmite, ultimate healing and sudden death.'})
keywordHandler:addKeyword({'potions'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: mana fluid and life fluid.'})
keywordHandler:addKeyword({'wands'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: wand of vortex, wand of dragonbreath, wand of plague, wand of cosmic energy and wand of inferno..'})
keywordHandler:addKeyword({'rods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: snakebite rod, moonlight rod, volcanic rod, quagmire rod and tempest rod'})


shopModule:addBuyableItem({'spellbook'}, 2175, 150, 'spellbook')
shopModule:addBuyableItem({'magic lightwand'}, 2163, 400, 'magic lightwand')

shopModule:addBuyableItem({'mana fluid', 'manafluid'}, 2006, 50, 7, 'mana fluid')
shopModule:addBuyableItem({'life fluid', 'lifefluid'}, 2006, 50, 2, 'life fluid')

shopModule:addBuyableItemContainer({'bp mf'}, 2001, 2006, 1000, 7, 'backpack of mana fluids')
shopModule:addBuyableItemContainer({'bp lf'}, 2000, 2006, 1000, 2, 'backpack of life fluids')

shopModule:addBuyableItem({'blank rune'}, 2260, 10, 1, 'blank rune')

shopModule:addSellableItem({'vial', 'flask'}, 7490, 5, 'empty vial', 0)

shopModule:addBuyableItemContainer({'bp sd'}, 2003, 2268, 6500, 2, 'backpack of sudden death rune')
shopModule:addBuyableItemContainer({'bp ava'}, 2002, 2274, 3600, 4, 'backpack of avalanche rune')
shopModule:addBuyableItemContainer({'bp uh'}, 2002, 2273, 3500, 2, 'backpack of ultimate healing rune')
shopModule:addBuyableItemContainer({'bp gfb'}, 2000, 2304, 3600, 4, 'backpack of great fireball rune')
shopModule:addBuyableItemContainer({'bp br'}, 1988, 2260, 200, 1, 'backpack of blank rune')
shopModule:addBuyableItemContainer({'bp ih'}, 2003, 2265, 1900, 2, 'backpack of intense healing rune')
shopModule:addBuyableItemContainer({'bp hmm'}, 2001, 2311, 2500, 10, 'backpack of heavy magic missile rune')
shopModule:addBuyableItemContainer({'bp lmm'}, 1998, 2287, 800, 10, 'backpack of light magic missile rune')
shopModule:addBuyableItemContainer({'bp fb'}, 2000, 2302, 1900, 10, 'backpack of fireball rune')
shopModule:addBuyableItemContainer({'bp exp'}, 2001, 2313, 5000, 6, 'backpack of explosion rune')
shopModule:addBuyableItemContainer({'bp mwall'}, 1999, 2293, 2320, 6, 'backpack of magic wall rune')
shopModule:addBuyableItemContainer({'bp para'}, 5949, 2278, 14000, 2, 'backpack of paralyze rune')
shopModule:addBuyableItemContainer({'bp ani'}, 2001, 2316, 7500, 2, 'backpack of animate dead rune')
shopModule:addBuyableItemContainer({'bp anti'}, 2003, 2266, 1300, 2, 'backpack of antidote rune')
shopModule:addBuyableItemContainer({'bp cham'}, 1998, 2291, 4200, 2, 'backpack of chameleon rune')
shopModule:addBuyableItemContainer({'bp conv'}, 1998, 2290, 1600, 2, 'backpack of convince creature rune')
shopModule:addBuyableItemContainer({'bp destro'}, 2003, 2261, 900, 6, 'backpack of destroy rune')
shopModule:addBuyableItemContainer({'bp desint'}, 2001, 2310, 520, 6, 'backpack of desintegrate rune')
shopModule:addBuyableItemContainer({'bp ebomb'}, 2003, 2262, 4060, 4, 'backpack of energy bomb rune')
shopModule:addBuyableItemContainer({'bp efield'}, 2002, 2277, 2300, 2, 'backpack of energy field rune')
shopModule:addBuyableItemContainer({'bp ewall'}, 2002, 2279, 6800, 2, 'backpack of energy wall rune')
shopModule:addBuyableItemContainer({'bp fbomb'}, 2000, 2305, 4700, 4, 'backpack of fire bomb rune')
shopModule:addBuyableItemContainer({'bp ffield'}, 2000, 2301, 1700, 6, 'backpack of fire field rune')
shopModule:addBuyableItemContainer({'bp fwall'}, 2000, 2303, 4900, 8, 'backpack of fire wall rune')
shopModule:addBuyableItemContainer({'bp pbomb'}, 1998, 2286, 1700, 4, 'backpack of poison bomb rune')
shopModule:addBuyableItemContainer({'bp pfield'}, 1998, 2285, 1300, 6, 'backpack of poison field rune')
shopModule:addBuyableItemContainer({'bp pwall'}, 1998, 2289, 4200, 8, 'backpack of poison field rune')
shopModule:addBuyableItemContainer({'bp sf'}, 2000, 2308, 920, 6, 'backpack of soul fire rune')


shopModule:addBuyableItem({'wand of vortex', 'vortex'}, 2190, 500, 'wand of vortex')
shopModule:addBuyableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 1000, 'wand of dragonbreath')
shopModule:addBuyableItem({'wand of plague', 'plague'}, 2188, 5000, 'wand of plague')
shopModule:addBuyableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 10000, 'wand of cosmic energy')
shopModule:addBuyableItem({'wand of inferno', 'inferno'}, 2187, 15000, 'wand of inferno')

shopModule:addBuyableItem({'snakebite rod', 'snakebite'}, 2182, 500, 'snakebite rod')
shopModule:addBuyableItem({'moonlight rod', 'moonlight'}, 2186, 1000, 'moonlight rod')
shopModule:addBuyableItem({'volcanic rod', 'volcanic'}, 2185, 1000, 'volcanic rod')
shopModule:addBuyableItem({'quagmire rod', 'quagmire'}, 2181, 2000, 'quagmire rod')
shopModule:addBuyableItem({'tempest rod', 'tempest'}, 2183, 15000, 'tempest rod')


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')

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

    local player = Player(cid)
    local vocationId = player:getVocation():getId()
    local items = {
        [1] = 2190,
        [2] = 2182,
        [5] = 2190,
        [6] = 2182
    }

    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if isInArray({1, 2, 5, 6}, vocationId) then
            if player:getStorageValue(30002) == -1 then
                selfSay('So you ask me for a {' .. ItemType(items[vocationId]):getName() .. '} to begin your advanture?', cid)
                npcHandler.topic[cid] = 1
            else
                selfSay('What? I have already gave you one {' .. ItemType(items[vocationId]):getName() .. '}!', cid)
            end
        else
            selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(items[vocationId], 1)
            player:setStorageValue(30002, 1)
            selfSay('Here you are young adept, take care yourself.', cid)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Just update these empty vial itemId's.
LUA:
-- vial selling
local empty_vials = {1111, 2222, 3333, 4444}

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
function onPlayerEndTrade(cid)                  npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)              npcHandler:onPlayerCloseChannel(cid)        end

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

keywordHandler:addKeyword({'runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: animate dead, blank rune, desintegrate, energy bomb, fireball, magic wall, paralyze, poison bomb, soulfire, stone shower, wild growth, antidote, chamaleon, convince creature, destroy field, energy field, energy wall, explosion, fire bomb, fire field, greate fireball, light magic missile, heavy magic missile, intense healing, poison field, poison wall, stalagmite, ultimate healing and sudden death.'})
keywordHandler:addKeyword({'potions'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: mana fluid and life fluid.'})
keywordHandler:addKeyword({'wands'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: wand of vortex, wand of dragonbreath, wand of plague, wand of cosmic energy and wand of inferno..'})
keywordHandler:addKeyword({'rods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell: snakebite rod, moonlight rod, volcanic rod, quagmire rod and tempest rod'})


shopModule:addBuyableItem({'spellbook'}, 2175, 150, 'spellbook')
shopModule:addBuyableItem({'magic lightwand'}, 2163, 400, 'magic lightwand')

shopModule:addBuyableItem({'mana fluid', 'manafluid'}, 2006, 50, 7, 'mana fluid')
shopModule:addBuyableItem({'life fluid', 'lifefluid'}, 2006, 50, 2, 'life fluid')

shopModule:addBuyableItemContainer({'bp mf'}, 2001, 2006, 1000, 7, 'backpack of mana fluids')
shopModule:addBuyableItemContainer({'bp lf'}, 2000, 2006, 1000, 2, 'backpack of life fluids')

shopModule:addBuyableItem({'blank rune'}, 2260, 10, 1, 'blank rune')

shopModule:addSellableItem({'vial', 'flask'}, 7490, 5, 'empty vial', 0)

shopModule:addBuyableItemContainer({'bp sd'}, 2003, 2268, 6500, 2, 'backpack of sudden death rune')
shopModule:addBuyableItemContainer({'bp ava'}, 2002, 2274, 3600, 4, 'backpack of avalanche rune')
shopModule:addBuyableItemContainer({'bp uh'}, 2002, 2273, 3500, 2, 'backpack of ultimate healing rune')
shopModule:addBuyableItemContainer({'bp gfb'}, 2000, 2304, 3600, 4, 'backpack of great fireball rune')
shopModule:addBuyableItemContainer({'bp br'}, 1988, 2260, 200, 1, 'backpack of blank rune')
shopModule:addBuyableItemContainer({'bp ih'}, 2003, 2265, 1900, 2, 'backpack of intense healing rune')
shopModule:addBuyableItemContainer({'bp hmm'}, 2001, 2311, 2500, 10, 'backpack of heavy magic missile rune')
shopModule:addBuyableItemContainer({'bp lmm'}, 1998, 2287, 800, 10, 'backpack of light magic missile rune')
shopModule:addBuyableItemContainer({'bp fb'}, 2000, 2302, 1900, 10, 'backpack of fireball rune')
shopModule:addBuyableItemContainer({'bp exp'}, 2001, 2313, 5000, 6, 'backpack of explosion rune')
shopModule:addBuyableItemContainer({'bp mwall'}, 1999, 2293, 2320, 6, 'backpack of magic wall rune')
shopModule:addBuyableItemContainer({'bp para'}, 5949, 2278, 14000, 2, 'backpack of paralyze rune')
shopModule:addBuyableItemContainer({'bp ani'}, 2001, 2316, 7500, 2, 'backpack of animate dead rune')
shopModule:addBuyableItemContainer({'bp anti'}, 2003, 2266, 1300, 2, 'backpack of antidote rune')
shopModule:addBuyableItemContainer({'bp cham'}, 1998, 2291, 4200, 2, 'backpack of chameleon rune')
shopModule:addBuyableItemContainer({'bp conv'}, 1998, 2290, 1600, 2, 'backpack of convince creature rune')
shopModule:addBuyableItemContainer({'bp destro'}, 2003, 2261, 900, 6, 'backpack of destroy rune')
shopModule:addBuyableItemContainer({'bp desint'}, 2001, 2310, 520, 6, 'backpack of desintegrate rune')
shopModule:addBuyableItemContainer({'bp ebomb'}, 2003, 2262, 4060, 4, 'backpack of energy bomb rune')
shopModule:addBuyableItemContainer({'bp efield'}, 2002, 2277, 2300, 2, 'backpack of energy field rune')
shopModule:addBuyableItemContainer({'bp ewall'}, 2002, 2279, 6800, 2, 'backpack of energy wall rune')
shopModule:addBuyableItemContainer({'bp fbomb'}, 2000, 2305, 4700, 4, 'backpack of fire bomb rune')
shopModule:addBuyableItemContainer({'bp ffield'}, 2000, 2301, 1700, 6, 'backpack of fire field rune')
shopModule:addBuyableItemContainer({'bp fwall'}, 2000, 2303, 4900, 8, 'backpack of fire wall rune')
shopModule:addBuyableItemContainer({'bp pbomb'}, 1998, 2286, 1700, 4, 'backpack of poison bomb rune')
shopModule:addBuyableItemContainer({'bp pfield'}, 1998, 2285, 1300, 6, 'backpack of poison field rune')
shopModule:addBuyableItemContainer({'bp pwall'}, 1998, 2289, 4200, 8, 'backpack of poison field rune')
shopModule:addBuyableItemContainer({'bp sf'}, 2000, 2308, 920, 6, 'backpack of soul fire rune')


shopModule:addBuyableItem({'wand of vortex', 'vortex'}, 2190, 500, 'wand of vortex')
shopModule:addBuyableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 1000, 'wand of dragonbreath')
shopModule:addBuyableItem({'wand of plague', 'plague'}, 2188, 5000, 'wand of plague')
shopModule:addBuyableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 10000, 'wand of cosmic energy')
shopModule:addBuyableItem({'wand of inferno', 'inferno'}, 2187, 15000, 'wand of inferno')

shopModule:addBuyableItem({'snakebite rod', 'snakebite'}, 2182, 500, 'snakebite rod')
shopModule:addBuyableItem({'moonlight rod', 'moonlight'}, 2186, 1000, 'moonlight rod')
shopModule:addBuyableItem({'volcanic rod', 'volcanic'}, 2185, 1000, 'volcanic rod')
shopModule:addBuyableItem({'quagmire rod', 'quagmire'}, 2181, 2000, 'quagmire rod')
shopModule:addBuyableItem({'tempest rod', 'tempest'}, 2183, 15000, 'tempest rod')


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')

local items = {
    [1] = 2190,
    [2] = 2182,
    [5] = 2190,
    [6] = 2182
}

-- vial selling
local empty_vials = {1111, 2222, 3333, 4444}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    local player = Player(cid)
    local vocationId = player:getVocation():getId()

    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if isInArray({1, 2, 5, 6}, vocationId) then
            if player:getStorageValue(30002) == -1 then
                selfSay('So you ask me for a {' .. ItemType(items[vocationId]):getName() .. '} to begin your advanture?', cid)
                npcHandler.topic[cid] = 1
            else
                selfSay('What? I have already gave you one {' .. ItemType(items[vocationId]):getName() .. '}!', cid)
            end
        else
            selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
 
    -- vial selling
    elseif msgcontains(msg, "vial") then
        selfSay("Would you like to sell all your empty vials for 5gp each?", cid)
        npcHandler.topic[cid] = 2
 
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(items[vocationId], 1)
            player:setStorageValue(30002, 1)
            selfSay('Here you are young adept, take care yourself.', cid)
        end
    
        -- vial selling
        if npcHandler.topic[cid] == 2 then
            local total_gold = 0
            for i = 1, #empty_vials do
                total_gold = total_gold + (player:getItemCount(empty_vials[i]) * 5)
            end
        
            if total_gold == 0 then
                selfSay("You don't have any empty vials..", cid)
                npcHandler.topic[cid] = 0
                return true
            end
        
            if not player:addMoney(total_gold) then
                selfSay("Your pockets are too full for the gold you would recieve. Clear out some inventory and try again.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
        
            for i = 1, #empty_vials do
                player:removeItem(empty_vials[i], player:getItemCount(empty_vials[i]))
            end
        
            selfSay("Thanks. Here is " .. total_gold .. " gold for the " .. (total_gold / 5) .. " empty vials you had on you.", cid)
        end
        npcHandler.topic[cid] = 0
    
    -- vial selling
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] >= 1 and npcHandler.topic[cid] <= 2 then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    
    end
 
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
If it's some old protocol like 7.x you need to check vial of ID: 2006 with subtype 0 (empty).
In later protocols they've added empty vial items for each potion type so take that into account.
 
Back
Top