Doom

Member
looking for some assistance on making this not target everyone around you unless in combat or hostel. it currently attacks everything including the owner

public void DrainLife()
{
ArrayList list = new ArrayList();

foreach (Mobile m in this.GetMobilesInRange(3))
{
if (m == this || !CanBeHarmful(m))
continue;

if (m is BaseCreature && (((BaseCreature)m).Controled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team))
list.Add(m);
if (m is BaseCreature)
list.Add(m);
else if (m.Player)
list.Add(m);

}

foreach (Mobile m in list)
{
DoHarmful(m);

m.FixedParticles(0x374A, 10, 15, 5013, 0x496, 0, EffectLayer.Waist);
m.PlaySound(0x231);

m.SendMessage("He Sucks Your Life Out!");

int toDrain = Utility.RandomMinMax(30, 50);

Hits += toDrain;
m.Damage(toDrain, this);
}
}
 
Take a look at one of my 'DrainLife' sections and see how I control what gets added to the list as well as what kind of damage might be applied.

I hope this helps a bit.

Code:
        public void DrainLife()
        {
            if( this.Map == null )
                return;

            ArrayList list = new ArrayList();

            foreach ( Mobile m in this.GetMobilesInRange( 2 ) )
            {
                if ( m == this || !CanBeHarmful( m ) )
                    continue;

                if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team) )
                    list.Add( m );
                else if ( m.Player )
                    list.Add( m );
            }

            foreach ( Mobile m in list )
            {
                DoHarmful( m );

                m.FixedParticles( 0x374A, 10, 15, 5013, 0x496, 0, EffectLayer.Waist );
                m.PlaySound( 0x231 );
                m.SendMessage( "You feel the life drain out of you!" );

                if (m is PlayerMobile)
                {
                    PlayerMobile pm = m as PlayerMobile;

                    if ( pm == null || pm.Deleted || !pm.Alive )
                    {
                        return;
                    }

                    if ( (pm.Skills.Swords.Base >= 115.0 && pm.Skills.Parry.Base >= 115.0) || (pm.Skills.Swords.Base >= 115.0 && pm.Skills.Bushido.Base >= 115.0) || (pm.Skills.Fencing.Base >= 115.0 && pm.Skills.Parry.Base >= 115.0) || (pm.Skills.Fencing.Base >= 115.0 && pm.Skills.Bushido.Base >= 115.0) || (pm.Skills.Macing.Base >= 115.0 && pm.Skills.Parry.Base >= 115.0) || (pm.Skills.Macing.Base >= 115.0 && pm.Skills.Bushido.Base >= 115.0) )
                    {
                        int toDrain = Utility.RandomMinMax( 60, 80 );
                        Hits += toDrain;
                        m.Damage( toDrain, this );
                    }
                }
                else
                {
                    int toDrain = Utility.RandomMinMax( 20, 30 );
                    Hits += toDrain;
                    m.Damage( toDrain, this );
                }
            }
        }
 
However the issue with this is that if its your pet it will attack u and others aswell as other pets thats the issue however I've got it figured out.
 
If a pet (or anything else unwanted) is attacking maybe you can force it to stop or attack something else. Here is a sample of one of my OnGotMeleeAttack sections. You could play with it and try putting it in your DrainLife or putting it in other 'OnGot' or 'OnGave' sections.

Code:
        public override void OnGotMeleeAttack( Mobile m )
        {
            base.OnGotMeleeAttack( m );

            if ( (m == null) || (m.Deleted) || !(m.Alive) || !(m.Map == this.Map) )
            {
                return;
            } 

            if ( 0.2 > Utility.RandomDouble() && m is BaseCreature )
            {
                BaseCreature c = (BaseCreature)m;

                c.ControlTarget = c.ControlMaster;
                c.ControlOrder = OrderType.Attack;
                c.Combatant = c.ControlMaster;
            }
        }
 
Hmm that looks like it attacks everything on the map if it's an area atrack unless u have it defined anywhere else a set range or line of sight?
 
I think my point was to suggest that 'you' could try various things using these types of code (and others) to make an 'attacker' drop you as a combatant or target. You can even have someone else's pet turn on their master. Sorry, I was not trying to complete your script here.
 
I had already mentioned I have it working not asking for a completion if whats been completed merely telling you this is buggy code you are sharing.
 
Dont see his code attacking everything on the map?

In his drain script he has
Code:
foreach ( Mobile m in this.GetMobilesInRange( 2 ) )

the other code is for getting actually hit by an Melee attack, so its fine too, without an range check
 

Active Shards

  • Unchained
    Custom (Classic)
    • Players
    • 130 Online
    • 273 Peak
  • The Crossroads
    Mondain's Legacy
    • Players
    • 107 Online
    • 190 Peak
  • UO Eventine
    Custom (Classic)
    • Players
    • 89 Online
    • 137 Peak
  • Insane UO
    Endless Journey
    • Players
    • 77 Online
    • 105 Peak
  • UO: New Renaissance
    Custom (Classic)
    • Players
    • 22 Online
    • 85 Peak
  • CALYPSO
    Custom (Modern)
    • Players
    • 20 Online
    • 30 Peak
  • Pandora
    Custom (Modern)
    • Players
    • 20 Online
    • 32 Peak
  • UO Phoenix
    Custom (Classic)
    • Players
    • 19 Online
    • 48 Peak
  • UO Enigma
    Custom (Modern)
    • Players
    • 18 Online
    • 172 Peak
  • Arth
    Custom (Modern)
    • Players
    • 15 Online
    • 34 Peak

Donations

Total amount
$0.00
Goal
$500.00
Back