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

[Plugin] Disable Pulse(), or w\e

lasbat

New Member
Joined
Jun 22, 2011
Messages
10
Reaction score
0
I'm implementing spritithealer-corpse navigation (hb's navigator cant get to it correctly) and i'm having a little issue.
How can i disable or do something with plugin(so it will stop calling pulse again and again), until my toon will get to the destination point?
Code:
if (Me.IsGhost)
            {
                
                Logging.Write("I'm flying to my body");
                
                body = new WoWPoint(Me.CorpsePoint.X,Me.CorpsePoint.Y,Me.CorpsePoint.Z);
                me = new WoWPoint(Me.X, Me.Y, Me.Z);
                WoWPoint point0 = new WoWPoint(Me.X, Me.Y, Me.Z + 50);
                Logging.Write("point0 {0}", point0);                
                while(Me.Location!=point0)
                {
                    Styx.Logic.Pathing.Flightor.MoveTo(point0);                    
                }
                Logging.Write("point1 {0}", point1);
                me = new WoWPoint(Me.X, Me.Y, Me.Z);
                
                while (Me.Location != point1)
                {
                    WoWMovement.ClickToMove(point1);
                }
}
Here is an example of what i'm doing
and here is an example of what i'm getting in logs
Code:
I'm flying to my body
point0 <6119.564, 1033.315, 249.7186>
point1 <5882.885, 666.8167, 318.8163>

I'm flying to my body
point0 <6119.564, 1033.315, 249.7186>
point1 <5882.885, 666.8167, 318.8163>

I'm flying to my body
point0 <6119.564, 1033.315, 249.7186>
point1 <5882.885, 666.8167, 318.8163>

and so on...
Perhaps i did\am doing something wrong, please correct me if it is so.
Maybe i can somehow disable bot's movement at all, so it will navigate with plugin only?
 
maybe chuck a wait function untill you arive to your desitantion ?

while ( me.ismoving )
 
Last edited:
show your pulse errors and your code

trust me there's a reason that it doesn't work, I had to change my code in order to fix a NullException (thank to znf).
 
Code:
public class Class1: HBPlugin
    {
        private static LocalPlayer Me { get { return ObjectManager.Me; } }
        public override string Name { get { return "pather"; } }
        public override string Author { get { return "Lasek"; } }
        public override Version Version { get { return new Version(1, 0); } }
        public override bool WantButton { get { return false; } }
       
        public override void Pulse()
        {
            WoWPoint body = new WoWPoint();
            WoWPoint me = new WoWPoint();
            WoWPoint point1 = new WoWPoint(6000.885, 666.8167, 318.8163);
            WoWPoint point2 = new WoWPoint(6136.799,791.6204,251.3421);
            //WoWPoint point3 = new WoWPoint(573.3088, 1577.405, 350.58);
           
           // wowpoint==573.3088,1577.405,350.58;
            //X="573.3088" Y="1577.405" Z="350.58"
            if (Me.IsGhost)
            {
                
                Logging.Write("I'm flying to my body");
                
                body = new WoWPoint(Me.CorpsePoint.X,Me.CorpsePoint.Y,Me.CorpsePoint.Z);
                me = new WoWPoint(Me.X, Me.Y, Me.Z);
                WoWPoint point0 = new WoWPoint(Me.X, Me.Y, Me.Z + 50);
               // Logging.Write("point0 {0}", point0);                
                while(me.Distance(point0)>5)
                {
                    Logging.Write("point0 {0}", point0);
                    Styx.Logic.Pathing.Flightor.MoveTo(point0);
                    wait(5000);
                }
               // Logging.Write("point1 {0}", point1);
                me = new WoWPoint(Me.X, Me.Y, Me.Z);
                while (me.Distance(point1) > 5)
                {
                    Logging.Write("point1 {0}", point0);
                    WoWMovement.ClickToMove(point1);
                    wait(5000);
                }
                me = new WoWPoint(Me.X, Me.Y, Me.Z);
                while (me.Distance(point2) > 5)
                {
                    Logging.Write("point2 {0}", point0);
                    WoWMovement.ClickToMove(point2);
                    wait(5000);
                }
                //Logging.Write("point {0}", point2);
                //WoWMovement.ClickToMove(point2);
                //Logging.Write("point {0}", point3);
                //WoWMovement.ClickToMove(point3);
                Logging.Write("point {0}", body);
                //Styx.Logic.Pathing.Navigator.MoveTo(body);
                Styx.Logic.Pathing.Flightor.MoveTo(body);
                
            }
        }
        public static Stopwatch timeout = new Stopwatch();
        public static void wait(int ms)
        {
            Logging.Write("timeout started");
            timeout.Start();
            
            if (timeout.ElapsedMilliseconds >= ms)
            {
                Logging.Write("timeout stopped");
                timeout.Stop();
                timeout.Reset();

            }
        }
    }


Code:
[13:42:34:832] timeout started
[13:42:34:832] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:841] timeout started
[13:42:34:841] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:841] timeout started
[13:42:34:841] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:849] timeout started
[13:42:34:849] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:850] timeout started
[13:42:34:850] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:859] timeout started
[13:42:34:859] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:859] timeout started
[13:42:34:859] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:867] timeout started
[13:42:34:867] point0 <5882.892, 666.8057, 219.5078>
[13:42:34:868] timeout started
i did something wrong:D
 
public static void wait(int ms)
{
Logging.Write("timeout started");

timeout.Start();

if (timeout.ElapsedMilliseconds >= ms)
{
Logging.Write("timeout stopped");
timeout.Stop();
timeout.Reset();

}
}



u might wanna chuck a loop in there or that is completly useless.
 
right, i've added a loop to timer, now its still the basic problem, bot flys to the 1st point and stops there
 
Last edited:
maybe u should go another way
here is an example how i would do it (this must be translated to HB Api, but shouldn't be that hard)
PHP:
using System.Linq;
using System;
using System.Threading;
using BCore.Api;
using BCore.Api.Common;
using BCore.Api.Navigation.Mover;
using BCore.Api.Objects;
using Bot.Api;
using Bot.Api.State;
using BCore.Api.Enum;
using PveLogic.Helper.Movement;

namespace PveLogic
{
    public class GhostRun : IState
    {
     
        public GhostRun(int priority) : base("GhostRun", 0, priority)
        {
        }

        public override BStateStatus Run()
        {
            BMain.FireHook(this.Name);

            //We are missing our corpse (wait for it)
            if (BMain.Me.CorpseLocation == null || BMain.Me.CorpseLocation.X == 0 && BMain.Me.CorpseLocation.Y == 0 && BMain.Me.CorpseLocation.Z == 0)
            {
                Thread.Sleep(500);
                return BStateStatus.Aborted;
            }


            if (BMain.Me.IsMounted)
            {
                //Probably on flying mount, take a ride!
            }


            BBot.Log("Calculating path to corpse: " + BMain.Me.CorpseLocation);
            BMover mover = new BMover(new GhostRunAbortCondition());   
            BMoveResult result = mover.PPatherMoveTo(BMain.Me.CorpseLocation, 3, 4);

            if (result == BMoveResult.CantFindPath)
            {
                BBot.Log("Can't get to our corpse");
                return BStateStatus.Aborted;
            }

            //We have to wait because we revived too often
            if (BCore.Api.Hook.BHook.GetLuaDoStringResult<int>("GetCorpseRecoveryDelay()") > 0)
            {
                Thread.Sleep(1000);
                return BStateStatus.Aborted;
            }

            BLocation safeSpot = _getSafeSpot();
            if (safeSpot != null)
            {
                BBot.Log("Moving to a safe spot");
                mover.PPatherMoveTo(BMain.Me.CorpseLocation, 3, 4);
            }
            else
            {
                BBot.Log("Did not find any safe spot.");
            }

            if (BMain.Me.CorpseLocation.DistanceToMe() <= 30)
            {
                BBot.Log("Reached our corpse. Going to revive!");

                Thread.Sleep(1000);

                BCore.Api.Hook.BHook.LuaDoString("RetrieveCorpse()");
                BTimer waitForAliveTimer = new BTimer(10000);
                while (!waitForAliveTimer.IsReady && BMain.Me.IsGhost)
                    Thread.Sleep(100);

                if (!BMain.Me.IsGhost)
                {
                    BBot.Log("Successfully revived!");
                }
            }

            return BStateStatus.Success;
        }

        private BLocation _getSafeSpot()
        {
            BLocation safeLocation = null;

            for (float radius = 3; radius <= 30 && safeLocation == null; radius += 10)
            {

                for (double degree = 0; degree < 360 && safeLocation == null; degree += 3)
                {
                    float testX = BMain.Me.X + (radius * (float)Math.Cos(degree));
                    float testY = BMain.Me.Y + (radius * (float)Math.Sin(degree));
                    float testZ = BCore.Api.Navigation.BPather.GetZ(testX, testY, 0, 0);
                   
                    if (testZ != float.MinValue)
                    {
                        BLocation testLocation = new BLocation(testX, testY, testZ);

                        if (!_monstersNear(testLocation))
                        {


                            //Can't revive this Z far from our corpse
                            if (Math.Abs(testZ - BMain.Me.Z) > 19)
                                continue;

                            if (_hasPathTo(testLocation))
                            {
                                safeLocation = testLocation;
                                break;
                            }

                        }
                    }

                }
            }

            return safeLocation;
        }


        private bool _monstersNear(BLocation testLocation)
        {          
            var uu = from unit in BObjectList.UnitObjects where testLocation.DistanceTo(unit) > unit.AggroRadius && (unit.Reaction == BUnitReaction.Hostile || unit.Reaction == BUnitReaction.Hated) select unit;            
            return uu.Count() != 0;
        }

        private bool _hasPathTo(BLocation location) {

            return BCore.Api.Navigation.BPather.CreatePath(BMain.Me.Location, location, 4, null) != null;
        }

        public override bool NeedRun()
        {
            return BMain.Me.IsGhost;
        }
    }
}
 
you guys are making it more complicated then it needs to be, not only that but you should NEVER use Sleeps, or while loops, specialy the way your using them

heres an example of how you should be doing it.

it does not use sleeps, and wont block other plugins, like BuddyCenter, or something that NEEDS to run from running.
Code:
        public static Stopwatch XYZWait = new Stopwatch();
        public static bool DidMove = false;

        public override void Pulse()
        {
           if(Waiting())
           {
               //this makes it return to the top of pulse, your not sleeping, 
               //and your not locking the thread, other plugins and whatever else can function normaly.
               return;
           }
           //we sick our logic behind this point, if you look at Waiting()
           //if waiting returns true we will just return, making it not do anything
            if(!Me.IsFlying)
            {
                //flys up by clicking directly above us.
                WoWMovement.ClickToMove(Me.X, Me.Y, Me.Z + 10);
                DidMove = true;
                XYZWait.Start();
            }
            
        }

        public bool Waiting()
        {
            if(DidMove)
            {
                //We did move, checking timer till its time, and making it wait.
                if(XYZWait.Elapsed.TotalSeconds > 10)
                {
                    //we did need to move and we waited 10sec return false to check our
                    //logic and make a new action if needed.
                    DidMove = false;
                    XYZWait.Reset();
                    return false;
                }
                return true;
            }
            if(!Me.IsMoving && Me.Dead)
            {
                //if im not moving and not dead, let it check our logic.
                return false;
            }
            if(Me.Location.Distance(Me.CorpsePoint) > 5)
            {
                //im way far from my corpse, and nothing above set it to wait, this will. 
                return true;
            }
            //otherwise dont wait. 
            return false;

        }
 
you guys are making it more complicated then it needs to be, not only that but you should NEVER use Sleeps, or while loops, specialy the way your using them

heres an example of how you should be doing it.

it does not use sleeps, and wont block other plugins, like BuddyCenter, or something that NEEDS to run from running.
Code:
        public static Stopwatch XYZWait = new Stopwatch();
        public static bool DidMove = false;

        public override void Pulse()
        {
           if(Waiting())
           {
               //this makes it return to the top of pulse, your not sleeping, 
               //and your not locking the thread, other plugins and whatever else can function normaly.
               return;
           }
           //we sick our logic behind this point, if you look at Waiting()
           //if waiting returns true we will just return, making it not do anything
            if(!Me.IsFlying)
            {
                //flys up by clicking directly above us.
                WoWMovement.ClickToMove(Me.X, Me.Y, Me.Z + 10);
                DidMove = true;
                XYZWait.Start();
            }
            
        }

        public bool Waiting()
        {
            if(DidMove)
            {
                //We did move, checking timer till its time, and making it wait.
                if(XYZWait.Elapsed.TotalSeconds > 10)
                {
                    //we did need to move and we waited 10sec return false to check our
                    //logic and make a new action if needed.
                    DidMove = false;
                    XYZWait.Reset();
                    return false;
                }
                return true;
            }
            if(!Me.IsMoving && Me.Dead)
            {
                //if im not moving and not dead, let it check our logic.
                return false;
            }
            if(Me.Location.Distance(Me.CorpsePoint) > 5)
            {
                //im way far from my corpse, and nothing above set it to wait, this will. 
                return true;
            }
            //otherwise dont wait. 
            return false;

        }
thanks alot for your reply, but its not what i've wanted to do.
I need my plugin to navigate to 1 point from spirithealer(navigator cant do it), and you've made it just to fly a bit up, when char is dead.
it won't work for my needs, sorry(it will crash wow)
 
thanks alot for your reply, but its not what i've wanted to do.
I need my plugin to navigate to 1 point from spirithealer(navigator cant do it), and you've made it just to fly a bit up, when char is dead.
it won't work for my needs, sorry(it will crash wow)
thats an example, you need to modify it for your own needs, im not going to code the entire thing for you. im not even sure what your trying to do, if i did i would have coded the example alittle better.

use the example as a jumping off point, DO NOT USE SLEEPS, or while loops.
 
Back
Top