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();
}
}






