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

Custom Heal Friend

boby psaico

Member
Joined
Oct 17, 2009
Messages
84
Reaction score
5
Hello,

I made a script of a new heal spell like exura sio where the caster is healed at the same time the target is (blocker for example).

The problem is: doesn't matter where the target is located, behind a wall or far away from caster, the spell is ignoring the distance or walls.

I'm not sure about the difference between onCastSpell and onGetFormulaValues functions. My spell uses onCastSpell, the only one that worked well.

Lua:
function onCastSpell(creature, variant)

    local level = getPlayerLevel(creature)
    local maglevel = getPlayerMagLevel(creature)
    
    local min = (level / 20) + (maglevel * 6.3) + 45
    local max = (level / 20) + (maglevel * 14.4) + 90
    local heal = math.random(min,max)
    
    --friend
    local target = Player(variant:getString())
    local targetPosition = target:getPosition() --friend
    local creaturePosition = creature:getPosition() --druid
    
    if target:getName() == creature:getName() then --druid
        doCreatureAddHealth(creature,heal)
        doSendMagicEffect(getThingPos(creature), CONST_ME_MAGIC_BLUE)
    else
        targetPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
        creaturePosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        doCreatureAddHealth(creature,heal)
        doCreatureAddHealth(target,heal)
    end

    return true
    
end


On spells.xml:
XML:
    <instant group="healing" spellid="84" name="Heal Self Friend" words="exura gran sio" lvl="18" mana="200" prem="1" aggressive="0" blockwalls="1" playernameparam="1" params="1" exhaustion="1000" groupcooldown="1000" needlearn="0" script="healing/heal self friend.lua">
        <vocation name="Druid" />
        <vocation name="Elder Druid" />
    </instant>

Here I removed needtarget="1" because if I use it, the server get an error
Code:
attempt to index local 'target' (a nil value)


Could someone help me to develop this spell better?

I guess TFS is 1.0, I couldn't compile a TFS 1.3 yet.
 
Solution
Hello,

I made a script of a new heal spell like exura sio where the caster is healed at the same time the target is (blocker for example).

The problem is: doesn't matter where the target is located, behind a wall or far away from caster, the spell is ignoring the distance or walls.

I'm not sure about the difference between onCastSpell and onGetFormulaValues functions. My spell uses onCastSpell, the only one that worked well.

Lua:
function onCastSpell(creature, variant)

    local level = getPlayerLevel(creature)
    local maglevel = getPlayerMagLevel(creature)

    local min = (level / 20) + (maglevel * 6.3) + 45
    local max = (level / 20) + (maglevel * 14.4) + 90
    local heal = math.random(min,max)

    --friend
    local...
Hello,

I made a script of a new heal spell like exura sio where the caster is healed at the same time the target is (blocker for example).

The problem is: doesn't matter where the target is located, behind a wall or far away from caster, the spell is ignoring the distance or walls.

I'm not sure about the difference between onCastSpell and onGetFormulaValues functions. My spell uses onCastSpell, the only one that worked well.

Lua:
function onCastSpell(creature, variant)

    local level = getPlayerLevel(creature)
    local maglevel = getPlayerMagLevel(creature)

    local min = (level / 20) + (maglevel * 6.3) + 45
    local max = (level / 20) + (maglevel * 14.4) + 90
    local heal = math.random(min,max)

    --friend
    local target = Player(variant:getString())
    local targetPosition = target:getPosition() --friend
    local creaturePosition = creature:getPosition() --druid

    if target:getName() == creature:getName() then --druid
        doCreatureAddHealth(creature,heal)
        doSendMagicEffect(getThingPos(creature), CONST_ME_MAGIC_BLUE)
    else
        targetPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
        creaturePosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        doCreatureAddHealth(creature,heal)
        doCreatureAddHealth(target,heal)
    end

    return true

end


On spells.xml:
XML:
    <instant group="healing" spellid="84" name="Heal Self Friend" words="exura gran sio" lvl="18" mana="200" prem="1" aggressive="0" blockwalls="1" playernameparam="1" params="1" exhaustion="1000" groupcooldown="1000" needlearn="0" script="healing/heal self friend.lua">
        <vocation name="Druid" />
        <vocation name="Elder Druid" />
    </instant>

Here I removed needtarget="1" because if I use it, the server get an error
Code:
attempt to index local 'target' (a nil value)


Could someone help me to develop this spell better?

I guess TFS is 1.0, I couldn't compile a TFS 1.3 yet.
You have to use variant:getNumber() instead of getString() because in this case the variant will only return a unique id of the creature.
Also it's a good idea to verify that target exists before you attempt to use other function with it. So try this out:
Lua:
function onCastSpell(creature, variant)
    local level, maglevel = creature:getLevel(), creature:getMagicLevel()
    local min = (level / 20) + (maglevel * 6.3) + 45
    local max = (level / 20) + (maglevel * 14.4) + 90
    local heal = math.random(min, max)
    
    local target = Player(variant:getNumber())
    if not target or target.uid == creature.uid then
        creature:addHealth(heal)
        creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    else
        creature:addHealth(heal)
        target:addHealth(heal)
        creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end
 
Last edited:
Solution
Back
Top