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

Spell Display animated animations with mana and health healing effect, with matching colors, etc.

Mateus Robeerto

Legendary OT User
Joined
Jun 5, 2016
Messages
1,744
Solutions
92
Reaction score
1,256
Location
ლ(ಠ益ಠლ)
I'll explain step by step how to add an animated effect to display the number of healing and mana.

Here is an example of the original UH (ultimate_healing) spell. TFS 1.5 8.0 Nekiro.

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_AGGRESSIVE, false)

function onGetFormulaValues(player, level, magicLevel)

    local min = (level / 5) + (magicLevel * 6.8) + 42

    local max = (level / 5) + (magicLevel * 12.9) + 90

    return min, max

end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)

    return combat:execute(creature, variant)

end

Let's work on how to correctly replace the proper place.

LUA:
return min, max

for this

LUA:
local totalIncrease = math.random(min, max)

    local formattedText = string.format("+%d", totalIncrease)

    doSendAnimatedText(formattedText, getPlayerPosition(cid), 12)

    return totalIncrease, totalIncrease


Look how the end result is here.

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_AGGRESSIVE, false)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 6.8) + 42
    local max = (level / 5) + (magicLevel * 12.9) + 90
 
    local totalIncrease = math.random(min, max)
    local formattedText = string.format("+%d", totalIncrease)
    Game.sendAnimatedText(formattedText, player:getPosition(), 12)

    return totalIncrease, totalIncrease
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

In green color it is 12, if you want to change it, just modify that line.

LUA:
doSendAnimatedText(formattedText, getPlayerPosition(cid), 12)

See the GIF to check the result

Please, after making the changes or modifications, let us know here so we know if it worked or not.

Note: For those of you who don't have text animation in your source, you need to add it to the source for the animated text display to work correctly.

Hope you enjoyed this script.😏
 
Last edited:
thx for share <3
Don’t follow the tutorial; mine is quite unintuitive, bad, useless, and cumbersome because you’ll have to add each script individually, which is a hassle.


Another alternative here is to just add the data/scripts/filename.lua file, which is a revscript. It will display all animations generally without needing to add each one separately—better, less work, and functional.



LUA:
local combatHandler = {
    [COMBAT_HEALING] = {
        color = TEXTCOLOR_RED,
        format = '%s%d',
        effect = CONST_ME_DRAWBLOOD,
        origin = ORIGIN_SPELL,
        selfOnly = true
    },
    [COMBAT_MANADRAIN] = {
        color = TEXTCOLOR_LIGHTBLUE,
        format = '%s%d',
        effect = CONST_ME_SOUND_BLUE,
        origin = ORIGIN_SPELL,
        selfOnly = true
    }
}

local function executeHandler(handler, player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local requiredOrigin = handler.origin or -1
    if requiredOrigin ~= -1 and origin ~= requiredOrigin then
        return
    end

    local selfDamageOnly = handler.selfOnly or false
    if selfDamageOnly and player ~= attacker then
        return
    end

    local color = handler.color
    local textFormat = handler.format
    local magicEffect = handler.effect
    local playerPos = player:getPosition()
    local dmg = primaryDamage + secondaryDamage

    local animatedText = textFormat:format((dmg > 0 and "+" or ""), dmg)
    Game.sendAnimatedText(animatedText, playerPos, color)
    if magicEffect then
        playerPos:sendMagicEffect(magicEffect)
    end
end

local healthChangeEvent = CreatureEvent("PlayerHealthChange")
healthChangeEvent:type("healthchange")

function healthChangeEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local player = Player(creature)
    local handler = combatHandler[primaryType or secondaryType]
    if player and handler then
        executeHandler(handler, player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

healthChangeEvent:register()

local manaChangeEvent = CreatureEvent("PlayerManaChange")
manaChangeEvent:type("manachange")

function manaChangeEvent.onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local player = Player(creature)
    local handler = combatHandler[primaryType or secondaryType]
    if player and handler then
        executeHandler(handler, player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

manaChangeEvent:register()

local loginEvent = CreatureEvent("RegisterPlayerStatsChangeEvents")

function loginEvent.onLogin(player)
    player:registerEvent("PlayerHealthChange")
    player:registerEvent("PlayerManaChange")
    return true
end

loginEvent:register()
 
Back
Top