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

Lua How fix my heal friend script tfs 1.2

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
151
Reaction score
9
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local base = 120
    local variation = 40
    
    local value = math.random(-variation, variation) + base
    local formula = 3 * maglevel + (2 * level)
    
    return formula * value / 100
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

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

i have some problem with this script.

current behavior:
when player(1) use exura sio on player(2), player(1) receive effect CONST_ME_MAGIC_BLUE and if the player(2) not have full health receive effect CONST_ME_MAGIC_BLUE
but if player(2) have full health receive effect CONST_ME_MAGIC_GREEN.

I watched some videos and the right behavior is
player(2) will receive CONST_ME_MAGIC_GREEN no matter your health.

how can i fix this? (One way I thought, is creating a new COMBAT_HEALING, but can i fix this without this)
 
Try this:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local base = 120
    local variation = 40
  
    local value = math.random(-variation, variation) + base
    local formula = 3 * maglevel + (2 * level)
  
    return formula * value / 100
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    if variant:getString() then
        local target = Player(variant:getString())
        if target then
            if target:getHealth() == target:getMaxHealth() then
                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            else
                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
        end
    end
    return combat:execute(creature, variant)
end

I added the default blue effect for healing if the receiver is below max health, it should turn green otherwise, although I'm not entirely certain about using variants this way since I haven't written a spell to use variants in a custom fashion in over a year.
 
not work :/ and now if player(1) is healing player(2) with full health, only appear effect
CONST_ME_MAGIC_BLUE on player(1), nothing appear on (player2)


edit: i found this on game.cpp

C++:
bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage& damage)
{
    const Position& targetPos = target->getPosition();
    if (damage.value > 0) {
        if (target->getHealth() <= 0) {
            return false;
        }

        int32_t realHealthChange = target->getHealth();
        target->gainHealth(attacker, damage.value);
        realHealthChange = target->getHealth() - realHealthChange;

        if (realHealthChange > 0 && !target->isInGhostMode()) {
            addMagicEffect(targetPos, CONST_ME_MAGIC_BLUE);
        }
 
Last edited:
Back
Top