• 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.4 HELP SPELL MANA/HEALTH RUNE

VagosClubTM

Active Member
Joined
Aug 16, 2019
Messages
219
Reaction score
32
Location
Chile
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
 
function onGetFormulaValues(player, level, maglevel)
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local minn = (level * 5) + (maglevel * 2) + 100
    local maxx = (level * 5) + (maglevel * 3) + 100
    local heal = math.floor(math.random(min, max))
    local mana = math.floor(math.random(minn, maxx))
    player:say("+ "..heal.." heal", TALKTYPE_ORANGE_1)
    player:say("+ "..mana.." mana", TALKTYPE_ORANGE_1)
    player:addHealth(heal)
    player:addMana(mana)
    return
end
 
combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
 
function onCastSpell(creature, var, isHotkey)
    return combat:execute(creature, var)
end

Hello friends this is the code that I would like to be able to fix, it has 2 problems.

1.- when using it on another player, he takes out a white skull

2.- It cannot be used in a protection zone.

Thank you very much in advance for taking the time to see my problem. <3
 
Solution
Lua:
function onGetFormulaValues(player, level, maglevel)
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local minn = (level * 5) + (maglevel * 2) + 100
    local maxx = (level * 5) + (maglevel * 3) + 100
    local heal = math.floor(math.random(min, max))
    local mana = math.floor(math.random(minn, maxx))
    player:say("+ "..heal.." heal", TALKTYPE_ORANGE_1)
    player:say("+ "..mana.." mana", TALKTYPE_ORANGE_1)
    --player:addHealth(heal)
    player:addMana(mana)
    return min, max
end

You don't need to player:addHealth(heal) because it's already a healing spell rune. So remove that line and then restore return min, max. Idk if its a bug or something, but...
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
 
function onGetFormulaValues(player, level, maglevel)
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local minn = (level * 5) + (maglevel * 2) + 100
    local maxx = (level * 5) + (maglevel * 3) + 100
    local heal = math.floor(math.random(min, max))
    local mana = math.floor(math.random(minn, maxx))
    player:say("+ "..heal.." heal", TALKTYPE_ORANGE_1)
    player:say("+ "..mana.." mana", TALKTYPE_ORANGE_1)
    player:addHealth(heal)
    player:addMana(mana)
    return
end
 
combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
 
function onCastSpell(creature, var, isHotkey)
    return combat:execute(creature, var)
end

Hello friends this is the code that I would like to be able to fix, it has 2 problems.

1.- when using it on another player, he takes out a white skull

2.- It cannot be used in a protection zone.

Thank you very much in advance for taking the time to see my problem. <3
Could be because your spells.xml entry. Are you sure its not set to group="attack"?
 
Could be because your spells.xml entry. Are you sure its not set to group="attack"?
Hi bro, that was part of the problem, now that I fix that, it can be used within the protection zone but still it takes out the skull of users when using it with others, that is, I use my stone on top of another player and when doing that I take a white skull, and thank you very much for telling me that now it can be used within the protection zone, thank you very much
 
Lua:
function onGetFormulaValues(player, level, maglevel)
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local minn = (level * 5) + (maglevel * 2) + 100
    local maxx = (level * 5) + (maglevel * 3) + 100
    local heal = math.floor(math.random(min, max))
    local mana = math.floor(math.random(minn, maxx))
    player:say("+ "..heal.." heal", TALKTYPE_ORANGE_1)
    player:say("+ "..mana.." mana", TALKTYPE_ORANGE_1)
    --player:addHealth(heal)
    player:addMana(mana)
    return min, max
end

You don't need to player:addHealth(heal) because it's already a healing spell rune. So remove that line and then restore return min, max. Idk if its a bug or something, but when you try to heal the player like that it turns it in to an attack.

Edit: this is still bugged code, see Apollos reply below for a whole fix not just skull fix.
 
Last edited:
Lua:
function onGetFormulaValues(player, level, maglevel)
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local minn = (level * 5) + (maglevel * 2) + 100
    local maxx = (level * 5) + (maglevel * 3) + 100
    local heal = math.floor(math.random(min, max))
    local mana = math.floor(math.random(minn, maxx))
    player:say("+ "..heal.." heal", TALKTYPE_ORANGE_1)
    player:say("+ "..mana.." mana", TALKTYPE_ORANGE_1)
    --player:addHealth(heal)
    player:addMana(mana)
    return min, max
end

You don't need to player:addHealth(heal) because it's already a healing spell rune. So remove that line and then restore return min, max. Idk if its a bug or something, but when you try to heal the player like that it turns it in to an attack.
Another problem is he is adding health and mana to the player no matter what. So if you use the rune on another player then it'll still heal the caster. Probably better to use onTargetCreature then like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onTargetCreature(creature, target)
    local player = creature:getPlayer()
    if not player then
        return
    end

    local level, magicLevel = player:getLevel(), player:getMagicLevel()

    local healthMin = (level * 2) + (magicLevel * 7) + 100
    local healthMax = (level * 3) + (magicLevel * 7) + 100
    local healthGain = math.floor(math.random(healthMin, healthMax))
    target:say("+ "..healthGain.." heal", TALKTYPE_ORANGE_1)
    target:addHealth(healthGain)

    local manaMin = (level * 5) + (magicLevel * 2) + 100
    local manaMax = (level * 5) + (magicLevel * 3) + 100
    local manaGain = math.floor(math.random(manaMin, manaMax))
    target:say("+ "..manaGain.." mana", TALKTYPE_ORANGE_1)
    target:addMana(manaGain)
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
 
Solution
Another problem is he is adding health and mana to the player no matter what. So if you use the rune on another player then it'll still heal the caster. Probably better to use onTargetCreature then like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onTargetCreature(creature, target)
    local player = creature:getPlayer()
    if not player then
        return
    end

    local level, magicLevel = player:getLevel(), player:getMagicLevel()

    local healthMin = (level * 2) + (magicLevel * 7) + 100
    local healthMax = (level * 3) + (magicLevel * 7) + 100
    local healthGain = math.floor(math.random(healthMin, healthMax))
    target:say("+ "..healthGain.." heal", TALKTYPE_ORANGE_1)
    target:addHealth(healthGain)

    local manaMin = (level * 5) + (magicLevel * 2) + 100
    local manaMax = (level * 5) + (magicLevel * 3) + 100
    local manaGain = math.floor(math.random(manaMin, manaMax))
    target:say("+ "..manaGain.." mana", TALKTYPE_ORANGE_1)
    target:addMana(manaGain)
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
Was in the middle of editing my post to reflect this, thank you :D you are absolutely correct.
 
Another problem is he is adding health and mana to the player no matter what. So if you use the rune on another player then it'll still heal the caster. Probably better to use onTargetCreature then like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onTargetCreature(creature, target)
    local player = creature:getPlayer()
    if not player then
        return
    end

    local level, magicLevel = player:getLevel(), player:getMagicLevel()

    local healthMin = (level * 2) + (magicLevel * 7) + 100
    local healthMax = (level * 3) + (magicLevel * 7) + 100
    local healthGain = math.floor(math.random(healthMin, healthMax))
    target:say("+ "..healthGain.." heal", TALKTYPE_ORANGE_1)
    target:addHealth(healthGain)

    local manaMin = (level * 5) + (magicLevel * 2) + 100
    local manaMax = (level * 5) + (magicLevel * 3) + 100
    local manaGain = math.floor(math.random(manaMin, manaMax))
    target:say("+ "..manaGain.." mana", TALKTYPE_ORANGE_1)
    target:addMana(manaGain)
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
hello bro thank you very much now if it works well and without problems they are the best thanks for the help <3
 
Another problem is he is adding health and mana to the player no matter what. So if you use the rune on another player then it'll still heal the caster. Probably better to use onTargetCreature then like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onTargetCreature(creature, target)
    local player = creature:getPlayer()
    if not player then
        return
    end

    local level, magicLevel = player:getLevel(), player:getMagicLevel()

    local healthMin = (level * 2) + (magicLevel * 7) + 100
    local healthMax = (level * 3) + (magicLevel * 7) + 100
    local healthGain = math.floor(math.random(healthMin, healthMax))
    target:say("+ "..healthGain.." heal", TALKTYPE_ORANGE_1)
    target:addHealth(healthGain)

    local manaMin = (level * 5) + (magicLevel * 2) + 100
    local manaMax = (level * 5) + (magicLevel * 3) + 100
    local manaGain = math.floor(math.random(manaMin, manaMax))
    target:say("+ "..manaGain.." mana", TALKTYPE_ORANGE_1)
    target:addMana(manaGain)
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
This is the correct way. xD

Here was my brutal attempt.
I heck'n suck with spells.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    return 1, 1 -- for some reason we have to deal a minimum of 1 damage, or it gives us battle? Bug? idk.
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey) -- we need to do all the healing inside here manually, because otherwise we can't find the target for the creature:say function
    local target = Creature(variant.number)
    local maglevel = creature:getMagicLevel()
    local level = creature:getLevel()
   
    -- health
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local amount = math.floor(math.random(min, max))
    target:say("+ " .. amount .. " heal", TALKTYPE_ORANGE_1)
    target:addHealth(amount)
   
    -- mana
    min = (level * 5) + (maglevel * 2) + 100
    max = (level * 5) + (maglevel * 3) + 100
    amount = math.floor(math.random(min, max))
    target:say("+ " .. amount .. " mana", TALKTYPE_ORANGE_1)
    target:addMana(amount)
   
    -- effects
    combat:execute(creature, variant)
    return
end
 
This is the correct way. xD

Here was my brutal attempt.
I heck'n suck with spells.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    return 1, 1 -- for some reason we have to deal a minimum of 1 damage, or it gives us battle? Bug? idk.
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey) -- we need to do all the healing inside here manually, because otherwise we can't find the target for the creature:say function
    local target = Creature(variant.number)
    local maglevel = creature:getMagicLevel()
    local level = creature:getLevel()
  
    -- health
    local min = (level * 2) + (maglevel * 7) + 100
    local max = (level * 3) + (maglevel * 7) + 100
    local amount = math.floor(math.random(min, max))
    target:say("+ " .. amount .. " heal", TALKTYPE_ORANGE_1)
    target:addHealth(amount)
  
    -- mana
    min = (level * 5) + (maglevel * 2) + 100
    max = (level * 5) + (maglevel * 3) + 100
    amount = math.floor(math.random(min, max))
    target:say("+ " .. amount .. " mana", TALKTYPE_ORANGE_1)
    target:addMana(amount)
  
    -- effects
    combat:execute(creature, variant)
    return
end
is this revscript or normal spell?
 
normal spell.

Don't use mine tho.

@Apollos version is the correct way to do this.
From this post.
I wanted to do it your way. IMO yours is the correct way, its just that bug causes the extra health. My main concern with mine is since there is no COMBAT_HEALING type then if it is ever tracked by onHealthChange checking primaryType then there could potentially be an issue? Idk probably not likely to happen but should be addressed.
 
I wanted to do it your way. IMO yours is the correct way, its just that bug causes the extra health. My main concern with mine is since there is no COMBAT_HEALING type then if it is ever tracked by onHealthChange checking primaryType then there could potentially be an issue? Idk probably not likely to happen but should be addressed.
At the moment it has not caused me errors, it works perfectly in tfs 1.4 version 772
 
I wanted to do it your way. IMO yours is the correct way, its just that bug causes the extra health. My main concern with mine is since there is no COMBAT_HEALING type then if it is ever tracked by onHealthChange checking primaryType then there could potentially be an issue? Idk probably not likely to happen but should be addressed.
It's an intuitive way for sure but I remember facing problems with my runes using this method so I'm not sure it could be considered the correct way. I have switched to finding my target with onCastSpell instead which so far has given me no problems. I would have thought your was was 'correct'. I know mine is janky for sure, lol.

It would be very nice to see a proper way of making spells heal mana like we can with health though so we can make mana runes as easily and simple as a healing rune without all this nonsense messing around in the script. I was confused...
 
Last edited:
It's an intuitive way for sure but I remember facing problems with my runes using this method so I'm not sure it could be considered the correct way. I have switched to finding my target with onCastSpell instead which so far has given me no problems. I would have thought your was was 'correct'. I know mine is janky for sure, lol.

It would be very nice to see a proper way of making spells heal mana like we can with health though so we can make mana runes as easily and simple as a healing rune without all this nonsense messing around in the script.

It's easy to do the mana healing, just there's no way to grab the target, if you want them to do creature:say, for example
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_MANADRAIN) -- this is the crucial part
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local min = 50
    local max = 100
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)   
end
 
It's easy to do the mana healing, just there's no way to grab the target, if you want them to do creature:say, for example
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_MANADRAIN) -- this is the crucial part
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local min = 50
    local max = 100
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)  
end
Oh that's right, I was confusing the two. The problem is always getting the target I see now. Never mind then, thank you :D
 
Another problem is he is adding health and mana to the player no matter what. So if you use the rune on another player then it'll still heal the caster. Probably better to use onTargetCreature then like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onTargetCreature(creature, target)
    local player = creature:getPlayer()
    if not player then
        return
    end

    local level, magicLevel = player:getLevel(), player:getMagicLevel()

    local healthMin = (level * 2) + (magicLevel * 7) + 100
    local healthMax = (level * 3) + (magicLevel * 7) + 100
    local healthGain = math.floor(math.random(healthMin, healthMax))
    target:say("+ "..healthGain.." heal", TALKTYPE_ORANGE_1)
    target:addHealth(healthGain)

    local manaMin = (level * 5) + (magicLevel * 2) + 100
    local manaMax = (level * 5) + (magicLevel * 3) + 100
    local manaGain = math.floor(math.random(manaMin, manaMax))
    target:say("+ "..manaGain.." mana", TALKTYPE_ORANGE_1)
    target:addMana(manaGain)
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
hello friends I realized today that I get this error with the time of using the mana rune, is it repairable?


Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/runes/mana_rune.lua:eek:nTargetCreature
(Unknown scriptfile)
data/spells/scripts/runes/mana_rune.lua:25: attempt to call method 'addMana' (a
nil value)
 
Back
Top