• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Potion script that heals based on your max hp/mana and magic level

Samaster

Raptorserver.ddns.net
Joined
Jun 9, 2013
Messages
291
Reaction score
23
Location
UK
Fellow OTlanders, with the help of Limos I have produced a working script for 1.0 that I couldn't find when I needed it and so am uploading it now.. go into Potions.lua which located in actions/scripts/liquids/potions.lua and replace what you have with this and should work..

If you don't want unlimited pots, just change (removeOnUse = "no",) to "yes"; but make sure your config also says removeOnUse = 1

This is fixed to my server, if you want to change the rates; change {6, 9}} to something like {16, 19}}.

You can also change the rates by editing the numbers on:

[[if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(manamax * (mana[1]/100) * 0.004, manamax * (mana[2]/100) * 0.004) * config.manaMultiplier * (mlevel * 0.5) + level))) then
return false]]

to larger or smaller depending on your server rates etc



Code:
local config = {
  removeOnUse = "no",
  usableOnTarget = "yes", -- can be used on target? (fe. healing friend)
  splashable = "no",
  realAnimation = "no", -- make text effect visible only for players in range 1x1
  healthMultiplier = 1.0,
  manaMultiplier = 1.0
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.usableOnTarget = getBooleanFromString(config.usableOnTarget)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
  [8704] = {empty = 7636, splash = 2, health = {3, 5}}, -- small health potion
  [7618] = {empty = 7636, splash = 2, health = {6, 9}}, -- health potion
  [7588] = {empty = 7634, splash = 2, health = {10, 13}, level = 50, vocations = {3, 4, 7, 8, 12}, vocStr = "knights and paladins"}, -- strong health potion
  [7591] = {empty = 7635, splash = 2, health = {14, 17}, level = 80, vocations = {4, 8, 12}, vocStr = "knights"}, -- great health potion
  [8473] = {empty = 7635, splash = 2, health = {19, 21}, level = 150, vocations = {4, 8, 12}, vocStr = "knights"}, -- ultimate health potion

  [7620] = {empty = 7636, splash = 7, mana = {4, 6}}, -- mana potion
  [7589] = {empty = 7634, splash = 7, mana = {8, 11}, level = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
  [7590] = {empty = 7635, splash = 7, mana = {12, 15}, level = 80, vocations = {1, 2, 5, 6, 9, 10}, vocStr = "sorcerers and druids"}, -- great mana potion

  [8472] = {empty = 7635, splash = 3, health = {13, 16}, mana = {9, 12}, level = 100, vocations = {3, 7, 11}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
  local potion = POTIONS[item.itemid]
  if(not potion) then
    return false
  end

  if(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) then
    if(not config.splashable) then
      return false
    end

    if(toPosition.x == CONTAINER_POSITION) then
      toPosition = getThingPos(item.uid)
    end
    end

  if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
    doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
    return true
  end

  if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
    doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
    return true
  end

  local health = potion.health
  local healthmax = getCreatureMaxHealth(cid)
  local mlevel = getPlayerMagLevel(cid)
  local level = getPlayerLevel(cid)
  if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(healthmax * (health[1]/100) * 0.01, healthmax * (health[2]/100) * 0.01) * config.healthMultiplier * (mlevel * 0.5) + level))) then
    return false
  end

  local mana = potion.mana
  local manamax = getPlayerMaxMana(cid)
  local mlevel = getPlayerMagLevel(cid)
  local level = getPlayerLevel(cid)
  if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(manamax * (mana[1]/100) * 0.004, manamax * (mana[2]/100) * 0.004) * config.manaMultiplier * (mlevel * 0.5) + level))) then
    return false
  end

  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
  if(not realAnimation) then
    doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
  else
    for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
      if(isPlayer(tid)) then
        doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
      end
    end
  end

  doAddCondition(cid, exhaust)
  if(not potion.empty or config.removeOnUse) then
    return true
  end
  if(fromPosition.x == CONTAINER_POSITION) then
  else  
  end
  return true
end



I hope this is useful! :)
 
Last edited:
Why is my 1.0 saying "getBooleanFromString" is a nil value? As if it's not recognized.
 
postjpg_whpnqrx.jpg
 
Code:
function getBooleanFromString(input)
     local tmp = type(input)
     if tmp == 'boolean' then
         return input
     end

     if(tmp == 'number') then
         return input > 0
     end

     local str = string.lower(tostring(input))
     return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
end
 
Code:
function getBooleanFromString(input)
     local tmp = type(input)
     if tmp == 'boolean' then
         return input
     end

     if(tmp == 'number') then
         return input > 0
     end

     local str = string.lower(tostring(input))
     return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
end
Where to paste this script?
 
This is awesome!

Amazing use of table. It will need a few changes to make it compatible with 1.1, very small and simple :D
 
It seems the removeOnUse is not functioning properly. Changed the config to yes and it doesn't remove anything.

EDIT: Vocation restriction is working properly
 
Last edited:
All you have to do is add this line

Code:
  Item(item.uid):remove(1)

just above

Code:
doAddCondition(cid, exhaust)

And it works perfectly I believe. I haven't found any problems with that added yet. Although I am very uncertain as to why once that is added in it automatically takes the health out of the stack of potions from one vial and adds that one empty vial to the player. I have no clue as to why, I tried using transform it turns the whole stack into empty vials, I tried removing one and adding in the correct empty vial manually with player:addItem(potion.empty) but I couldn't do it like that, but once I removed that and just left the line for removing one item it worked perfectly...
 
Fellow OTlanders, with the help of Limos I have produced a working script for 1.0 that I couldn't find when I needed it and so am uploading it now.. go into Potions.lua which located in actions/scripts/liquids/potions.lua and replace what you have with this and should work..

If you don't want unlimited pots, just change (removeOnUse = "no",) to "yes"; but make sure your config also says removeOnUse = 1

This is fixed to my server, if you want to change the rates; change {6, 9}} to something like {16, 19}}.

You can also change the rates by editing the numbers on:

[[if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(manamax * (mana[1]/100) * 0.004, manamax * (mana[2]/100) * 0.004) * config.manaMultiplier * (mlevel * 0.5) + level))) then
return false]]

to larger or smaller depending on your server rates etc



Code:
local config = {
  removeOnUse = "no",
  usableOnTarget = "yes", -- can be used on target? (fe. healing friend)
  splashable = "no",
  realAnimation = "no", -- make text effect visible only for players in range 1x1
  healthMultiplier = 1.0,
  manaMultiplier = 1.0
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.usableOnTarget = getBooleanFromString(config.usableOnTarget)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
  [8704] = {empty = 7636, splash = 2, health = {3, 5}}, -- small health potion
  [7618] = {empty = 7636, splash = 2, health = {6, 9}}, -- health potion
  [7588] = {empty = 7634, splash = 2, health = {10, 13}, level = 50, vocations = {3, 4, 7, 8, 12}, vocStr = "knights and paladins"}, -- strong health potion
  [7591] = {empty = 7635, splash = 2, health = {14, 17}, level = 80, vocations = {4, 8, 12}, vocStr = "knights"}, -- great health potion
  [8473] = {empty = 7635, splash = 2, health = {19, 21}, level = 150, vocations = {4, 8, 12}, vocStr = "knights"}, -- ultimate health potion

  [7620] = {empty = 7636, splash = 7, mana = {4, 6}}, -- mana potion
  [7589] = {empty = 7634, splash = 7, mana = {8, 11}, level = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
  [7590] = {empty = 7635, splash = 7, mana = {12, 15}, level = 80, vocations = {1, 2, 5, 6, 9, 10}, vocStr = "sorcerers and druids"}, -- great mana potion

  [8472] = {empty = 7635, splash = 3, health = {13, 16}, mana = {9, 12}, level = 100, vocations = {3, 7, 11}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
  local potion = POTIONS[item.itemid]
  if(not potion) then
    return false
  end

  if(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) then
    if(not config.splashable) then
      return false
    end

    if(toPosition.x == CONTAINER_POSITION) then
      toPosition = getThingPos(item.uid)
    end
    end

  if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
    doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
    return true
  end

  if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
    doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
    return true
  end

  local health = potion.health
  local healthmax = getCreatureMaxHealth(cid)
  local mlevel = getPlayerMagLevel(cid)
  local level = getPlayerLevel(cid)
  if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(healthmax * (health[1]/100) * 0.01, healthmax * (health[2]/100) * 0.01) * config.healthMultiplier * (mlevel * 0.5) + level))) then
    return false
  end

  local mana = potion.mana
  local manamax = getPlayerMaxMana(cid)
  local mlevel = getPlayerMagLevel(cid)
  local level = getPlayerLevel(cid)
  if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(manamax * (mana[1]/100) * 0.004, manamax * (mana[2]/100) * 0.004) * config.manaMultiplier * (mlevel * 0.5) + level))) then
    return false
  end

  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
  if(not realAnimation) then
    doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
  else
    for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
      if(isPlayer(tid)) then
        doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
      end
    end
  end

  doAddCondition(cid, exhaust)
  if(not potion.empty or config.removeOnUse) then
    return true
  end
  if(fromPosition.x == CONTAINER_POSITION) then
  else 
  end
  return true
end



I hope this is useful! :)
its perfect but i need normal mana potion/strong MP heal with 200 only not like great mana potions same thing with health :S cuz all healing with same heal
 
This is a potion.lua I used for my evo server back in the days it works with tfs 0.4 (tibia 8.6) Great mana potion, great health potion and great spirit potion heals based on your lvl and your magic lvl but smp (strong mana potion) heals 250-350 all the time no matter the lvl and mana potion heals 80-110 no matter the lvl or magic lvl and same with the health potion.
Code:
local config = {
        removeOnUse = "no",
        usableOnTarget = "yes", -- can be used on target? (fe. healing friend)
        splashable = "no",
        range = -1,
        realAnimation = "no", -- make text effect visible only for players in range 1x1
        multiplier = {
                health = 1.0,
                mana = 1.0
        }
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.usableOnTarget = getBooleanFromString(config.usableOnTarget)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
        [7618] = {empty = 7618, splash = 2, health = {100, 200}}, -- health potion
        [7620] = {empty = 7620, splash = 7, mana = {70, 100}}, -- mana potion
        [7589] = {empty = 7589, splash = 7, mana = {200, 350}, level = 50, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
        [7588] = {empty = 7588, splash = 2, health = {250, 350}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion
    [7591] = {vocations = {4, 8}, vocStr = 'knights', -- great health potion
        minhp = 'level * 2.2 + maglv * 3.3',
        maxhp = 'level * 2.75 + maglv * 4.4'},

    [7590] = {vocations = {1, 2, 5, 6}, vocStr = 'sorcerers and druids', -- great mana potion
        minmana = 'level * 1.4 + maglv * 3',
        maxmana = 'level * 1.5 + maglv * 4'},

    [8472] = {vocations = {3, 7}, vocStr = 'paladins', -- great spirit potion
        minhp = 'level * 1.3 + maglv * 2.5',
        maxhp = 'level * 1.6 + maglv * 3.5',
        minmana = 'level * 1.1 + maglv * 2.2',
        maxmana = 'level * 1.5 + maglv * 2.8'}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local potion = POTIONS[item.itemid]
        if(not potion) then
                return false
        end

        if(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) then
                if(not config.splashable) then
                        return false
                end

                if(toPosition.x == CONTAINER_POSITION) then
                        toPosition = getThingPosition(item.uid)
                end

                doDecayItem(doCreateItem(POOL, potion.splash, toPosition))
                doRemoveItem(item.uid, 1)
                if(not potion.empty or config.removeOnUse) then
                        return true
                end

                if(fromPosition.x ~= CONTAINER_POSITION) then
                        doCreateItem(potion.empty, fromPosition)
                else
                        doPlayerAddItem(cid, potion.empty, 1)
                end

                return true
        end

        if(hasCondition(cid, CONDITION_EXHAUST)) then
                doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
                return true
        end

        if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
                not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES))
        then
                doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
                return true
        end

        if(config.range > 0 and cid ~= itemEx.uid and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(itemEx.uid)) > config.range) then
                return false
        end

        local health = potion.health
        if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.multiplier.health))) then
                return false
        end

        local mana = potion.mana
        if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.multiplier.mana))) then
                return false
        end

        doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_MAGIC_BLUE)
        if(not config.realAnimation) then
                doCreatureSay(itemEx.uid, "Mmmmh...", TALKTYPE_ORANGE_1)
        else
                for i, tid in ipairs(getSpectators(getThingPosition(itemEx.uid), 1, 1)) do
                        if(isPlayer(tid)) then
                                doCreatureSay(itemEx.uid, "Mmmmh...", TALKTYPE_ORANGE_1, false, tid)
                        end
                end
        end

        doAddCondition(cid, exhaust)
        doRemoveItem(item.uid, 0)
        if(not potion.empty or config.removeOnUse) then
                return true
        end

        if(fromPosition.x ~= CONTAINER_POSITION) then
                doCreateItem(potion.empty, fromPosition)
        else
                doPlayerAddItem(cid, potion.empty, 0)
        end

        return true
end
 
This is a potion.lua I used for my evo server back in the days it works with tfs 0.4 (tibia 8.6) Great mana potion, great health potion and great spirit potion heals based on your lvl and your magic lvl but smp (strong mana potion) heals 250-350 all the time no matter the lvl and mana potion heals 80-110 no matter the lvl or magic lvl and same with the health potion.
Code:
local config = {
        removeOnUse = "no",
        usableOnTarget = "yes", -- can be used on target? (fe. healing friend)
        splashable = "no",
        range = -1,
        realAnimation = "no", -- make text effect visible only for players in range 1x1
        multiplier = {
                health = 1.0,
                mana = 1.0
        }
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.usableOnTarget = getBooleanFromString(config.usableOnTarget)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
        [7618] = {empty = 7618, splash = 2, health = {100, 200}}, -- health potion
        [7620] = {empty = 7620, splash = 7, mana = {70, 100}}, -- mana potion
        [7589] = {empty = 7589, splash = 7, mana = {200, 350}, level = 50, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
        [7588] = {empty = 7588, splash = 2, health = {250, 350}, level = 50, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion
    [7591] = {vocations = {4, 8}, vocStr = 'knights', -- great health potion
        minhp = 'level * 2.2 + maglv * 3.3',
        maxhp = 'level * 2.75 + maglv * 4.4'},

    [7590] = {vocations = {1, 2, 5, 6}, vocStr = 'sorcerers and druids', -- great mana potion
        minmana = 'level * 1.4 + maglv * 3',
        maxmana = 'level * 1.5 + maglv * 4'},

    [8472] = {vocations = {3, 7}, vocStr = 'paladins', -- great spirit potion
        minhp = 'level * 1.3 + maglv * 2.5',
        maxhp = 'level * 1.6 + maglv * 3.5',
        minmana = 'level * 1.1 + maglv * 2.2',
        maxmana = 'level * 1.5 + maglv * 2.8'}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local potion = POTIONS[item.itemid]
        if(not potion) then
                return false
        end

        if(not isPlayer(itemEx.uid) or (not config.usableOnTarget and cid ~= itemEx.uid)) then
                if(not config.splashable) then
                        return false
                end

                if(toPosition.x == CONTAINER_POSITION) then
                        toPosition = getThingPosition(item.uid)
                end

                doDecayItem(doCreateItem(POOL, potion.splash, toPosition))
                doRemoveItem(item.uid, 1)
                if(not potion.empty or config.removeOnUse) then
                        return true
                end

                if(fromPosition.x ~= CONTAINER_POSITION) then
                        doCreateItem(potion.empty, fromPosition)
                else
                        doPlayerAddItem(cid, potion.empty, 1)
                end

                return true
        end

        if(hasCondition(cid, CONDITION_EXHAUST)) then
                doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
                return true
        end

        if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
                not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES))
        then
                doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
                return true
        end

        if(config.range > 0 and cid ~= itemEx.uid and getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(itemEx.uid)) > config.range) then
                return false
        end

        local health = potion.health
        if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.multiplier.health))) then
                return false
        end

        local mana = potion.mana
        if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.multiplier.mana))) then
                return false
        end

        doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_MAGIC_BLUE)
        if(not config.realAnimation) then
                doCreatureSay(itemEx.uid, "Mmmmh...", TALKTYPE_ORANGE_1)
        else
                for i, tid in ipairs(getSpectators(getThingPosition(itemEx.uid), 1, 1)) do
                        if(isPlayer(tid)) then
                                doCreatureSay(itemEx.uid, "Mmmmh...", TALKTYPE_ORANGE_1, false, tid)
                        end
                end
        end

        doAddCondition(cid, exhaust)
        doRemoveItem(item.uid, 0)
        if(not potion.empty or config.removeOnUse) then
                return true
        end

        if(fromPosition.x ~= CONTAINER_POSITION) then
                doCreateItem(potion.empty, fromPosition)
        else
                doPlayerAddItem(cid, potion.empty, 0)
        end

        return true
end
SMp/GMP/HP
Doesn't Work :D
 
Back
Top