Life Drain (on attack)

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Azzerhoden
UOX3 Newbie
Posts: 16
Joined: Wed Oct 05, 2022 3:10 pm
Has thanked: 0
Been thanked: 8 times

Life Drain (on attack)

Post 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;
        }
    }
}
Attachments
life_drain.js
(1.11 KiB) Downloaded 239 times
These users thanked the author Azzerhoden for the post:
dragon slayer
Post Reply