RedBeard

Member
Currently this script finds multiple targets and launches an arrow at all targets at once. I'm trying to get it to attack one target at a time. When it does multiple targets the damage seems to multiply as well strangely.

I change the 'foreach' to if statements having some trouble

Code:
public virtual void Refresh()

		{



			bool foundPlayer = false;



			ArrayList list = new ArrayList();



			foreach ( Mobile mob in GetMobilesInRange( TrapRange ))

			{

				if ( !mob.Alive || mob.AccessLevel > AccessLevel.Player || (mob.Hidden && NoDamageHidden) )

					continue;



				if ( ( (this.Z + 8) >= mob.Z && (mob.Z + 16) > this.Z ) )

				{

if (mob is BaseCreature || mob is BaseCreature && (((BaseCreature)mob).Controlled || ((BaseCreature)mob).Summoned))

list.Add(mob);

else if (mob.Player)

list.Add(mob);



					foundPlayer = true;



					foreach (Mobile mm in list)

					{



Effects.SendMovingEffect( this, mm, SpellEffect, 5, 0, false, true );

Effects.PlaySound( Location, Map, Sound );

Spells.SpellHelper.Damage( TimeSpan.FromSeconds( 0.5 ), mm, mm, Utility.RandomMinMax( MinDamage, MaxDamage ), 100, 0, 0, 0, 0 );



					}





				}

			}

		}
 
If you move the entire code block of Lines 45-58 to Line 65, you'll fix the increasing damage issue.
What's going on is you have a foreach in a foreach, so the same mobiles are being added to the same list multiple times.
Whoever's last in that list is going to be seriously messed up lol :D

In the second foreach, you could wrap the effects in a Timer.DelayCall(), increasing the timer's initial delay by N time for each sequential Mobile it loops over. This will create N timers which all start at the same time, but give the effect of a delayed action between each one.

Code:
int i = 0;

foreach( Mobile mm in list)
{
	Timer.DelayCall(TimeSpan.FromSeconds(0.5 * i++), () =>
	{
		Effects.SendMovingEffect( this, mm, SpellEffect, 5, 0, false, true );
 
		Effects.PlaySound( Location, Map, Sound );
 
		Spells.SpellHelper.Damage( TimeSpan.FromSeconds( 0.5 ), mm, mm, Utility.RandomMinMax( MinDamage, MaxDamage ), 100, 0, 0, 0, 0 );
	});
}
 
1- I have same issue as him, trap attacks multiple targets at once, i tried what you posted @Voxpire and trap still attacking multiple targets at once.

Code:
        public virtual void Refresh()
        {
            ArrayList list = new ArrayList();

            foreach (Mobile mob in GetMobilesInRange(TrapRange))
            {
                if (!mob.Alive || mob.AccessLevel > AccessLevel.Player || (mob.Hidden && NoDamageHidden) || (mob.Player && mob.Backpack.FindItemByType(typeof(nms)) != null) )
                    continue;

                if (((this.Z + 8) >= mob.Z && (mob.Z + 16) > this.Z))
                {
                    if (mob is BaseCreature && (((BaseCreature)mob).Controlled || ((BaseCreature)mob).Summoned))
                        list.Add(mob);
                    else if (mob.Player)
                        list.Add(mob);
      int i = 0;
foreach( Mobile mm in list)
{
    Timer.DelayCall(TimeSpan.FromSeconds(0.5 * i++), () =>
    {
        Effects.SendMovingEffect( this, mm, SpellEffect, 5, 0, false, true );
        Effects.PlaySound( Location, Map, Sound );
        Spells.SpellHelper.Damage( TimeSpan.FromSeconds( 0.5 ), mm, mm, Utility.RandomMinMax( MinDamage, MaxDamage ), 100, 0, 0, 0, 0 );
   
               });
             }
           }
        }
    }


2- Im trying to emulate Dota/LoL turrets behaviour, its possible to make them attack BaseCreature first and if theres no BaseCreature mobiels around, then attack PlayerMobile?
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back