Jump to content

number of mobs around my target at a given distance?


cedced30
 Share

Recommended Posts

Hi, i tried to get the distance between my target and the mobs around it to check if any of them is too close to charge in, the problem is, the bool always returns true and if i try to return the distance between my target and the mob close, it returns 0.

Can anyone help pls? i got this so far:

 

public int TotalMobsCloseToMyTarget;

    private bool IsRangedPullBetter()
    {
        List<WoWUnit> mobsAroundMe = ObjectManager.GetWoWUnitHostile();

        foreach (WoWUnit unit in mobsAroundMe)
        {
            // nombre de mobs proches de ma target
            if (unit != null && (unit.Position.DistanceTo(ObjectManager.Me.TargetObject.Position) <= 7.0F && !unit.IsDead))
            {
                
                DistanceEnemisProches = unit.Position.DistanceTo(ObjectManager.Me.TargetObject.Position);
                TotalMobsCloseToMyTarget++;
                return true;
            }
        }
        return false;
    }

 

Link to comment
Share on other sites

  • 2 weeks later...

I am not sure if this works, as I have not tested it, but try and play around with this:

private bool IsRangedPullBetter()
{
    // Create a list
    var mobsAroundMe = new List<WoWUnit>();

    // Check my target's surroundings for mobs that are valid, alive, attackable, and within
    // 7 yards of target and sort them in the list from closest to furthest from player's position
    if (ObjectManager.Me.HasTarget)
    {
        mobsAroundMe.AddRange(ObjectManager.GetObjectWoWUnit().Where(u =>
        u != null && u.IsValid && u.IsAlive && u.IsAttackable &&
        u.Position.DistanceTo(ObjectManager.Target.Position) <= 7.0f).OrderBy(n =>
        ObjectManager.Me.Position.DistanceTo(n.Position)));
    }

    // Number of mobs within 7 yards of my target = mobsAroundMe.Count();

    // I may want to use a pull spell if there are more than 2 mobs near my target
    if (mobsAroundMe.Count() > 2)
    {
        return true;
    }
    return false;
}

 

Link to comment
Share on other sites

thanks man :)

I found my errors and corrected them in the meantime, here's the working version, i'm using it on my warrior class

1 -, it checks if you have a ranged weapon equiped and if the target is at good distance, if not, returns false.

2 -, If there is only 1 hostile (your target) :

-if there is a neutral lvl1+ (not a critter) around your target, it checks if the neutral is closest to you or your target, if the neutral is closest to you, it returns false (no need for ranged pull), if the neutral is closest to your target, it returns true (you can ranged pulll your target).

- If there are only critters around your target, it returns false, you can charge in, no danger.

3 if there are more than 1 hostile in a 25m radius, it will return true (ranged pull)

I wrote this because my character would do stupid shit like spam cooldowns for 1 or 2 critters or even attack an hostile, then aoe and get aggro from nearby neutral mobs and get killed over and over (fellwood south is horrible for that matter)..

private static bool IsRangedPullBetter()
    {
        if (ObjectManager.Me.GetEquipedItemBySlot(InventorySlot.INVSLOT_RANGED) == 0 && (ObjectManager.Target.GetDistance < 8
                                                                                     || ObjectManager.Target.GetDistance > 25)) return false;
        
        var mobsAroundMyTarget = ObjectManager.GetWoWUnitAttackables().Where(u => u.Position.DistanceTo(ObjectManager.Target.Position) <= 25
                                                                                  && u.IsAttackable);        
        
        var hostilesAroundMyTarget = ObjectManager.GetWoWUnitHostile().Count(u => u.Position.DistanceTo(ObjectManager.Target.Position) <= 25
                                                                                  && u.IsAttackable);
        
        var neutralsAroundMyTarget = ObjectManager.GetWoWUnitAttackables().Count(u => u.Position.DistanceTo(ObjectManager.Target.Position) <= 15
                                                                                      && u.IsAttackable 
                                                                                      && IsNeutral(u) 
                                                                                      && u.Level >= 10);
        
        var crittersAroundMyTarget = ObjectManager.GetWoWUnitAttackables().Count(u => u.Position.DistanceTo(ObjectManager.Target.Position) <= 10
                                                                                      && u.IsAttackable 
                                                                                      && IsNeutral(u) 
                                                                                      && u.Level < 2);
        
        if (hostilesAroundMyTarget > 1)
        {
            return hostilesAroundMyTarget > 1;
        }

        if (crittersAroundMyTarget != 0 && neutralsAroundMyTarget == 0)
        {
            return false;
        }
        
        return neutralsAroundMyTarget >= 1 && mobsAroundMyTarget.All(unit =>
                   !(unit.Position.DistanceTo(ObjectManager.Me.Position) <
                     ObjectManager.Target.Position.DistanceTo(unit.Position)));        
    }

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...