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

[CB] RunMacro

axazol

New Member
Joined
Jun 27, 2010
Messages
308
Reaction score
8
PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using Styx.Database;
using Styx.Helpers;
using Styx.Logic.BehaviorTree;
using Styx.Logic.Inventory.Frames.Gossip;
using Styx.Logic.Pathing;
using Styx.Logic.Questing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using TreeSharp;
using Action = TreeSharp.Action;

namespace Styx.Bot.Quest_Behaviors
{
    /// 
    /// RunMacro by AxaZol
    /// Allows you to run custom macro at selected location.
    /// ##Syntax##
    /// Macro: Macro body.
    /// NumOfTimes: Number of times to interact with object.
    /// [Optional] WaitTime: Time in msec to wait after each macro usage.
    /// 
    public class RunMacro : CustomForcedBehavior
    {
        public RunMacro(Dictionary args)
            : base(args)
        {
            bool error = false;

            if (!Args.ContainsKey("Macro"))
            {
                Logging.Write("Could not find attribute 'Macro' in RunMacro behavior! please check your profile!");
                error = true;
            }
            
            string macro = Args["Macro"];

            int numOfTimes;
            if (!int.TryParse(Args["NumOfTimes"], out numOfTimes))
            {
                Logging.Write("Parsing attribute 'NumOfTimes' in RunMacro behavior failed! please check your profile!");
                error = true;
            }
            
            if(Args.ContainsKey("WaitTime"))
            {
                int waitTime;
                int.TryParse(Args["WaitTime"], out waitTime);
                WaitTime = waitTime != 0 ? waitTime : 1500;
            }
            
            if (error)
                TreeRoot.Stop();

            Macro = macro;
            NumOfTimes = numOfTimes;
        }

        public string Macro { get; set; }
        public int NumOfTimes { get; set; }        
        public int WaitTime { get; private set; }

        #region Overrides of CustomForcedBehavior

        private bool _isDone;
        public override bool IsDone
        {
            get
            {
                return _isDone;
            }
        }

        public override void OnStart()
        {
            TreeRoot.GoalText = string.Format("Run Macro {0} Times", NumOfTimes);
            for (int counter = 1; counter <= NumOfTimes; counter++)
            {
                TreeRoot.StatusText = string.Format("Run Macro {0} Times", NumOfTimes);
                Lua.DoString(string.Format("RunMacroText(\"{0}\")", Macro), 0);
                Thread.Sleep(WaitTime);
            };
            _isDone = true;
        }

        #endregion
    }
}
Usage:
PHP:
<CustomBehavior File="RunMacro"
    Macro="/wave\n/dance"
    NumOfTimes="1"
    WaitTime="2000" />
Tip: For multiline macros use "\n" seporator.

UPD: chinajade improvement
 

Attachments

Last edited:
I want your babies....just sayin.


I'll test it out now. thank you!
 
Is it possible to turn in quests that require clicking on your quest log with a macro. If so this is a HUGE deal.
 
Axazol,

The power and simplicity of this behavior is a stroke of genius! Thank you!

One minor note, the code that reads:
Code:
            if (error)
                Thread.CurrentThread.Abort();

should be the following instead...
Code:
            if (error)
                TreeRoot.Stop();

Any chance of your contributing this to the HBcore?

thanks again!
chinajade
 
Is it possible to turn in quests that require clicking on your quest log with a macro. If so this is a HUGE deal.
If you askin about quests what popups for completition at quest tracker, i think this is not possible until the HBcore will not support the delivery and reception of quests such way in
and <turnin> tags in quest profile.

Any chance of your contributing this to the HBcore?
Possible, but there is not for me to decide. ^^
Anyone can use all CB, what i've posted here for any self purpose with out my agreement.
</turnin></pickup>
 
Last edited:
Axazol said:
Possible, but there is not for me to decide.

Well, it kinda is--as its your work. You would have to donate it to the core, or give them permission to use it. I'm not sure how these things are worked out, but I've seen it done several times before. They could always write one from scratch I guess, but here's one that works well and is proven. :D


cheers,
chinajade
 
Direct answer: I'm allow to use all my CB in any cases of quest profile making or implement it to the Core.
 
Accept Quest from item if has item and not on the quest

Code:
<If Condition="(HasItem(55243)) &amp;&amp; (!HasQuest(25736))" >
<CustomBehavior File="RunMacro"
    Macro="/use Floodsurge Core \n/script AcceptQuest() "
    NumOfTimes="1"
    WaitTime="2000" /> 
</If>

Replace the ItemID and QuestId, aswell as the object name (maybe you can use by id but im not sure).
 
Ok so i have a rough (Aka pretty awful way of doing this) way to hand in quests via quest log That requires 2 macros;

Number one *Note this is dependent on the number of quests you have in your log and is currently set to slot one, the order of quests is dependent on your quest pickup order you need to replace the button number ("2") with its postion + 1 (as the name plate also counts as a button):
Code:
<If Condition="HasQuest(25736)" >
<CustomBehavior File="RunMacro"
    Macro="/click QuestLogScrollFrameButton2\n/click QuestLogFrameCompleteButton"
    NumOfTimes="1"
    WaitTime="2000" /> 
</If>

Code:
<If Condition="HasQuest(25736)" >
<CustomBehavior File="RunMacro"
    Macro="/run SelectGossipAvailableQuest(1)\n/run SelectGossipActiveQuest(1)\n/run CompleteQuest()\n/run SelectGossipOption(1)\n/run AcceptQuest()\n/run GetQuestReward(1)"
    NumOfTimes="1"
    WaitTime="2000" /> 
</If>
 
You could maybe do a standalone plug-in that pages through all the button numbers?
 
Accept Quest from item if has item and not on the quest
<if condition="(HasItem(55243)) && (!HasQuest(25736))">
In cases with high latency i recomend split it in to two macro with 2000ms or more delay in first.
</if>
You could maybe do a standalone plug-in that pages through all the button numbers?
It depends on many aspects of profile and i think is better to learn WoW API than makes alot of "onetime-usage" behaviors.
 
Last edited:
In cases with high latency i recomend split it in to two macro with 2000ms or more delay in first.
.

Yea your right, didn't work even with 50ms.

The other might be a very useful one tho for being able to turn in quests to your log aka the new stv ones.
 
Yep, I also use it for handin quests. I allready asked a CB for macros a while ago but no one replied for it. So I asked axazol to make one. I didn't even think of using accepting quests and such after I used it for the quest.
With macro's you can do almost everything :D
 
I want to pipe in and say Sleep() is bad. HB is a pulse based application and using sleep will lock up the entire thread for that duration. That means there won't be responses to incoming events such as combat, or even Tripwire during that duration of the sleep, so if possible stay away from the sleep()!. There's 2 alternatives, use a Stopwatch and return if the elapsed time is less then the wait time. or use the CreateBehavior and using the wait action.
 
Last edited:
Ther is no problem to use alternatives, i just dont know how it'll work when bot get agro on wait timer. So only one alternative looks good - behavior.
 
With AxaZol's permission, I've moved this behavior into the Wiki. You can find the page for it here...
[wiki]Honorbuddy Custom Behavior: RunMacro[/wiki]


You can also download the behavior from that location, and it is now the Community's to keep updated.

cheers & thanks again AxaZol!
chinajade
 
Back
Top