• 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+ How much mana/health gain on potion heal.

Raber

New Member
Joined
Feb 6, 2011
Messages
30
Reaction score
2
Wondering if there's any way to show how much mana/health gain is made when a potion is used. This would be replacing the "Aaaaah..." which it normally casts.

here's the code that I use:

Lua:
local config = {
lvl = 1, -- the multiplier for how much level matters. Default 1.
mlvl = 2, -- the mulitplier for how much mlvl matters. Default 1.
forMin = 0.9, -- forumula multiplier for MIN/max range. Default 0.9 == 90%          --Change both to 1.0 for amount healed to have no min/max
forMax = 1.1, -- forumula multiplier for min/MAX range. Default 0.9 == 110%          --Change both to 1.0 for amount healed to have no min/max
removeOnUse = false, -- Does this remove 1 potion after it's use? true/false          -- Default true.
useOnSummons = true, -- Can you use this on a players summon? true/false              -- Default true.
useOnGuildSummon = true, -- Can you use this on guild mate's summon? true/false      -- Default true.
useOnPartySummon = true, -- Can you use this on a party members summon? true/false      -- Default true.
realPvpMode = false, -- True = Players can't use potions for hotkeys || False = Players are allowed to use potions for hotkeys.
exhaust = Condition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD), --Condition for each specific potion.Adjust time in potions table below.
cooldown =  Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_HEAD) -- Condition for creating "groups" of potions with same cooldown time, eg. all mana potions.
}
local POTIONS = {
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [8704] = {empty = 7636, spellid = 1, splash = 2, exhaust = 500, health = true, mana = false, healthpercent = 2},                                                                         -- small health potion
  [7618] = {empty = 7636, spellid = 1, splash = 2, exhaust = 500, health = true, mana = false, healthpercent = 3},                                                                        -- health potion
  [7588] = {empty = 7634, spellid = 2, splash = 2, exhaust = 500, health = true, mana = false, healthpercent = 4, lvlReq = 50, vocations = {3, 4, 7, 8, 9, 10}},                            -- strong health potion
  [7591] = {empty = 7635, spellid = 2, splash = 2, exhaust = 500, health = true, mana = false, healthpercent = 5, lvlReq = 80, vocations = {4, 8, 9}},                                     -- great health potion
  [8473] = {empty = 7635, spellid = 2, splash = 2, exhaust = 500, health = true, mana = false, healthpercent = 6, lvlReq = 130, vocations = {4, 8, 9}},                                     -- ultimate health potion
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [7620] = {empty = 7636, spellid = 3, splash = 7, exhaust = 500, health = false, mana = true, manapercent = 2},                                                                             -- mana potion
  [7589] = {empty = 7634, spellid = 3, splash = 7, exhaust = 500, health = false, mana = true, manapercent = 3, lvlReq = 50, vocations = {1, 2, 3, 5, 6, 7, 10, 11, 12}},                    -- strong mana potion
  [7590] = {empty = 7635, spellid = 3, splash = 7, exhaust = 500, health = false, mana = true, manapercent = 4, lvlReq = 80, vocations = {1, 2, 5, 6, 11, 12}},                             -- great mana potion
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [8472] = {empty = 7635, spellid = 2, splash = 3, exhaust = 500, health = true,  mana = true, healthpercent = 5, manapercent = 3, lvlReq = 80, vocations = {3, 7, 10}}                     -- great spirit potion
}
------Below for Advanced Users Only----------
function Player:isCreatureFriend(creature)
    local PID
    local GID
      if self:getParty() then
        PID = self:getParty():getId()
      end
      if self:getGuild() then
        GID = self:getGuild():getId()
    end
    if creature:isPlayer() then
        if creature:getParty() then
            if creature:getParty():getId() == PID then
                return true
            end
        end
        if creature:getGuild() then
            if creature:getGuild():getId() == GID then
                  return true
            end
        end
        return false
    end
    if creature:isMonster() then
    local master = creature:getMaster()
        if master then
            if master:getId() == self:getId() then
                return true
            end
            if master:getParty() and master:getParty():getId() == PID then
                return true
            end
            if master:getGuild() and master:getGuild():getId() == GID then
                return true
            end
            return false
        end
    end
end

function onUse(caster, item, castPos, target, toPosition, isHotkey)
local potion = POTIONS[item.itemid]
local health = potion.health
local mana = potion.mana
local hpPercent = potion.healthpercent
local mpPercent = potion.manapercent
local exhaust = config.exhaust
local cooldown = config.cooldown
local mlevel = caster:getMagicLevel()
local level = caster:getLevel()
    if(not potion) then
        return false
    end
    if isHotkey and config.realPvpMode == true then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Hotkey use is disabled for potions!")
    end
    if toPosition.z == 0 or nil then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end
    if toPosition.x == 65535 or nil then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end

    if target:isItem() then
        if (not target:hasProperty()) then
            Item(doCreateItem(2016, potion.splash, toPosition)):decay()
                if config.removeOnUse and not caster:getGroup():getAccess() then
                    Item(item.uid):remove(1)
                end
            return true
        end
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end
    local healthmax = target:getMaxHealth()
    local manamax = target:getMaxMana()
    if caster:getCondition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD, potion.spellid) then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED)
    end
    if (potion.vocations) and  (not caster:getGroup():getAccess()) then
        if (not isInArray(potion.vocations, caster:getVocation():getId())) then
            caster:getPosition():sendMagicEffect(CONST_ME_POFF)
            return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Your vocation may not use this fluid")
        end
    end
    if((potion.lvlReq and caster:getLevel() < potion.lvlReq) and not caster:getGroup():getAccess()) then 
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Only players of " ..potion.level.. " or above may use this fluid.")
    end
    if target:isPlayer() then
        if health == true then
            target:addHealth(( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax))))
        end
        if mana == true then
            target:addMana(( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax))))
        end
    end
    if target:isMonster() then
    local monsterMaster = target:getMaster()
        if caster:isCreatureFriend(target) then
            if config.useOnSummons == true then
                if health then
                    target:addHealth(( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax))))
                else
                    caster:getPosition():sendMagicEffect(CONST_ME_POFF)
                    return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"Summons don't use mana!")
                end
            else
                caster:getPosition():sendMagicEffect(CONST_ME_POFF)
                return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on summons!")
            end
        else
            caster:getPosition():sendMagicEffect(CONST_ME_POFF)
            return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
        end
    end       
    if target:isNpc() then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
    end
    if config.removeOnUse and not caster:getGroup():getAccess() then
        Item(item.uid):remove(1)
    end
    exhaust:setParameter(CONDITION_PARAM_TICKS, potion.exhaust)
    exhaust:setParameter(CONDITION_PARAM_SUBID, potion.spellid)
    caster:addCondition(cooldown)
    caster:addCondition(exhaust)
    target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
  return true
end
 
Solution
Sorry, but I don't understand how this helps me. I know how to change how much a potion will heal. But what I need is to show how much it healed, this should be above the character in-game.

Guessing this has to be changed:

Lua:
 target:say("Aaaah...", TALKTYPE_MONSTER_SAY)

But not sure to what.

Try
Lua:
if health == true then
    target:say("+" .. ( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax))), TALKTYPE_MONSTER_SAY)
end
if mana == true then
    target:say("+" ..( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl...
There's a formula.

Lua:
if health == true then
    target:addHealth(( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax))))
end
if mana == true then
    target:addMana(( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax))))
end

You may change this:

Code:
lvl = 1, -- the multiplier for how much level matters. Default 1.
mlvl = 2, -- the mulitplier for how much mlvl matters. Default 1.
forMin = 0.9, -- forumula multiplier for MIN/max range. Default 0.9 == 90%          --Change both to 1.0 for amount healed to have no min/max
forMax = 1.1, -- forumula multiplier for min/MAX range. Default 0.9 == 110%          --Change both to 1.0 for amount healed to have no min/max

and
Code:
healthpercent =
manapercent =

in
Code:
local POTIONS

Text:
Lua:
target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
 
Last edited:
There's a formula.
Read the script config
Lua:
local config = {
lvl = 1, -- the multiplier for how much level matters. Default 1.
mlvl = 2, -- the mulitplier for how much mlvl matters. Default 1.
forMin = 0.9, -- forumula multiplier for MIN/max range. Default 0.9 == 90%          --Change both to 1.0 for amount healed to have no min/max
forMax = 1.1, -- forumula multiplier for min/MAX range. Default 0.9 == 110%          --Change both to 1.0 for amount healed to have no min/max
removeOnUse = false, -- Does this remove 1 potion after it's use? true/false          -- Default true.
useOnSummons = true, -- Can you use this on a players summon? true/false              -- Default true.
useOnGuildSummon = true, -- Can you use this on guild mate's summon? true/false      -- Default true.
useOnPartySummon = true, -- Can you use this on a party members summon? true/false      -- Default true.
realPvpMode = false, -- True = Players can't use potions for hotkeys || False = Players are allowed to use potions for hotkeys.
exhaust = Condition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD), --Condition for each specific potion.Adjust time in potions table below.
cooldown =  Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_HEAD) -- Condition for creating "groups" of potions with same cooldown time, eg. all mana potions.
}

What formula? I want to change the output from "Aaaah..." when a potion is used, to make it show how much it healed.

Example: "+1234" instead of "Aaaah..."
 
I edited my last posting

Sorry, but I don't understand how this helps me. I know how to change how much a potion will heal. But what I need is to show how much it healed, this should be above the character in-game.

Guessing this has to be changed:

Lua:
 target:say("Aaaah...", TALKTYPE_MONSTER_SAY)

But not sure to what.
 
Sorry, but I don't understand how this helps me. I know how to change how much a potion will heal. But what I need is to show how much it healed, this should be above the character in-game.

Guessing this has to be changed:

Lua:
 target:say("Aaaah...", TALKTYPE_MONSTER_SAY)

But not sure to what.

Try
Lua:
if health == true then
    target:say("+" .. ( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax))), TALKTYPE_MONSTER_SAY)
end
if mana == true then
    target:say("+" ..( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax))), TALKTYPE_MONSTER_SAY)
end
 
Solution
Try
Lua:
if health == true then
    target:say("+" .. ( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax))), TALKTYPE_MONSTER_SAY)
end
if mana == true then
    target:say("+" ..( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax))), TALKTYPE_MONSTER_SAY)
end

Thanks dude! Added .."" after the formula and it worked!

Like this:

Lua:
 target:say("+"..(( math.random((((level)*config.lvl ) + ((mlevel)*config.mlvl ))*config.forMin, ((((level)*config.lvl )+ ((mlevel))*config.mlvl )*config.forMax)))).."", TALKTYPE_MONSTER_SAY)

*changed the formula some for more balance*
 
Thanks dude! Added .."" after the formula and it worked!

Like this:

Lua:
 target:say("+"..(( math.random((((level)*config.lvl ) + ((mlevel)*config.mlvl ))*config.forMin, ((((level)*config.lvl )+ ((mlevel))*config.mlvl )*config.forMax)))).."", TALKTYPE_MONSTER_SAY)

*changed the formula some for more balance*
Nice!
Now mark the post with answered ^^
 
Nice!
Now mark the post with answered ^^

Yeah it's nice, one detail tho. The problem with that formula is that it shows a random amount, not the actual heal.

Example: I heal for 550 mana (actual heal) and it shows a random amount between the min and max in the formula, this since we use math.random.

Is there any way for it to calculate what was healed and then show the correct amount?
 
Make a variable to hold it, calculate it once, pass it to the relevant callback functions to output text. It'll clean up your code and make it more readable if your equation is outside the if, and is only done once. It can then be used. As it stands you are generating different random numbers for healing and textual output.
 
Make a variable to hold it, calculate it once, pass it to the relevant callback functions to output text. It'll clean up your code and make it more readable if your equation is outside the if, and is only done once. It can then be used. As it stands you are generating different random numbers for healing and textual output.
Idk how to do this, can you explain?
 
For instance:
Lua:
local healthToAdd = ( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax)))

if health == true then
    target:addHealth(healthToAdd)
end

local manaToAdd = ( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax)))

if mana == true then
    target:addMana(manaToAdd)
end

Then you can reuse healthToAdd and manaToAdd to output the text, such that your health/mana increase is consistent with the value displayed in the textual effects.
 
For instance:
Lua:
local healthToAdd = ( math.random((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl ) + ((mlevel/18)*config.mlvl ))*config.forMin, ((((healthmax/100)*hpPercent ) + ((level/12)*config.lvl )+ ((mlevel/18))*config.mlvl )*config.forMax)))

if health == true then
    target:addHealth(healthToAdd)
end

local manaToAdd = ( math.random((((manamax/100)*mpPercent ) + ((level/18)*config.lvl ) + ((mlevel/12)*config.mlvl ))*config.forMin, ((((manamax/100)*mpPercent ) + ((level/18)*config.lvl )+ ((mlevel/12))*config.mlvl )*config.forMax)))

if mana == true then
    target:addMana(manaToAdd)
end

Then you can reuse healthToAdd and manaToAdd to output the text, such that your health/mana increase is consistent with the value displayed in the textual effects.

Nice! Just as I imagined.
Store the formula as a variable then call it in the function XD
 
Here's your script with a couple changes, might not be ideal but I did it anyway:

Lua:
local config = {
lvl = 1, -- the multiplier for how much level matters. Default 1.
mlvl = 2, -- the mulitplier for how much mlvl matters. Default 1.
forMin = 1.0, -- forumula multiplier for MIN/max range. Default 0.9 == 90%          --Change both to 1.0 for amount healed to have no min/max
forMax = 1.1, -- forumula multiplier for min/MAX range. Default 0.9 == 110%          --Change both to 1.0 for amount healed to have no min/max
removeOnUse = false, -- Does this remove 1 potion after it's use? true/false          -- Default true.
useOnSummons = true, -- Can you use this on a players summon? true/false              -- Default true.
useOnGuildSummon = true, -- Can you use this on guild mate's summon? true/false      -- Default true.
useOnPartySummon = true, -- Can you use this on a party members summon? true/false      -- Default true.
realPvpMode = false, -- True = Players can't use potions for hotkeys || False = Players are allowed to use potions for hotkeys.
exhaust = Condition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD), --Condition for each specific potion.Adjust time in potions table below.
cooldown =  Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_HEAD) -- Condition for creating "groups" of potions with same cooldown time, eg. all mana potions.
}
local POTIONS = {
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [7590] = {empty = 7635, spellid = 3, splash = 7, exhaust = 300, health = false, mana = true, lvlReq = 80, vocations = {1, 2, 5, 6, 11, 12}},                             -- great mana potion
}
------Below for Advanced Users Only----------
function Player:isCreatureFriend(creature)
    local PID
    local GID
      if self:getParty() then
        PID = self:getParty():getId()
      end
      if self:getGuild() then
        GID = self:getGuild():getId()
    end
    if creature:isPlayer() then
        if creature:getParty() then
            if creature:getParty():getId() == PID then
                return true
            end
        end
        if creature:getGuild() then
            if creature:getGuild():getId() == GID then
                  return true
            end
        end
        return false
    end
    if creature:isMonster() then
    local master = creature:getMaster()
        if master then
            if master:getId() == self:getId() then
                return true
            end
            if master:getParty() and master:getParty():getId() == PID then
                return true
            end
            if master:getGuild() and master:getGuild():getId() == GID then
                return true
            end
            return false
        end
    end
end
function onUse(caster, item, castPos, target, toPosition, isHotkey)
local potion = POTIONS[item.itemid]
local health = potion.health
local mana = potion.mana
local hpPercent = potion.healthpercent
local mpPercent = potion.manapercent
local exhaust = config.exhaust
local cooldown = config.cooldown
local mlevel = caster:getMagicLevel()
local level = caster:getLevel()
    if(not potion) then
        return false
    end
    if isHotkey and config.realPvpMode == true then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Hotkey use is disabled for potions!")
    end
    if toPosition.z == 0 or nil then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end
    if toPosition.x == 65535 or nil then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end
    local healthmax = target:getMaxHealth()
    local manamax = target:getMaxMana()
    if caster:getCondition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD, potion.spellid) then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED)
    end
    if (potion.vocations) and  (not caster:getGroup():getAccess()) then
        if (not isInArray(potion.vocations, caster:getVocation():getId())) then
            caster:getPosition():sendMagicEffect(CONST_ME_POFF)
            return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Your vocation may not use this fluid")
        end
    end
    if((potion.lvlReq and caster:getLevel() < potion.lvlReq) and not caster:getGroup():getAccess()) then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Only players of " ..potion.level.. " or above may use this fluid.")
    end
    local healthToAdd = (( math.random((((level)*config.lvl ) + ((mlevel)*config.mlvl ))*config.forMin, ((((level)*config.lvl )+ ((mlevel))*config.mlvl )*config.forMax))))
    local manaToAdd = (( math.random((((level)*config.lvl ) + ((mlevel)*config.mlvl ))*config.forMin, ((((level)*config.lvl )+ ((mlevel))*config.mlvl )*config.forMax))))
    if target:isPlayer() then
        if health == true and mana == true then
            target:addHealth(healthToAdd)
            target:addMana(manaToAdd)
            target:say("+"..healthToAdd .. " +"..manaToAdd)
        if health == true then
            target:addHealth(healthToAdd)
            target:say("+" .. healthToAdd)
        end
        if mana == true then
            target:addMana(manaToAdd)
            target:say("+" .. manaToAdd)
        end
    end
    if target:isMonster() then
    local monsterMaster = target:getMaster()
        if caster:isCreatureFriend(target) then
            if config.useOnSummons == true then
                if health then
                    target:addHealth(healthToAdd)
                    target:say("+" .. healthToAdd)
                else
                    caster:getPosition():sendMagicEffect(CONST_ME_POFF)
                    return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"Summons don't use mana!")
                end
            else
                caster:getPosition():sendMagicEffect(CONST_ME_POFF)
                return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on summons!")
            end
        else
            caster:getPosition():sendMagicEffect(CONST_ME_POFF)
            return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
        end
    end     
    if target:isNpc() then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
    end
    if config.removeOnUse and not caster:getGroup():getAccess() then
        Item(item.uid):remove(1)
    end
    exhaust:setParameter(CONDITION_PARAM_TICKS, potion.exhaust)
    exhaust:setParameter(CONDITION_PARAM_SUBID, potion.spellid)
    caster:addCondition(cooldown)
    caster:addCondition(exhaust)
    target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    target:say("+"..manaToAdd.."", TALKTYPE_MONSTER_SAY)
  return true
end
 
Thanks for the help, but that last version you sent didn't work.

For any one wanting this here's the script for GMP, you can easy add other potions or change it to another potion.

Lua:
local config = {
lvl = 1, -- the multiplier for how much level matters. Default 1.
mlvl = 2, -- the mulitplier for how much mlvl matters. Default 1.
forMin = 1.0, -- forumula multiplier for MIN/max range. Default 0.9 == 90%          --Change both to 1.0 for amount healed to have no min/max
forMax = 1.1, -- forumula multiplier for min/MAX range. Default 0.9 == 110%          --Change both to 1.0 for amount healed to have no min/max
removeOnUse = false, -- Does this remove 1 potion after it's use? true/false          -- Default true.
useOnSummons = true, -- Can you use this on a players summon? true/false              -- Default true.
useOnGuildSummon = true, -- Can you use this on guild mate's summon? true/false      -- Default true.
useOnPartySummon = true, -- Can you use this on a party members summon? true/false      -- Default true.
realPvpMode = false, -- True = Players can't use potions for hotkeys || False = Players are allowed to use potions for hotkeys.
exhaust = Condition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD), --Condition for each specific potion.Adjust time in potions table below.
cooldown =  Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_HEAD) -- Condition for creating "groups" of potions with same cooldown time, eg. all mana potions.
}
local POTIONS = {
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  [7590] = {empty = 7635, spellid = 3, splash = 7, exhaust = 300, health = false, mana = true, lvlReq = 80, vocations = {1, 2, 5, 6, 11, 12}},                             -- great mana potion
}
------Below for Advanced Users Only----------
function Player:isCreatureFriend(creature)
    local PID
    local GID
      if self:getParty() then
        PID = self:getParty():getId()
      end
      if self:getGuild() then
        GID = self:getGuild():getId()
    end
    if creature:isPlayer() then
        if creature:getParty() then
            if creature:getParty():getId() == PID then
                return true
            end
        end
        if creature:getGuild() then
            if creature:getGuild():getId() == GID then
                  return true
            end
        end
        return false
    end
    if creature:isMonster() then
    local master = creature:getMaster()
        if master then
            if master:getId() == self:getId() then
                return true
            end
            if master:getParty() and master:getParty():getId() == PID then
                return true
            end
            if master:getGuild() and master:getGuild():getId() == GID then
                return true
            end
            return false
        end
    end
end

function onUse(caster, item, castPos, target, toPosition, isHotkey)
local potion = POTIONS[item.itemid]
local health = potion.health
local mana = potion.mana
local hpPercent = potion.healthpercent
local mpPercent = potion.manapercent
local exhaust = config.exhaust
local cooldown = config.cooldown
local mlevel = caster:getMagicLevel()
local level = caster:getLevel()
local healthToAdd = (( math.random((((level)*config.lvl ) + ((mlevel)*config.mlvl ))*config.forMin, ((((level)*config.lvl )+ ((mlevel))*config.mlvl )*config.forMax))))
local manaToAdd = (( math.random((((level)*config.lvl ) + ((mlevel)*config.mlvl ))*config.forMin, ((((level)*config.lvl )+ ((mlevel))*config.mlvl )*config.forMax))))
    if(not potion) then
        return false
    end
    if isHotkey and config.realPvpMode == true then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Hotkey use is disabled for potions!")
    end
    if toPosition.z == 0 or nil then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end
    if toPosition.x == 65535 or nil then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    end

    local healthmax = target:getMaxHealth()
    local manamax = target:getMaxMana()
    if caster:getCondition(CONDITION_EXHAUST_HEAL, CONDITIONID_HEAD, potion.spellid) then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED)
    end
    if (potion.vocations) and  (not caster:getGroup():getAccess()) then
        if (not isInArray(potion.vocations, caster:getVocation():getId())) then
            caster:getPosition():sendMagicEffect(CONST_ME_POFF)
            return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Your vocation may not use this fluid")
        end
    end
    if((potion.lvlReq and caster:getLevel() < potion.lvlReq) and not caster:getGroup():getAccess()) then 
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_INFO_DESCR,"Only players of " ..potion.level.. " or above may use this fluid.")
    end
    if target:isPlayer() then
        if health == true then
            target:addHealth(healthToAdd)
        end
        if mana == true then
            target:addMana(manaToAdd)
        end
    end
    if target:isMonster() then
    local monsterMaster = target:getMaster()
        if caster:isCreatureFriend(target) then
            if config.useOnSummons == true then
                if health then
                    target:addHealth(healthToAdd)
                else
                    caster:getPosition():sendMagicEffect(CONST_ME_POFF)
                    return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"Summons don't use mana!")
                end
            else
                caster:getPosition():sendMagicEffect(CONST_ME_POFF)
                return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on summons!")
            end
        else
            caster:getPosition():sendMagicEffect(CONST_ME_POFF)
            return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
        end
    end       
    if target:isNpc() then
        caster:getPosition():sendMagicEffect(CONST_ME_POFF)
        return caster:sendTextMessage(MESSAGE_STATUS_SMALL,"You can't use this on that creature!")
    end
    if config.removeOnUse and not caster:getGroup():getAccess() then
        Item(item.uid):remove(1)
    end
    exhaust:setParameter(CONDITION_PARAM_TICKS, potion.exhaust)
    exhaust:setParameter(CONDITION_PARAM_SUBID, potion.spellid)
    caster:addCondition(cooldown)
    caster:addCondition(exhaust)
    target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    target:say("+"..manaToAdd.."", TALKTYPE_MONSTER_SAY)
  return true
end
 
Back
Top