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

move closer when out of range

hazard

Well-Known Member
Joined
Sep 16, 2010
Messages
1,854
Reaction score
55
I am trying to add a command to my CC to make the druid move closer to a target when they go slightly out of range. I have been looking at other CC's and been trying for a while now but yet again I am stuck :/

So anything target between 40 and 60 fett I am trying to get the druid to move within 30 yards of the targets range.

Idea:
Code:
else if (Battlegrounds.IsInsideBattleground && u.Distance > 40 && u.Distance < 60)
{
WoWPoint moveTo = WoWMathHelper.CalculatePointFrom(Me.Location, u.Location, 30f);
WoWMovement.MoveTo(u.Location, 30f);
return false;
}
 
here is the exact method I made for my Rogue CC called JSub Rogue. If you're interested go download it and check out some stuff there. You can copy it if you want just give credit!! :D
you can change the distance to whatever you want.

void MoveTo()
{
if (Me.CurrentTarget.Distance > 3)
{
Navigator.MoveTo(Me.CurrentTarget.Location);

}
}
 
Here is one I wrote and haven't implemented yet. Put the unit and how close to it you want to be...

PHP:
private void CloseDistance(WoWUnit u, int distance)
        {
            Navigator.PlayerMover.MoveTowards(u.Location);               
            while (u.Distance > distance)
            {
                if (!Me.IsMoving)
                {
                    Navigator.PlayerMover.MoveTowards(u.Location);
                }
                Thread.Sleep(100);                
            }
            Navigator.PlayerMover.MoveStop();
        }

This is one that I never got working right :( ...

PHP:
private void SmartCloseDistance(WoWUnit u, int distance)
        {
            WoWPoint[] PathToTarget = Navigator.GeneratePath(Me.Location, u.Location);
            int CurrentPoint = 0;
            Logging.Write("Moving this many points: " + PathToTarget.Length);
            while (u.Distance > distance && CurrentPoint<PathToTarget.Length)
            {                
                Logging.Write("Moving to point " + PathToTarget[CurrentPoint]); 
                Navigator.MoveTo(PathToTarget[CurrentPoint]);
                CurrentPoint++;
            }
            Navigator.PlayerMover.MoveStop();
        }
 
haze210's one will work properly. Behavior trees help you a lot to sort these things out. The logic error in your code is that the CC is being executed at each pulse, thus you're overkilling with calculations each CC iteration untill you're where you want to be.

jasf10, your SmartCloseDistance method has something which you should avoid at all costs: a while cycle. Using it you're preventing the code to do anything else. Let's suppose you die in the meanwhile, the bot will still try to go to the next waypoint. In any case I'd do something like this using your method:

PHP:
        private void SmartCloseDistance(WoWUnit u, int distance)
        {
            WoWPoint[] PathToTarget = Navigator.GeneratePath(Me.Location, u.Location);
            int CurrentPoint = 0;
            Logging.Write("Moving this many points: " + PathToTarget.Length);
            while (CurrentPoint < PathToTarget.Length || u.Distance > distance)
            {
                if(PathToTarget[CurrentPoint].Distance <= Navigator.PathPrecision) // Dynamic distance calculated on speed, you can adjust it adding + Xf
                {
                                Logging.Write("Moving to point " + PathToTarget[CurrentPoint]); 
                                CurrentPoint++;
                }
                Navigator.MoveTo(PathToTarget[CurrentPoint]);
            }
            // Navigator.PlayerMover.MoveStop();
        }
 
Last edited:
Wow... I never thought about dying during a while loop. Thanks dude.
 
@jim87 the code that you gave me threw up a large error so I tried to change it a little but it does not seem to work as my druid just stands there now.

Code:
        private bool SmartHeal()
        {
            WoWUnit u = ObjectManager.GetObjectsOfType<wowplayer>(false, false).FirstOrDefault(unit => unit.IsHostile && unit.IsAlive && !unit.Mounted && unit.InLineOfSight);

            WoWPoint[] PathToTarget = Navigator.GeneratePath(Me.Location, u.Location);
            int CurrentPoint = 35;
            if (u.Distance > 40 && u.Distance < 60)
            {
                Navigator.MoveTo(PathToTarget[CurrentPoint]);
                return true;
            }
            else
            {
                return false;
            }
        }
</wowplayer>

p.s how do I use a <code><code>private void?</code></code>
 
Last edited:
@jim87 the code that you gave me threw up a large error so I tried to change it a little but it does not seem to work as my druid just stands there now.

Code:
        private bool SmartHeal()
        {
            WoWUnit u = ObjectManager.GetObjectsOfType<wowplayer>(false, false).FirstOrDefault(unit => unit.IsHostile && unit.IsAlive && !unit.Mounted && unit.InLineOfSight);

            WoWPoint[] PathToTarget = Navigator.GeneratePath(Me.Location, u.Location);
            int CurrentPoint = 35;
            if (u.Distance > 40 && u.Distance < 60)
            {
                Navigator.MoveTo(PathToTarget[CurrentPoint]);
                return true;
            }
            else
            {
                return false;
            }
        }
</wowplayer>

p.s how do I use a <code><code>private void?</code></code>

You are probably getting a index out of bounds error. b/c you set current point to 35. I guess you would want that to just be zero so you could move to the first point. 35 would mean that the array PathToTarget has at least 36 points in it.

I would add !Me.IsMoving to your if statement as well so your CC doesn't keep generating paths every millisecond while your dude is moving to that point.

If you are setting the return type to void, you are just saying that your method doesn't return anything. If you make your movement a void method, you can pick you target in your healing method, call you movement and continue on with your healing rotation. For a bool, you would probably want to put it in you if statement before a heal check.
 
That was just a proof of concept, the method should not used as is, as it will freeze all the other behaviors in case of combat, death or whatever.
 
I don't think the CC needs to worry about movement. If you dude is out of range, he can fall out of combat and the bot can move him to a better place. Have you done any runs to study movement yet?

A worst case scenario for implementing movement into a healing CC is... consider you have 10 targets needing healing in a 60m radius, they are in all directions and all 40m+ away from you. They could end up playing tug of war with you as you move to heal one, then move to heal another, and another. This differs from a dps, where they stick to one target for extended periods of time.
 
Last edited:
Back
Top