Public Macros Help on a basic Autofollow/Assist .mac
Reply
Help on a basic Autofollow/Assist .mac
First off I'd like to say wonderful website.

Ok... so please excuse my extreme basic knowledge of coding and understanding of scripting. So after about 8 hours of trial and error with utilizing other .mac's I've seen, I've tried to develop a .mac on my own which basically follows the character I have chosen, then will assist him and run to the mob and spam their multibind, then when no more targets exist, goes back to following. So far I have been about 90% successful with what I wrote, however I have encountered a problem and have tried countless way to remedy it with no luck.

The Successes:
-Autofollow function works fine
-Assist and running to the mob works fine
-The spamming of the multibind works fine
-Re-Following resumes just fine

The Problem:
-The multibind continues to spam while Autofollowing the character

Below is the .mac I have written, no joke it took me 8 hours to figure it out up to this point, don't laugh :-P
-----------------------------------------------------------------------

Macro
More +
#turbo
Sub Main
:Main_Loop
/call Assist
/goto :Main_Loop

Sub Assist
      /assist Toonname      /if (${Target.Distance}>15) /keypress up hold
      /if (${Target.Distance}<15) /keypress up
      /face fast
      /if (${Target.PctHPs} > 10) /keypress Num_3
      /delay 1
   /if (!${Target.ID}) /call Follow
/return


Sub Follow
      /target Toonname      /if (${Target.Distance}>15) /keypress up hold
      /if (${Target.Distance}<15) /keypress up
      /face fast
      /delay 1
   /if (!${Target.ID}) /goto :Main_Loop
/return


-----------------------------------------------------------------------

I thoroughly enjoy figuring things out on my own, however I have tried to rewrite this what feels like a 1000 times with no luck in figuring out how to get the 'Follower' to not spam his multibind on the PC he is following. The rewriting either causes it to not function properly, or just not function at all. This is by far the most 'working' form of it I have been able to come up with.

Any expertise on this issue would be greatly appreciated, thank you for your time.

Mod edit: formatting
Mon Feb 26, 2018 4:04 pm
8 hours isn’t so bad for getting started, and it looks like you’ve got some experience already. Most new folks don’t indent. While it’ll work without it, it’s a best practice to always have a /return even for Sub Main:

Macro
More +
#turbo

Sub Main
   :Main_Loop
      /call Assist
   /goto :Main_Loop
/return
Sub Assist
      /assist Toonname
      /if (${Target.Distance}>15) /keypress up hold
      /if (${Target.Distance}<15) /keypress up
      /face fast
      /if (${Target.PctHPs} > 10) /keypress Num_3
      /delay 1
      /if (!${Target.ID}) /call Follow
/return


Sub Follow
      /target Toonname
      /if (${Target.Distance}>15) /keypress up hold
      /if (${Target.Distance}<15) /keypress up
      /face fast
      /delay 1
      /if (!${Target.ID}) /goto :Main_Loop
/return


This is a good exercise for learning to script, but once you’ve got it working you should check out mq2moveutils and mq2melee. They have this functionality with a single command.

The /return at the end of a Sub will send program flow back to the part of the program that called it. It’s also a good idea to limit the /goto to doing loops only. If your leaning on it to send program flow all around the code, things start to get very confusing. So the return at the end of Sub Follow will send the program flow back to the end of Sub Assist. The return in Sub Assist will send the flow back to Sub Main. The goto at the end of Sub Follow basically makes a loop but it’s looping across all three Subs. Try to limit the loops to be just inside of one Sub.

So when it starts it immediately calls Sub Assist. It assist Toonname, runs to the target and hits multi bind. You still have a target so it skips the /if, and continues on to /return. That sends you back to Sub Main and it all happens again.

Once the things dies, the next iteration it jumps to Sub Assist again. Assist Toonname and gets nothing (cause it’s dead). Then it tries to move forward and face nothing since you don’t have a target. Then it does multi bind (this is the erroneous cast that’s giving you problems. Then your /if works this time so it jumps to Sub Follow. When Follow gets to the end, the /if doesn’t fire since you have Toonname targeted. But the /return does fire, and sends you back to the line that called Sub Follow, which was the last line of Sub Assist. The next line of code is the /return for Sub Assist. That /return sends you back to the line that called Sub Assist, which is Sub Main. The next line executes, which is /goto :Main_Loop so it all starts over and does everything in this paragraph again.

And if/else is a good way to do one thing or another exclusively. I would try something like this, no guarantee this is right, I don’t have EQ loaded right now to test it. But it’s maybe in the direction you’re wanting to go at least.

Macro
More +
#turbo

Sub Main
        :Main_Loop
                /assist Toonname
                /if (${Target.ID}) {
                        | if Toonname has a target, go for it
                        /call Assist
                } else {
                        | else toonname doesn’t have a target, so we follow him instead
                        /call Follow
                }
        /goto :Main_Loop
/return

|move towards the target and cast multibind
Sub Assist  
      /face fast
      /if (${Target.Distance}>15) /keypress up hold
      /if (${Target.Distance}<15) /keypress up
      /if (${Target.PctHPs} > 10) /keypress Num_3
      /delay 1
/return

| target Toonname and follow him
Sub Follow
      /target Toonname
      /face fast
      /if (${Target.Distance}>15) /keypress up hold
      /if (${Target.Distance}<15) /keypress up
      /delay 1
/return


There’s some other things you can do, but it’ll be good practice to work it out :)

Edit: ugh, sorry Tab indents on iOS are apparently massive
Mon Feb 26, 2018 5:28 pm
Project Lead
BTW, I think /delay 1 is 1 millisecond. If you wanted one second it’s /delay 1s

You can also delay with a break condition, it’s something like /delay 10s ${Target.ID}. It stops the delay as soon as the condition is met. So that would delay until you have a target, or 10 seconds—whatever is shortest. You could put that after a /target command so you wait until the targeting is done (not really necessary in this example since targeting automatically waits to finish). It’s a good way to not pause for an unnecessary amount of time. Not related to your script, just something interesting you can do with it.
Tue Feb 27, 2018 6:11 pm
Project Lead
Nice!
Thanks for the help! I ended up coming up with something that worked in the meantime with help from a buddy who knows about this stuff. Thank you for breaking down the lines of code and explaining what they actually do. TBH I had no clue hahaha, I was just doing my best to emulate what I've seen from other seemingly 'professionally' written scripts. This is what ended up working in the meantime to keep from the Multibind spamming on the follow target.

#turbo
Sub Main
:Main_Loop
/call Assist
/goto :Main_Loop

Sub Assist
/assist ToonName
/if (${Target.Distance}>15) /keypress up hold
/if (${Target.Distance}<15) /keypress up
/face fast
/if ((${Target.PctHPs} > 10 )&&(!${Target.Name.Equal[ToonName]})) /keypress Num_3
/delay 1
/if (!${Target.ID}) /call Follow
/return


Sub Follow
/target ToonName
/if (${Target.Distance}>15) /keypress up hold
/if (${Target.Distance}<15) /keypress up
/face fast
/delay 1
/if (!${Target.ID}) /goto :Main_Loop
/return


I plan on implementing your script as well. I would like to explore and learn more on the 'else' commands, and stuff like 'variables' to clean up what would look like excessive/unnecessary script to someone like yourself. Trying to find literature that doesn't read like an alien language to me is proving... difficult, lol.

Thank you for taking the time to respond to this thread! :-)
Tue Mar 06, 2018 1:40 pm
Public Macros Help on a basic Autofollow/Assist .mac
Reply