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

Need a way make hb pause

parrot

Community Developer
Joined
Feb 5, 2012
Messages
222
Reaction score
7
Hi. im making my first plugin. I want it to make honorbuddy stop and pretend to be afk while other players are nearby. Ive written some test code which seem to work but im not happy with how it makes honobuddy pause what its doing. When A player is detected i keep my code running in a loop preventing the function from returning. Is there a better way to accomplish the same behavior?



Code:
    class Afk : HBPlugin
    {
        public override sealed string Name { get { return "Parrots AFK plugin"; } }
        public override string Author { get { return "Parrot"; } }
        public override Version Version { get { return new Version(0, 1); } }
        private static LocalPlayer Me { get { return ObjectManager.Me; } }
        private static List<WoWObject> playerList = new List<WoWObject>();



        private static bool detected = false; //true if player is nearby
        private static DateTime detectedTime;
        private static int waitTime = 1; //mins to wait before logout

        public override void Pulse()
        {


            if (!Me.Combat)
            {
                updatePlayerList();
                while (playerList.Count() > 0)
                {
                                   
                    if (!detected)
                    {
                        Logging.Write("Afk: Player detected. Waiting..");
                        detected = true;
                        detectedTime = DateTime.Now;
                        WoWMovement.MoveStop();
                    }

                    if (detectedTime.Minute < (DateTime.Now.Minute - waitTime))
                    {
                        Logging.Write("Afk: Logging out");
                        Lua.DoString("ForceQuit()");

                    }
                    updatePlayerList();
                    Thread.Sleep(1);

                }

                if (detected)
                    Logging.Write("Afk: Player gone. Resuming..");
                detected = false;
            }    
            

        }

        private static void updatePlayerList()
        {
            ObjectManager.Update();
            playerList = ObjectManager.GetObjectsOfType<WoWObject>(true, true).Where(o =>
                    o != null && o.IsValid &&  (o.GetType() == typeof(WoWPlayer))).ToList();
            
        }




    }
 
never ever force honorbuddy to sleep like that. the use of sleeps are bad.
have you tried using the WaitTimer Api?
Styx.Helpers.WaitTimer.WaitTimer(System.TimeSpan)
 
thx for the reply.
So a timer could replace the sleep call which in my example isnt really needed anyways but what about the loop, is it ok to use it like that?
 
dont use while loops with sleeps in them
make it so when it raches the point where your like "here are the conditions i want it to wait"
make a bool, if the bool is true then return, and have that at the root of the pulse. (make sense)
Code:
Pulse()
{
      if(Wait())
      {
      return;
      }
}
public bool Wait()
{
if(!Me.Combat && PlayersNear)
{
return true;
}
return false;
}
something like that.
 
Last edited:
well, i can only see that working with a loop since pulse will return when it reaches the end either way. So id have to call it like this: while(Wait()); which is the same code I already had although more structured. But i cant really think of any other way to do it so maybe its fine. 6am so i better get some sleep. Thanks a lot for the help! feel free to share any other ideas or clarify if i misunderstood you somehow
 
have i told you my ideas about how awesome it would be it would be to eat a twinkie thats thirty-five feet long, weighing approximately six hundred pounds.
 
Back
Top