Page 1 of 1

Life Drain (on attack)

Posted: Wed Nov 23, 2022 7:21 pm
by Azzerhoden
The following script applies a life drain effect on a successful attack. I use this on wraiths and the chance of a life drain during an attack is 25%. It's based on the life_drain_aura.js file
// For creatures that can drain life of target when they are hit in combat.  From the life_drain_aura.js script

var iSpecialAttack = 25;   // This is the % chance the attacker will attempt to drain life

function onAttack(pAttacker, pDefender, damageValue, damageType )
{
    var iCurrentHps = pDefender.maxhp;
    var iNum = RandomNumber( 0, 100 );
    if (iNum < iSpecialAttack)  // there is a 25% chance the attack for a chance to drain life
    {
        if( pDefender.health < iCurrentHps )
        {
            var mSpell = Spells[8];
            pDefender.SpellStaticEffect( mSpell );
            pDefender.SoundEffect( 0x01E6, true );  
            hpDrain = RandomNumber( 3, 10 );

            // Apply damage to target
            pDefender.Damage( hpDrain, 1 );
            if( pDefender.socket != null )
                pDefender.EmoteMessage("You feel your life force being stolen away!");
            iCurrentHps = pDefender.health;

            // Restore HP for creature
            if( pAttacker.health >= hpDrain )
                pAttacker.health += hpDrain;
            else
                pAttacker.health += damaged.health;
        }
    }
}