Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!
Moderator: MacroQuest Developers
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Tue Jan 27, 2004 9:15 pm
I got this macro from a forum in the Macros Depot. It's been developed by Mckorr and Losingteam. I tweaked it some and now it's giving me a message that I cant seem to shake. It spams my MQ screen with "Variable name already defined." Here's the script. I'm pretty new at scripting and kind of picking it up as i go along, so it isnt very wonderful and alot of it may be done wrong. Any help is appreciated.
Code: Select all
|Use of this macro would be /macro assist.mac tankname
#turbo
#Event tankattacking "@Param0 hits"
/declare tankname global
/varset tankname "@Param0"
Sub Main
:MainLoop
/call Event_tankattacking
/goto :MainLoop
Sub Attack
/declare MyXLOC global
/declare MyYLOC global
/declare ObstacleCount global
/declare targetarray array
/varset targetarray(0) "$target(name,clean)"
/varset targetarray(1) $target(level)
/varset targetarray(2) $target(name)
/varset targetarray(3) $target(id)
/assist "@Param0"
/if n $target()=="NULL" /return
/echo Fighting a level @targetarray(1) @targetarray(0)
/face
/call MovetoMob
:CloserAF
/if "$target(id)"!=@targetarray(3) /goto :EndAF
/if n $target(distance)>10 /press up
/if n $target(distance)<10 /press down
/if n $target(distance)<15 /attack on
/if n $target(distance)>15 /attack off
/if n $target(distance)>15 /call MovetoMob
/face fast
|/if n $target(distance)<11 /if n $char(ability,"Bash")>0 /doability "Bash"
|/if n $target(distance)<11 /if n $char(ability,"Kick")>0 /doability "Kick"
|/if n $target(distance)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm"
/goto :CloserAF
:EndAF
/echo The level @targetarray(1) @targetarray(0) is dead...
/sendkey up up
/sendkey up down
/attack off
/varset targetarray(3) 0
/goto :MainLoop
Sub MoveToMob
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/if n $target(distance)<=15 {
/face
/return
}
/sendkey down up
:Movementloop
/varadd ObstacleCount 1
/if $target()=="FALSE" /return
/face
/if n $target(distance)<=10 {
/face
/sendkey up up
/return
}
/if @ObstacleCount>=3 {
/call CheckObstacle
/goto :Movementloop
}
/if n $target(distance)>10 /goto :MovementLoop
/return
Sub CheckObstacle
/if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/return
Sub HitObstacle
/sendkey up up
/sendkey down down
/delay 3
/sendkey up down
/sendkey down ctrl
/if n $rand(99)>50 {
/sendkey down right
} else {
/sendkey down left
}
/delay 5
/sendkey up right
/sendkey up left
/sendkey up ctrl
/sendkey down up
/return
Sub Event_tankattacking
/call Attack
/return
-
Sparky421
- decaying skeleton

- Posts: 7
- Joined: Wed Jan 21, 2004 5:32 pm
Post
by Sparky421 » Tue Jan 27, 2004 9:24 pm
I believe the problem is you need to declare your variables inside Sub Main but outside of the main loop function. Also Im not positive, but you may need to have...
Code: Select all
/declare tankname global
/varset tankname "@Param0"
inside Sub Main also, but since you didn't say that was a problem I'll leave it where it is.
Try this code to stop the spam...
Code: Select all
|Use of this macro would be /macro assist.mac tankname
#turbo
#Event tankattacking "@Param0 hits"
/declare tankname global
/varset tankname "@Param0"
Sub Main
/declare MyXLOC global
/declare MyYLOC global
/declare ObstacleCount global
/declare targetarray array
:MainLoop
/call Event_tankattacking
/goto :MainLoop
Sub Attack
/varset targetarray(0) "$target(name,clean)"
/varset targetarray(1) $target(level)
/varset targetarray(2) $target(name)
/varset targetarray(3) $target(id)
/assist "@Param0"
/if n $target()=="NULL" /return
/echo Fighting a level @targetarray(1) @targetarray(0)
/face
/call MovetoMob
:CloserAF
/if "$target(id)"!=@targetarray(3) /goto :EndAF
/if n $target(distance)>10 /press up
/if n $target(distance)<10 /press down
/if n $target(distance)<15 /attack on
/if n $target(distance)>15 /attack off
/if n $target(distance)>15 /call MovetoMob
/face fast
|/if n $target(distance)<11 /if n $char(ability,"Bash")>0 /doability "Bash"
|/if n $target(distance)<11 /if n $char(ability,"Kick")>0 /doability "Kick"
|/if n $target(distance)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm"
/goto :CloserAF
:EndAF
/echo The level @targetarray(1) @targetarray(0) is dead...
/sendkey up up
/sendkey up down
/attack off
/varset targetarray(3) 0
/goto :MainLoop
Sub MoveToMob
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/if n $target(distance)<=15 {
/face
/return
}
/sendkey down up
:Movementloop
/varadd ObstacleCount 1
/if $target()=="FALSE" /return
/face
/if n $target(distance)<=10 {
/face
/sendkey up up
/return
}
/if @ObstacleCount>=3 {
/call CheckObstacle
/goto :Movementloop
}
/if n $target(distance)>10 /goto :MovementLoop
/return
Sub CheckObstacle
/if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/return
Sub HitObstacle
/sendkey up up
/sendkey down down
/delay 3
/sendkey up down
/sendkey down ctrl
/if n $rand(99)>50 {
/sendkey down right
} else {
/sendkey down left
}
/delay 5
/sendkey up right
/sendkey up left
/sendkey up ctrl
/sendkey down up
/return
Sub Event_tankattacking
/call Attack
/return
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Tue Jan 27, 2004 9:44 pm
Hmm. Didnt do anything.
I think ya took something important out. But i dont think i'm skilled enough to know wut. Hehe

-
dont_know_at_all
- Developer

- Posts: 5450
- Joined: Sun Dec 01, 2002 4:15 am
- Location: Florida, USA
-
Contact:
Post
by dont_know_at_all » Tue Jan 27, 2004 9:49 pm
main is called once.
put all your global declares at the top of main
-
GD
- a snow griffon

- Posts: 353
- Joined: Sat Jun 29, 2002 11:57 pm
Post
by GD » Wed Jan 28, 2004 7:17 am
You have no /return in Sub Main or Sub Attack, but i don't think that'd cause the problem.
Opinions are like assholes, everyone has one, but most of them stink.
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Thu Jan 29, 2004 9:46 pm
Well, i got it to stop spamming me, but now it says "Ending macro: Flow ran into another subroutine. could anyone point out where that might be? I'm getting better but not even sure what that means... here is the script.
Code: Select all
|Use of this macro would be /macro assist.mac tankname
#turbo
#Event tankattacking "points of damage"
/declare MyXLOC global
/declare MyYLOC global
/declare ObstacleCount global
/declare tankname global
/varset tankname "@Param0"
Sub Main
:MainLoop
/assist "tankname"
/if $target()=="TRUE" { /call Attack
} else {
/goto :MainLoop }
Sub Attack
/declare targetarray array
/varset targetarray(0) "$target(name,clean)"
/varset targetarray(1) $target(level)
/varset targetarray(2) $target(name)
/varset targetarray(3) $target(id)
/if n $target()=="NULL" /return
/echo Fighting a level @targetarray(1) @targetarray(0)
/face
/call MovetoMob
:CloserAF
/if "$target(id)"!=@targetarray(3) /goto :EndAF
/if n $target(distance)>10 /press up
/if n $target(distance)<10 /press down
/if n $target(distance)<15 /attack on
/if n $target(distance)>15 /attack off
/if n $target(distance)>15 /call MovetoMob
/face fast
|/if n $target(distance)<11 /if n $char(ability,"Bash")>0 /doability "Bash"
|/if n $target(distance)<11 /if n $char(ability,"Kick")>0 /doability "Kick"
|/if n $target(distance)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm"
/goto :CloserAF
:EndAF
/echo The level @targetarray(1) @targetarray(0) is dead...
/sendkey up up
/sendkey up down
/attack off
/varset targetarray(3) 0
/goto :MainLoop
Sub MoveToMob
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/if n $target(distance)<=15 {
/face
/return
}
/sendkey down up
:Movementloop
/varadd ObstacleCount 1
/if $target()=="FALSE" /return
/face
/if n $target(distance)<=10 {
/face
/sendkey up up
/return
}
/if @ObstacleCount>=3 {
/call CheckObstacle
/goto :Movementloop
}
/if n $target(distance)>10 /goto :MovementLoop
/return
Sub CheckObstacle
/if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/return
Sub HitObstacle
/sendkey up up
/sendkey down down
/delay 3
/sendkey up down
/sendkey down ctrl
/if n $rand(99)>50 {
/sendkey down right
} else {
/sendkey down left
}
/delay 5
/sendkey up right
/sendkey up left
/sendkey up ctrl
/sendkey down up
/return
Sub Event_tankattacking
/call Attack
/return
-
ml2517
- a grimling bloodguard

- Posts: 1216
- Joined: Wed Nov 12, 2003 1:12 am
Post
by ml2517 » Thu Jan 29, 2004 10:00 pm
Found several mistakes, fixed them but didn't test it, try this:
* see below
Last edited by
ml2517 on Thu Jan 29, 2004 10:38 pm, edited 1 time in total.
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Thu Jan 29, 2004 10:25 pm
I ran the script, and when the tank was attacking, it ended.
Hmm.. Mabye ya put in some kind of /end-like format in there so it just ends the mac when it gets a target?
If ya could look at it one more time, that'd be great, but ima turn in for the night, so i cant really test it.
Thanks

-
ml2517
- a grimling bloodguard

- Posts: 1216
- Joined: Wed Nov 12, 2003 1:12 am
Post
by ml2517 » Thu Jan 29, 2004 10:37 pm
Ok found more errors and actually fired it up this time:
Code: Select all
| Use of this macro would be /macro assist.mac tankname
#turbo
#Event tankattacking "points of damage"
Sub Main
/declare MyXLOC global
/declare MyYLOC global
/declare ObstacleCount global
/declare tankname global
/declare targetarray array
/varset tankname "@Param0"
:MainLoop
/assist @tankname
/delay 5
/if $target()=="TRUE" {
/call Attack
}
/goto :MainLoop
/return
Sub Attack
/varset targetarray(0) "$target(name,clean)"
/varset targetarray(1) $target(level)
/varset targetarray(2) $target(name)
/varset targetarray(3) $target(id)
/if $target()=="FALSE" /return
/echo Fighting a level @targetarray(1) @targetarray(0)
/face
/call MovetoMob
:CloserAF
/if n $target(id)!=@targetarray(3) /goto :EndAF
/if n $target(distance)>12 /press up
/if n $target(distance)<8 /press down
/if n $target(distance)<15 /attack on
/if n $target(distance)>15 /attack off
/if n $target(distance)>15 /call MovetoMob
/face fast
|/if n $target(distance)<11 /if n $char(ability,"Bash")>0 /doability "Bash"
|/if n $target(distance)<11 /if n $char(ability,"Kick")>0 /doability "Kick"
|/if n $target(distance)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm"
/goto :CloserAF
:EndAF
/echo The level @targetarray(1) @targetarray(0) is dead...
/sendkey up up
/sendkey up down
/attack off
/varset targetarray(3) 0
/return
Sub MoveToMob
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/if n $target(distance)<=15 {
/face
/return
}
/sendkey down up
:Movementloop
/varadd ObstacleCount 1
/if $target()=="FALSE" /return
/face
/if n $target(distance)<=10 {
/face
/sendkey up up
/return
}
/if n @ObstacleCount>=3 {
/call CheckObstacle
/goto :Movementloop
}
/if n $target(distance)>10 /goto :MovementLoop
/return
Sub CheckObstacle
/if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle
/varset MyXLOC $char(x)
/varset MyYLOC $char(y)
/varset ObstacleCount 0
/return
Sub HitObstacle
/sendkey up up
/sendkey down down
/delay 3
/sendkey up down
/sendkey down ctrl
/if n $rand(99)>50 {
/sendkey down right
} else {
/sendkey down left
}
/delay 5
/sendkey up right
/sendkey up left
/sendkey up ctrl
/sendkey down up
/return
Sub Event_tankattacking
/call Attack
/return
-
Mckorr
- Developer

- Posts: 2326
- Joined: Fri Oct 18, 2002 1:16 pm
- Location: Texas
Post
by Mckorr » Fri Jan 30, 2004 8:54 am
Frankly you are doing this the hard way.
Get autofight.inc.
Code: Select all
#turbo
#include autofight.inc
sub Main
:MainLoop
/assist @Param0
/delay 5
/if $target()=="TRUE" {
/call Attack
}
/goto :MainLoop
/endmacro
Name it assist.mac. Call it with /macro assist Tank.
The delays are necessary to make sure /assist targets correctly.
This way you don't have to reinvent the wheel, the attack routines are already in place and you shouldn't have any conflicts.
Use #include files! Your 50+ line macro just became 11 lines :)
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Fri Jan 30, 2004 10:21 am
Quick question for ya, Mckorr. :)
When it /call Attack's... where does it get the Sub Attack from? the inc file?
-
Mckorr
- Developer

- Posts: 2326
- Joined: Fri Oct 18, 2002 1:16 pm
- Location: Texas
Post
by Mckorr » Fri Jan 30, 2004 12:31 pm
Yes. If you look at autofight.inc, you'll notice that the "main" loop is called Attack.
When you use #include autofight.inc, you can call subroutines in the included file just like they were a part of your own macro. In this case, /call Attack tells it to use the Attack subroutine from the autofight.inc file, and that Attack routine calls everything else in autofight.
Using multiple include files allows you to build macros from existing "modules". I have autofight.inc, autoloot.inc, etc. so I never have to rewrite, or even copy and past, my fighting and looting subroutines over and over again.
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Fri Jan 30, 2004 7:06 pm
Hehe, that's cool. Thanks for da info and the great mac/inc files!
8)
-
C247
- orc pawn

- Posts: 21
- Joined: Tue Jan 27, 2004 9:09 pm
Post
by C247 » Sat Jan 31, 2004 12:01 pm
Doh, I tested it this morning, and I moved back step by step and got flooded with "There were no matches for (0-100) any look"
But it seemed everything else kind of worked right.
Was using the inc file and everything.

-
Mckorr
- Developer

- Posts: 2326
- Joined: Fri Oct 18, 2002 1:16 pm
- Location: Texas
Post
by Mckorr » Mon Feb 02, 2004 2:16 pm
autofight.inc pretty much won't allow you to move away from a target once the attack routine is called. It's very bulldog, once it bites it won't let go.
Now what you CAN do with it is strafe. Hold CTRL and press left or right arrow and you will move sideways, maintaining your facing towards the target. You circle around the target this way.
What it sounds like you did was hit ESC in there someplace and lost your target, which will give you a lot of error messages.