Jump to content

Execute code if in combat but no spells have been cast for x time


Recommended Posts

Due to the MoP client continously breaking, I am looking for ways to reliably do a ReloadUI() to fix it, as a work around.

Unfortunately, when this occurs, sometimes my pet is enough to kill my targets, and the bot never dies. So a simple reload after dying isn't enough.

Therefore I'm looking for a more reliable way. One idea is to execute the Lua code, if combat has been going on for 5+ seconds, and no spell has been cast by the bot.
I wish there was a more reliable way, but I haven't really noticed anything, except that when I restart the bot without reloading the UI, it will say that all movement keys are unbound.

Any help (like code examples) is appreciated.

i would implent the check in a pulse method(runs every x seconds), add stopwatch and attach luaevents that reads your combat actions.

If a spell was cast it resets your stopwatch (maybe attach also "PLAYER_ENTER_COMBAT" & "PLAYER_LEAVE_COMBAT") to control itself.

Here how it could look like:

    private System.Diagnostics.Stopwatch ActionTimer;



    public void Initialize()
    {
        //...
        EventsLuaWithArgs.OnEventsLuaWithArgs += Events;
        EventsLua.AttachEventLua(LuaEventsId.PLAYER_ENTER_COMBAT, m => Event_PLAYER_ENTER_COMBAT());
        EventsLua.AttachEventLua(LuaEventsId.PLAYER_LEAVE_COMBAT, m => Event_PLAYER_LEAVE_COMBAT());
    }



    public void Events(LuaEventsId id, List<string> args)
    {
        //everytime something happens it will write it here
        //for e.g. try to cast a spell and lookup which args was used
        for (int i = 0; i < 11; i++)
        {
            Logging.Write("\nArg"+i+" contains: "+args[i]);
        }

        //example
        if (args[0] == "player" 
            && (args[2] == "SPELL1") || (args[2] == "SPELL2"))  //arg[0] is probably fine but check args[2] if it contains any spellname
        {
            if (ObjectManager.Me.InCombat)
            {
                Logging.Write("reset stopwatch");
                ActionTimer.Reset();
                if (!ActionTimer.IsRunning)
                    ActionTimer.Start();
            }
        }
    }


    public void Pulse()//or any other method thats ticks every x seconds
    {
        if (ActionTimer.ElapsedMilliseconds >= 5000)
        {
            ActionTimer.Reset();
            Lua.LuaDoString("RunMacroText('/reload')");
        }
    }


    public void Event_PLAYER_ENTER_COMBAT()
    {
        ActionTimer.Reset();
        ActionTimer.Start();
    }


    public void Event_PLAYER_LEAVE_COMBAT()
    {
        ActionTimer.Reset();
        ActionTimer.Stop();
    }

 

 

 

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
×
×
  • Create New...