What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[?]Check distance between two WoWUnits

no1knowsy

Well-Known Member
Joined
Feb 28, 2010
Messages
3,927
Reaction score
57
I was looking at the API and other plugins but I didn't see any methods to check the distances between two WoWUnits (both of these units not be ObjectManager.Me)

Like if something is dead, I want it to check if any other wow units are within say 10 yards of the dead unit. This is for a Mage Plugin for Blinking help...

So far it passes args when a mob dies of the dead units into it, and it checks distances to that unit and blinks, other checks in play for ability to blink blah blah...

I just really need a method to check distance between the lootable mob and other WoWUnits.
 
u can get units around yourself
PHP:
        public List<WoWUnit> NearbyUnfriendlyUnits
        {
            get
            {
                return
                    ObjectManager.GetObjectsOfType<WoWUnit>(false, false).Where(p => !p.IsFriendly && !p.Dead && p.DistanceSqr <= 10 * 10).
                        ToList();
            }
        }
 
Yes, but I'm writing it to get my mage to blink to the now dead and lootable mob, and want to check if there are units around the lootable mob, not just around me :(
Is there a way?
 
do u know the units around?
if not, try this
Get all Enemey around u
PHP:
        public List<WoWUnit> NearbyUnfriendlyUnits
        {
            get
            {
                return
                    ObjectManager.GetObjectsOfType<WoWUnit>(false, false).Where(p => !p.IsFriendly && !p.Dead && p.DistanceSqr <= 40* 40).
                        ToList();
            }
        }

Check if the Units around u, are around ur dead mob
PHP:
        private List<WoWUnit> aUnitsAroundDeadUnit= new List<WoWUnit>();
          
	foreach (WoWUnit oponents in NearbyUnfriendlyUnits) // Loop through List with foreach
	{
		if(oponents.Distance(deadUnit.Location)<=10)
		{
			aUnitsAroundDeadUnit.Add(oponents);
		}
	}
if(aUnitsAroundDeadUnit.Count()>1){//do not blink}

but why would u spent a CD for blinking?
 
Last edited:
if(oponents.Distance(deadUnit.Location)<=10)
I did not know you could use the Distance function like this :)
Thank you very much!
It's for blinking to the object, faster than running to it, and it looks more natural for a mage to blink to things :)
 
Lol, found another problem. I wasn't checking to see if the two units were the same thing lol, so obviously it's gonna see two variables, but not know they are the same thing, so it see's two mobs, and won't blink... Stupid programming!
 
my bad ... the using of distance is a little bit different ;) sorry
PHP:
            foreach (WoWUnit oponents in NearbyUnfriendlyUnits) // Loop through List with foreach
            {
                if (oponents.Location.Distance(deadUnit.Location) <= 10)
                {
                    //Prevents adding one unit two times
                    WoWUnit UniqueUnit = aUnitsAroundDeadUnit.Find(delegate(WoWUnit p) { return p.Guid == oponents.Guid; });
                    if (UniqueUnit == null) { aUnitsAroundDeadUnit.Add(oponents); }
                }
            }

Surely this works with LINQ too, but i'm not that firm with LINQ
But i think if u know LINQ u can do this with 1 or 2 Lines of Coding instead of 10 or 20
 
Got at error with that oponents.Distance(deadUnit.Location)

Error: Non-invocable member 'Styx.WoWInternals.WoWObjects.WoWObject.Distance' cannot be used like a method.
 
Got at error with that oponents.Distance(deadUnit.Location)

Error: Non-invocable member 'Styx.WoWInternals.WoWObjects.WoWObject.Distance' cannot be used like a method.
yeah i know, this is why i postet the second snippet :)
Try the snippet directly above your posting
 
Yeah I saw that too. I added it just before looking at your post to see if it would work, and it appears it is working :)
Now the IsFriendly is just looking for if they are green correct? if they are yellow does it still show as friendly? or only red?
!IsFriendly returns (true if green Unit, true if yellow unit, false if red unit)?

I just changed !IsFriendly to "IsHostile", problem solved, I see now problem of blinking into yellow mobs, only red ones.
 
Last edited:
!isFriendly returns true if the unit is yellow or red (this is my conclusion)
isFriendly returns true if the unit is green (that'S the tooltip when using Visual Studio)

if u only want units that are red then change
!IsFriendly to IsHostile
PHP:
        public List<WoWUnit> NearbyUnfriendlyUnits
        {
            get
            {
                return
                    ObjectManager.GetObjectsOfType<WoWUnit>(false, false).Where(p => p.IsHostile && !p.Dead && p.DistanceSqr <= 40* 40).
                        ToList();
            }
        }
to ensure we get no players from the other faction
PHP:
        public List<WoWUnit> NearbyUnfriendlyUnits
        {
            get
            {
                return
                    ObjectManager.GetObjectsOfType<WoWUnit>(false, false).Where(p => p.IsHostile && !p.IsPlayer && !p.Dead && p.DistanceSqr <= 40* 40).
                        ToList();
            }
        }
 
Last edited:
Back
Top