• 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.x !vial or !flask talkactions

leandroluck

New Member
Joined
Dec 24, 2010
Messages
104
Reaction score
1
Well I'm looking for this function that when the player speaks '! Vial or! Flask' all empty potions will begin to be removed.
In case he speaks again the potions will reappear
 
Solution
@leandroluck Oh okay, I misunderstood

Lua:
local baseStorage = 50000
local vials = {7634, 7635, 7636}

function removePlayerVials(cid)
    local player = Player(cid)
    if not player then
        return
    end
  
    if player:getStorageValue(baseStorage) < 1 then
        return player:returnVials()
    end

    for k,v in pairs(vials) do
        local count = player:getItemCount(v)
        if count > 0 then
            player:setStorageValue(v, math.max(player:getStorageValue(v), 0) + count)
            player:removeItem(v, count)
        end
    end
    addEvent(removePlayerVials, 1000, player:getId())
end

function Player:returnVials()
    for k,v in pairs(vials) do
        local count = self:getStorageValue(v)
        if...
Lua:
local storage_vials = 21000

local vials = {1111, 1111} --Item id of empty vials to store.

function onSay(player, words, param, channel)
    if player:getStorageValue(storage_vials) == -1 or player:getStorageValue(storage_vials) == 0 then
        for i = 1, #vials do
            local count = player:getItemCount(vials[i])
            if count then
                player:removeItem(vials[i], count)
                player:setStorageValue(vials[i], count)
            else
                player:setStorageValue(vials[i], 0)
            end
        end
        player:setStorageValue(storage_vials, 1)
    else
        for i = 1, #vials do
            if player:getStorageValue(vials[i]) ~= -1 and player:getStorageValue(vials[i]) >= 1 then
                player:addItem(vials[i], player:getStorageValue(vials[i]))
                player:setStorageValue(vials[i], 0)
            end
        end
        player:setStorageValue(storage_vials, 0)
    end
   return true
end
 
Lua:
local storage_vials = 21000

local vials = {1111, 1111} --Item id of empty vials to store.

function onSay(player, words, param, channel)
    if player:getStorageValue(storage_vials) == -1 or player:getStorageValue(storage_vials) == 0 then
        for i = 1, #vials do
            local count = player:getItemCount(vials[i])
            if count then
                player:removeItem(vials[i], count)
                player:setStorageValue(vials[i], count)
            else
                player:setStorageValue(vials[i], 0)
            end
        end
        player:setStorageValue(storage_vials, 1)
    else
        for i = 1, #vials do
            if player:getStorageValue(vials[i]) ~= -1 and player:getStorageValue(vials[i]) >= 1 then
                player:addItem(vials[i], player:getStorageValue(vials[i]))
                player:setStorageValue(vials[i], 0)
            end
        end
        player:setStorageValue(storage_vials, 0)
    end
   return true
end
the empty potions are only disappearing when he speaks 'vial'
can do for when the player speaks '! vial' from this moment the potion iram begins to remove little.
If he speaks again the potions will not be removed again.
 
Lua:
local baseStorage = 50000
local vials = {7634, 7635, 7636}

function Player:removeVials()
    for k,v in pairs(vials) do
        local count = self:getItemCount(v)
        if count > 0 then
            self:setStorageValue(v, count)
            self:removeItem(v, count)
        end
    end
end

function Player:returnVials()
    for k,v in pairs(vials) do
        local count = self:getStorageValue(v)
        if count > 0 then
            self:setStorageValue(v, 0)
            self:addItem(v, count, true)
        end
    end
end

function onSay(player, words, param, channel)
    if player:getStorageValue(baseStorage) < 1 then
        player:removeVials()
        player:setStorageValue(baseStorage, 1)
    else
        player:returnVials()
        player:setStorageValue(baseStorage, 0)
    end
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    return false
end
 
Lua:
local baseStorage = 50000
local vials = {7634, 7635, 7636}

function Player:removeVials()
    for k,v in pairs(vials) do
        local count = self:getItemCount(v)
        if count > 0 then
            self:setStorageValue(v, count)
            self:removeItem(v, count)
        end
    end
end

function Player:returnVials()
    for k,v in pairs(vials) do
        local count = self:getStorageValue(v)
        if count > 0 then
            self:setStorageValue(v, 0)
            self:addItem(v, count, true)
        end
    end
end

function onSay(player, words, param, channel)
    if player:getStorageValue(baseStorage) < 1 then
        player:removeVials()
        player:setStorageValue(baseStorage, 1)
    else
        player:returnVials()
        player:setStorageValue(baseStorage, 0)
    end
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    return false
end
Hello, this script is the same as above, the player speaks '! Vial'
all vial will sumi sure. more if he uses potion the vial is still in the backpack I would like it when it says "! vial" a loop ia happens always removing the potions from the backpack without it needs to be talking.
If he speaks again the loop would turn off
 
@leandroluck Oh okay, I misunderstood

Lua:
local baseStorage = 50000
local vials = {7634, 7635, 7636}

function removePlayerVials(cid)
    local player = Player(cid)
    if not player then
        return
    end
  
    if player:getStorageValue(baseStorage) < 1 then
        return player:returnVials()
    end

    for k,v in pairs(vials) do
        local count = player:getItemCount(v)
        if count > 0 then
            player:setStorageValue(v, math.max(player:getStorageValue(v), 0) + count)
            player:removeItem(v, count)
        end
    end
    addEvent(removePlayerVials, 1000, player:getId())
end

function Player:returnVials()
    for k,v in pairs(vials) do
        local count = self:getStorageValue(v)
        if count > 0 then
            self:setStorageValue(v, 0)
            self:addItem(v, count, true)
        end
    end
end
function onSay(player, words, param, channel)
    if player:getStorageValue(baseStorage) < 1 then
        player:setStorageValue(baseStorage, 1)
        removePlayerVials(player:getId())
    else
        player:setStorageValue(baseStorage, 0)  
    end
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    return false
end

If you want it to work after the logout and log back on, without having to write the command again you have to add in login.lua:
Lua:
if player:getStorageValue(50000) == 1 then
    removePlayerVials(player:getId())
end
 
Solution
Code:
if not savedFlasks then
    savedFlasks = {}
end

local flasks = {7636, 7635}
function onSay(player, words, param)
    local guid = player:getGuid()
    if not savedFlasks[guid] then
        savedFlasks[guid] = {}
    end
 
    if #savedFlasks[guid] > 0 then
        for _, tab in pairs(savedFlasks[guid]) do
            player:addItem(tab.id, tab.count)
        end
        savedFlasks[guid] = {}
    else
        for _, flaskId in pairs(flasks) do
            local currCount = player:getItemCount(flaskId)
            if currCount > 0 then
                savedFlasks[guid][#savedFlasks[guid] + 1] = {id = flaskId, count = currCount}
                player:removeItem(flaskId, currCount)
            end
        end
    end
    return true
end

When server gets shutdown savedFlasks will be empty, so players wont get their removed flasks, if you want this to work after server shutdown, you have to save savedFlasks at shutdown in database or use storages.
 
Last edited:
Lua:
local baseStorage = 50000
local vials = {7634, 7635, 7636}

function Player:removeVials()
    for k,v in pairs(vials) do
        local count = self:getItemCount(v)
        if count > 0 then
            self:setStorageValue(v, count)
            self:removeItem(v, count)
        end
    end
end

function Player:returnVials()
    for k,v in pairs(vials) do
        local count = self:getStorageValue(v)
        if count > 0 then
            self:setStorageValue(v, 0)
            self:addItem(v, count, true)
        end
    end
end

function onSay(player, words, param, channel)
    if player:getStorageValue(baseStorage) < 1 then
        player:removeVials()
        player:setStorageValue(baseStorage, 1)
    else
        player:returnVials()
        player:setStorageValue(baseStorage, 0)
    end
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    return false
end

Lua Script Error: [Test Interface]
data/creaturescripts/scripts/others/login.lua
data/creaturescripts/scripts/others/login.lua:108: attempt to index global 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/creaturescripts/scripts/others/login.lua:108: in main chunk
 
Lua Script Error: [Test Interface]
data/creaturescripts/scripts/others/login.lua
data/creaturescripts/scripts/others/login.lua:108: attempt to index global 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/creaturescripts/scripts/others/login.lua:108: in main chunk

post your login.lua
 
Code:
local events = {
    'ElementalSpheresOverlords',
    'BigfootBurdenVersperoth',
    'Razzagorn',
    'Shatterer',
    'Zamulosh',   
    'The Hunger',
    'The Rage',
    'Eradicator',
    'Eradicator1',
    'Rupture',
    'World Devourer',   
    'Tarbaz',
    'Shulgrax',
    'Ragiaz',
    'Plagirath',
    'Mazoran',
    'Destabilized',
    'BigfootBurdenWiggler',
    'SvargrondArenaKill',
    'NewFrontierShardOfCorruption',
    'NewFrontierTirecz',
    'ServiceOfYalaharDiseasedTrio',
    'ServiceOfYalaharAzerus',
    'ServiceOfYalaharQuaraLeaders',
    'InquisitionBosses',
    'InquisitionUngreez',
    'KillingInTheNameOfKills',
    'KillingInTheNameOfKillss',
    'KillingInTheNameOfKillsss',
    'MastersVoiceServants',
    'SecretServiceBlackKnight',
    'ThievesGuildNomad',
    'WotELizardMagistratus',
    'WotELizardNoble',
    'WotEKeeper',
    'Maxxed',
    'WotEBosses',
    'WotEZalamon',
    'WarzoneThree',
    'PlayerDeath',
    'AdvanceSave',
    'bossesWarzone',
    'AdvanceRookgaard',
    'PythiusTheRotten',
    'DropLoot',
    'Yielothax',
    'BossParticipation',
    'Energized Raging Mage',
    'Raging Mage', 
    'modalMD1',
    'VibrantEgg',
    'DeathCounter',
    'KillCounter',
    'bless1',
    'lowerRoshamuul',
    'SpikeTaskQuestCrystal',
    'SpikeTaskQuestDrillworm',
    'petlogin',
    'Idle',
    'bossLloyd1',
    'bossLloyd2',
    'bossLloyd3',
    'AutoLoot',
    'Kroazur',   
    'bossaddonnostalgia',
    'PlayerAddPointsTimer',
    'PlayerResetPointsTimer',   
    'points',
    'Gelidrazah the Frozen',
    'Koshei The Deathless',
    'Zorvorax',   
    'petthink',
    'Kalyassa',
    'Tazhadur',   
    'UpperSpikeKill',
    'MiddleSpikeKill',
    'LowerSpikeKill'

}




local function onMovementRemoveProtection(cid, oldPosition, time)
    local player = Player(cid)
    if not player then
        return true
    end

    local playerPosition = player:getPosition()
    if (playerPosition.x ~= oldPosition.x or playerPosition.y ~= oldPosition.y or playerPosition.z ~= oldPosition.z) or player:getTarget() then
        player:setStorageValue(Storage.combatProtectionStorage, 0)
        return true
    end

    addEvent(onMovementRemoveProtection, 1000, cid, oldPosition, time - 1) 
end

 function Player.sendVipDaysMessage(self)
    if self:isVip() then
        local vipTime = self:getVipTime() - os.time()
        local vipDays = 1 + (math.floor(vipTime / 86400))
        return self:getVipTime() ~= false and self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You have '.. vipDays .. ' vip day(s) in your account.')
    end
end

function onLogin(player)
    local loginStr = 'Welcome to ' .. configManager.getString(configKeys.SERVER_NAME) .. '!'

    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. ' Please choose your outfit.'       
        player:setBankBalance(0)

        if player:getSex() == 1 then
            player:setOutfit({lookType = 128, lookHead = 78, lookBody = 106, lookLegs = 58, lookFeet = 76})       
        else
            player:setOutfit({lookType = 136, lookHead = 78, lookBody = 106, lookLegs = 58, lookFeet = 76})   
        end

        player:sendTutorial(1)
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format('Your last visit was on %s.', os.date('%a %b %d %X %Y', player:getLastLoginSaved()))
    end

    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
   
    local playerId = player:getId()
   
    player:loadSpecialStorage()

    --[[-- Maintenance mode
    if (player:getGroup():getId() < 2) then
        return false
    else
       
    end--]]
   


    if (player:getGroup():getId() >= 4) then
        player:setGhostMode(true)
    end

    -- Stamina
    nextUseStaminaTime[playerId] = 1

    -- EXP Stamina
    nextUseXpStamina[playerId] = 1

    -- Prey Stamina
    nextUseStaminaPrey[playerId+1] = {Time = 1}
    nextUseStaminaPrey[playerId+2] = {Time = 1}
    nextUseStaminaPrey[playerId+3] = {Time = 1}

    -- Prey Data
    if (player:getVocation():getId() ~= 0) then
        local columnUnlocked = getUnlockedColumn(player)
        if (not columnUnlocked) then
            columnUnlocked = 0
        end

        for i = 0, columnUnlocked do
            sendPreyData(player, i)
        end
    end

    if (player:getAccountType() == ACCOUNT_TYPE_TUTOR) then
        local msg = [[:: Regras Tutor ::
            1*>3 Advertências você perde o cargo.
            2*>Sem conversas paralelas com jogadores no Help, se o player começar a ofender, você simplesmente o mute.
            3*>Seja educado com os player no Help e principalmente no Privado, tenta ajudar o máximo possível.
            4*>Sempre logue no seu horário, caso não tiver uma justificativa você será removido da staff.
            5*>Help é somente permitido realizar dúvidas relacionadas ao tibia.
            6*>Não é Permitido divulgar time pra upar ou para ajudar em quest.
            7*>Não é permitido venda de itens no Help.
            8*>Caso o player encontre um bug, peça para ir ao site mandar um ticket e explicar em detalhes.
            9*>Mantenha sempre o Chat dos Tutores aberto. (obrigatório).
            10*>Você terminou de cumprir seu horário, viu que não tem nenhum tutor Online, você comunica com algum CM in-game ou ts e fica no help até alguém logar, se der.
            11*>Mantenha sempre um ótimo português no Help, queremos tutores que dêem suporte, não que fiquem falando um ritual satânico.
            12*>Se ver um tutor fazendo algo que infrinja as regras, tire uma print e envie aos superiores."
            -- Comandos --
            Mutar Player: /mute nick,90. (90 segundos)
            Desmutar Player: /unmute nick.
            -- Comandos --]]
        player:popupFYI(msg)
    end
   
    -- OPEN CHANNERLS (ABRIR CHANNELS)
    if table.contains({"Rookgaard", "Dawnport"}, player:getTown():getName())then
        --player:openChannel(7) -- help channel
        player:openChannel(3) -- world chat
        player:openChannel(6) -- advertsing rook main
    else
        player:openChannel(7) -- help channel
        player:openChannel(3) -- world chat
        player:openChannel(5) -- advertsing main
    end

      --
    -- Rewards
    local rewards = #player:getRewardList()
    if(rewards > 0) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have %d %s in your reward chest.", rewards, rewards > 1 and "rewards" or "reward"))
    end

    -- Update player id
    local stats = player:inBossFight()
    if stats then
        stats.playerId = player:getId()
    end

    -- fury gates
    local messageType = nil
    if (player:getClient().os == 3 or
        player:getClient().os == 5) then
        messageType = MESSAGE_EVENT_ADVANCE
    end

    if Game.getStorageValue(GlobalStorage.FuryGates) == 1 then
        player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, 'Fury Gate is on Venore Today.')
    elseif Game.getStorageValue(GlobalStorage.FuryGates) == 2 then
        player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, 'Fury Gate is on Abdendriel Today.')
    elseif Game.getStorageValue(GlobalStorage.FuryGates) == 3 then
        player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, 'Fury Gate is on Thais Today.')
    elseif Game.getStorageValue(GlobalStorage.FuryGates) == 4 then
        player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, 'Fury Gate is on Carlin Today.')
    elseif Game.getStorageValue(GlobalStorage.FuryGates) == 5 then
        player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, 'Fury Gate is on Edron Today.')
    elseif Game.getStorageValue(GlobalStorage.FuryGates) == 6 then
        player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, 'Fury Gate is on Kazordoon Today.')
    end

    player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, '[BUGS?] Reporte em  nosso forum! Boards >> Bug Report')
    player:sendTextMessage(messageType or MESSAGE_STATUS_CONSOLE_ORANGE, '[Comandos] !aol,!bless,!cast,!promotion,!autoloot,!backpack,!food,!shovel,!pick todos os comandos em nosso site')
   
    -- Events
    for i = 1, #events do
        player:registerEvent(events[i])
    end

 
    if player:getStorageValue(Storage.combatProtectionStorage) <= os.time() then
        player:setStorageValue(Storage.combatProtectionStorage, os.time() + 10)
        onMovementRemoveProtection(playerId, player:getPosition(), 10)
    end

    -- Exp stats
    local staminaMinutes = player:getStamina()
    local Boost = player:getExpBoostStamina()
    if staminaMinutes > 2400 and player:isPremium() and Boost > 0 then
        player:setBaseXpGain(200) -- 200 = 1.0x, 200 = 2.0x, ... premium account       
    elseif staminaMinutes > 2400 and player:isPremium() and Boost <= 0 then
        player:setBaseXpGain(150) -- 150 = 1.0x, 150 = 1.5x, ... premium account   
    elseif staminaMinutes <= 2400 and staminaMinutes > 840 and player:isPremium() and Boost > 0 then
        player:setBaseXpGain(150) -- 150 = 1.5x        premium account
    elseif staminaMinutes > 840 and Boost > 0 then
        player:setBaseXpGain(150) -- 150 = 1.5x        free account
    elseif staminaMinutes <= 840 and Boost > 0 then
        player:setBaseXpGain(100) -- 50 = 0.5x    all players   
    elseif staminaMinutes <= 840 then
        player:setBaseXpGain(50) -- 50 = 0.5x    all players   
    end
    return true
end
 
Are you using the script from this post?
TFS 1.x !vial or !flask talkactions

Also I don't see anywhere in your login.lua where you pasted the code:
Lua:
if player:getStorageValue(50000) == 1 then
    removePlayerVials(player:getId())
end
Hello, I've put it in the middle of the same script, the one I pasted is the original which I pasted the server did not call
 
@leandroluck

Could you paste both the talkaction script you are using and how you implemented it in login.lua?
There's a language barrier and it would be easier to help if I could see how you implemented the code.
 
Back
Top