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

it is possible to create a script for example: !enable mana??

Penthelisea

Member
Joined
Nov 13, 2011
Messages
61
Reaction score
16
Hello Guys, it is possible to create a script for example:

actually i have a tfs 1.2 , when use mana fluid , have a empty flask,, but is possible make a script to use !enable mana , then when you use manas fluids automatic remove flask, and use !disable mana then work normal, mana empty,,, understand? thanks a lot^^
 
Let's see if I understood you..

You are using TFS 1.2.
After using a mana potion you receive an empty potion and you need a command that will automatically remove the empty potions for players who have used !enable mana and if player wants to keep the empty potions again they will disable auto-remove with !disable mana ?
 
Try this. I haven't tested it, let me know if it works.

Note: the command has no exhaustion, idk if there's any exhaustion set by default - otherwise you might wanna add that manually.
( Player.setExhaustion, Player.getExhaustion [TFS 1.0] (https://otland.net/threads/player-setexhaustion-player-getexhaustion-tfs-1-0.224233/#post-2156057) )


data/global.lua
Lua:
POTION_REMOVER_CONFIG = {
    storage = 11224
}

Talkaction
Lua:
-- !removeflask on | off

function onSay(player, words, param)
    if param == 'on' then
        player:setStorageValue(POTION_REMOVER_CONFIG.storage, 1)
    else if param == 'off' then
        player:setStorageValue(POTION_REMOVER_CONFIG.storage, -1)
    end

    return false
end

data/actions/scripts/other/potions.lua
Lua:
local ultimateHealthPot = 8473
local greatHealthPot = 7591
local greatManaPot = 7590
local greatSpiritPot = 8472
local strongHealthPot = 7588
local strongManaPot = 7589
local healthPot = 7618
local manaPot = 7620
local smallHealthPot = 8704
local antidotePot = 8474
local greatEmptyPot = 7635
local strongEmptyPot = 7634
local emptyPot = 7636

local antidote = Combat()
antidote:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
antidote:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
antidote:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
antidote:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
antidote:setParameter(COMBAT_PARAM_DISPEL, CONDITION_POISON)

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, (configManager.getNumber(configKeys.EX_ACTIONS_DELAY_INTERVAL) - 100))
-- 1000 - 100 due to exact condition timing. -100 doesn't hurt us, and players don't have reminding ~50ms exhaustion.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target == nil or not target:isPlayer() then
        return true
    end

    if player:getCondition(CONDITION_EXHAUST_HEAL) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end

    local enableAutoRemove = false
    if player:getStorageValue(POTION_REMOVER_CONFIG.storage) == 1 then
        enableAutoRemove = true
    end

    local itemId = item:getId()
    if itemId == antidotePot then
        if not antidote:execute(target, numberToVariant(target:getId())) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == smallHealthPot then
        if not doTargetCombatHealth(0, target, COMBAT_HEALING, 60, 90, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == healthPot then
        if not doTargetCombatHealth(0, target, COMBAT_HEALING, 125, 175, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == manaPot then
        if not doTargetCombatMana(0, target, 75, 125, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == strongHealthPot then
        if (not isInArray({3, 4, 7, 8}, target:getVocation():getId()) or target:getLevel() < 50) and not getPlayerFlagValue(player, PlayerFlag_IgnoreSpellCheck) then
            player:say("This potion can only be consumed by paladins and knights of level 50 or higher.", TALKTYPE_MONSTER_SAY)
            return true
        end

        if not doTargetCombatHealth(0, target, COMBAT_HEALING, 250, 350, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == strongManaPot then
        if (not isInArray({1, 2, 3, 5, 6, 7}, target:getVocation():getId()) or target:getLevel() < 50) and not getPlayerFlagValue(player, PlayerFlag_IgnoreSpellCheck) then
            player:say("This potion can only be consumed by sorcerers, druids and paladins of level 50 or higher.", TALKTYPE_MONSTER_SAY)
            return true
        end

        if not doTargetCombatMana(0, target, 115, 185, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == greatSpiritPot then
        if (not isInArray({3, 7}, target:getVocation():getId()) or target:getLevel() < 80) and not getPlayerFlagValue(player, PlayerFlag_IgnoreSpellCheck) then
            player:say("This potion can only be consumed by paladins of level 80 or higher.", TALKTYPE_MONSTER_SAY)
            return true
        end

        if not doTargetCombatHealth(0, target, COMBAT_HEALING, 250, 350, CONST_ME_MAGIC_BLUE) or not doTargetCombatMana(0, target, 100, 200, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == greatHealthPot then
        if (not isInArray({4, 8}, target:getVocation():getId()) or target:getLevel() < 80) and not getPlayerFlagValue(player, PlayerFlag_IgnoreSpellCheck) then
            player:say("This potion can only be consumed by knights of level 80 or higher.", TALKTYPE_MONSTER_SAY)
            return true
        end

        if not doTargetCombatHealth(0, target, COMBAT_HEALING, 425, 575, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == greatManaPot then
        if (not isInArray({1,2,5,6}, target:getVocation():getId()) or target:getLevel() < 80) and not getPlayerFlagValue(player, PlayerFlag_IgnoreSpellCheck) then
            player:say("This potion can only be consumed by sorcerers and druids of level 80 or higher.", TALKTYPE_MONSTER_SAY)
            return true
        end

        if not doTargetCombatMana(0, target, 150, 250, CONST_ME_MAGIC_BLUE) then
            return false
        end
        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    elseif itemId == ultimateHealthPot then
        if (not isInArray({4, 8}, target:getVocation():getId()) or target:getLevel() < 130) and not getPlayerFlagValue(player, PlayerFlag_IgnoreSpellCheck) then
            player:say("This potion can only be consumed by knights of level 130 or higher.", TALKTYPE_MONSTER_SAY)
            return true
        end

        if not doTargetCombatHealth(0, target, COMBAT_HEALING, 650, 850, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
        if enableAutoRemove then
            player:addItem(emptyPot, 1)
        end
    end
    return true
end
 
this is me global.lua, where i can add this :
POTION_REMOVER_CONFIG = {
storage = 11224
}



Lua:
dofile('data/lib/lib.lua')

function getDistanceBetween(firstPosition, secondPosition)
    local xDif = math.abs(firstPosition.x - secondPosition.x)
    local yDif = math.abs(firstPosition.y - secondPosition.y)
    local posDif = math.max(xDif, yDif)
    if firstPosition.z ~= secondPosition.z then
        posDif = posDif + 15
    end
    return posDif
end

function getFormattedWorldTime()
    local worldTime = getWorldTime()
    local hours = math.floor(worldTime / 60)

    local minutes = worldTime % 60
    if minutes < 10 then
        minutes = '0' .. minutes
    end
    return hours .. ':' .. minutes
end

string.split = function(str, sep)
    local res = {}
    for v in str:gmatch("([^" .. sep .. "]+)") do
        res[#res + 1] = v
    end
    return res
end

string.trim = function(str)
    return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
end

table.contains = function(array, value)
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end
Post automatically merged:



i no have potions, i have fluids...

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

local poison = Condition(CONDITION_POISON)
poison:addDamage(1, 4000, -0)
poison:addDamage(1, 4000, -10)
poison:addDamage(2, 4000, -9)
poison:addDamage(2, 4000, -8)
poison:addDamage(3, 4000, -7)
poison:addDamage(3, 4000, -6)
poison:addDamage(4, 4000, -5)
poison:addDamage(4, 4000, -4)
poison:addDamage(6, 4000, -3)
poison:addDamage(10, 4000, -2)
poison:addDamage(10, 4000, -1)
poison:addDamage(10, 4000, -1)
poison:addDamage(10, 4000, -1)
poison:addDamage(8, 3950, -1)
poison:addDamage(1, 3940, -1)

local messages = {
    [FLUID_WATER] = "Gulp.",
    [FLUID_WINE] = "Aah...",
    [FLUID_BEER] = "Aah...",
    [FLUID_MUD] = "Gulp.",
    [FLUID_BLOOD] = "Gulp.",
    [FLUID_SLIME] = "Urgh!",
    [FLUID_OIL] = "Gulp.",
    [FLUID_URINE] = "Urgh!",
    [FLUID_MILK] = "Mmmh.",
    [FLUID_MANAFLUID] = "Aaaah...",
    [FLUID_LIFEFLUID] = "Aaaah...",
    [FLUID_LEMONADE] = "Mmmh."
}

function onUse(player, item, fromPosition, target, toPosition)
    local targetItemType = ItemType(target:getId())
    if targetItemType and targetItemType:isFluidContainer() then
            if target:getFluidType() == 0 and item:getFluidType() ~= 0 then
            target:transform(target:getId(), item:getFluidType())
            item:transform(item:getId(), 0)
            return true
        elseif item:getFluidType() == 0 and target:getFluidType() ~= 0 then
            return false
        elseif target:getFluidType() ~= 0 and item:getFluidType() == 0 then
            target:transform(target:getId(), 0)
            item:transform(item:getId(), target:getFluidType())
            return true
        end
    end
 
    if target:isCreature() and target == player then
        if item:getFluidType() == FLUID_NONE then
            player:sendCancelMessage("It is empty.")
        else
            local self = target == player
            if self and item:getFluidType() == FLUID_BEER or item:getFluidType() == FLUID_WINE then
                player:addCondition(drunk)
            elseif self and item:getFluidType() == FLUID_SLIME then
                player:addCondition(poison)
            elseif item:getFluidType() == FLUID_MANAFLUID then
                target:addMana(math.random(25, 75))
                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            elseif item:getFluidType() == FLUID_LIFEFLUID then
                target:addHealth(math.random(40, 50))
                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
         
            if not self then
                if item:getFluidType() ~= FLUID_MANAFLUID and item:getFluidType() ~= FLUID_LIFEFLUID then
                    if toPosition.x == CONTAINER_POSITION then
                        toPosition = player:getPosition()
                    end
                    Game.createItem(2886, item:getFluidType(), toPosition):decay()
                    return true
                end
            end
         
            local message = messages[item:getFluidType()]
            if message then
                target:say(message, TALKTYPE_SAY)
            else
                target:say("Gulp.", TALKTYPE_SAY)
            end
            item:transform(item:getId(), FLUID_NONE)
        end
    else
        if toPosition.x == CONTAINER_POSITION then
            toPosition = player:getPosition()
        end
     
        local tile = Tile(toPosition)
        if not tile then
            return false
        end
     
        if item:getFluidType() ~= FLUID_NONE and tile:hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
            return false
        end
     
        local fluidSource = targetItemType and targetItemType:getFluidSource() or FLUID_NONE
        if fluidSource ~= FLUID_NONE then
            item:transform(item:getId(), fluidSource)
        elseif item:getFluidType() == FLUID_NONE then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
        else

            Game.createItem(2886, item.type, toPosition):decay()
                item:transform(item:getId(), FLUID_NONE)
        end
    end
    return true
end
 
Last edited:
this is me global.lua, where i can add this :
POTION_REMOVER_CONFIG = {
storage = 11224
}



dofile('data/lib/lib.lua')

function getDistanceBetween(firstPosition, secondPosition)
local xDif = math.abs(firstPosition.x - secondPosition.x)
local yDif = math.abs(firstPosition.y - secondPosition.y)
local posDif = math.max(xDif, yDif)
if firstPosition.z ~= secondPosition.z then
posDif = posDif + 15
end
return posDif
end

function getFormattedWorldTime()
local worldTime = getWorldTime()
local hours = math.floor(worldTime / 60)

local minutes = worldTime % 60
if minutes < 10 then
minutes = '0' .. minutes
end
return hours .. ':' .. minutes
end

string.split = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
res[#res + 1] = v
end
return res
end

string.trim = function(str)
return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
end

table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then
return true
end
end
return false
end
Post automatically merged:

i no have potions, i have fluids...

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

local poison = Condition(CONDITION_POISON)
poison:addDamage(1, 4000, -0)
poison:addDamage(1, 4000, -10)
poison:addDamage(2, 4000, -9)
poison:addDamage(2, 4000, -8)
poison:addDamage(3, 4000, -7)
poison:addDamage(3, 4000, -6)
poison:addDamage(4, 4000, -5)
poison:addDamage(4, 4000, -4)
poison:addDamage(6, 4000, -3)
poison:addDamage(10, 4000, -2)
poison:addDamage(10, 4000, -1)
poison:addDamage(10, 4000, -1)
poison:addDamage(10, 4000, -1)
poison:addDamage(8, 3950, -1)
poison:addDamage(1, 3940, -1)

local messages = {
[FLUID_WATER] = "Gulp.",
[FLUID_WINE] = "Aah...",
[FLUID_BEER] = "Aah...",
[FLUID_MUD] = "Gulp.",
[FLUID_BLOOD] = "Gulp.",
[FLUID_SLIME] = "Urgh!",
[FLUID_OIL] = "Gulp.",
[FLUID_URINE] = "Urgh!",
[FLUID_MILK] = "Mmmh.",
[FLUID_MANAFLUID] = "Aaaah...",
[FLUID_LIFEFLUID] = "Aaaah...",
[FLUID_LEMONADE] = "Mmmh."
}

function onUse(player, item, fromPosition, target, toPosition)
local targetItemType = ItemType(target:getId())
if targetItemType and targetItemType:isFluidContainer() then
if target:getFluidType() == 0 and item:getFluidType() ~= 0 then
target:transform(target:getId(), item:getFluidType())
item:transform(item:getId(), 0)
return true
elseif item:getFluidType() == 0 and target:getFluidType() ~= 0 then
return false
elseif target:getFluidType() ~= 0 and item:getFluidType() == 0 then
target:transform(target:getId(), 0)
item:transform(item:getId(), target:getFluidType())
return true
end
end

if target:isCreature() and target == player then
if item:getFluidType() == FLUID_NONE then
player:sendCancelMessage("It is empty.")
else
local self = target == player
if self and item:getFluidType() == FLUID_BEER or item:getFluidType() == FLUID_WINE then
player:addCondition(drunk)
elseif self and item:getFluidType() == FLUID_SLIME then
player:addCondition(poison)
elseif item:getFluidType() == FLUID_MANAFLUID then
target:addMana(math.random(25, 75))
target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
elseif item:getFluidType() == FLUID_LIFEFLUID then
target:addHealth(math.random(40, 50))
target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
end

if not self then
if item:getFluidType() ~= FLUID_MANAFLUID and item:getFluidType() ~= FLUID_LIFEFLUID then
if toPosition.x == CONTAINER_POSITION then
toPosition = player:getPosition()
end
Game.createItem(2886, item:getFluidType(), toPosition):decay()
return true
end
end

local message = messages[item:getFluidType()]
if message then
target:say(message, TALKTYPE_SAY)
else
target:say("Gulp.", TALKTYPE_SAY)
end
item:transform(item:getId(), FLUID_NONE)
end
else
if toPosition.x == CONTAINER_POSITION then
toPosition = player:getPosition()
end

local tile = Tile(toPosition)
if not tile then
return false
end

if item:getFluidType() ~= FLUID_NONE and tile:hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
return false
end

local fluidSource = targetItemType and targetItemType:getFluidSource() or FLUID_NONE
if fluidSource ~= FLUID_NONE then
item:transform(item:getId(), fluidSource)
elseif item:getFluidType() == FLUID_NONE then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
else

Game.createItem(2886, item.type, toPosition):decay()
item:transform(item:getId(), FLUID_NONE)
end
end
return true
end

Please post the code properly, or when people copy your script, there may be errors due to formatting rules.
 
Back
Top