Macro Assist

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

Iceassassin
a lesser mummy
a lesser mummy
Posts: 49
Joined: Tue Nov 05, 2002 11:40 am

Macro Assist

Post by Iceassassin » Mon Nov 25, 2002 6:21 pm

This is a macro I found on the boards...
However, every time, it runs for NO REASON! I just can't seem to find the wrong part...

P.S Added a twisting macro in there AND waiting.mac

Code: Select all

|fight.mac 
|Automated fight, hunt, group bot for pure melee 

#include routines.mac 

#define HateListLen v21 
#define NoAttack v42 
#define NoLOS v38 
#define Attacker v60 
#define AttackedMe v56 
#define SONG1 t1 
#define SONG2 t2 
#define SONG3 t3 
#define SONG4 t4 

#chat tell 
#event HitsYou "YOU for"
#event MissedNote "You miss a note, bringing your song to a close!" 
#event Stunned "You are unstunned." 

sub main


   /zapvars 
    
   /if n $p0==0 /if "$target()"=="FALSE" { 
      /echo No Target and No Controller(s)! 
      /echo Setting up Hunting Loop! 
      /varset v20 42 
      /call Hunt       
      /return 
      } 
   /if n $p0==0 /if "$target(type)"=="PC" { 
      /echo No controller specified! Trying Current Target! 
      /varset v1 "$target(name)" 
      /echo $v1 is the Controller! 
      /call Follow 
      } 
   /if n $p0!=0 { 
      /varset v1 $p0 
      /echo $v1 is the Controller! 
      /call Follow 
      } 
   /if "$target(type)"=="NPC" { 
      /echo Target is NPC!  Attacking.... 
      /varset v20 42 
      /call Attack 
      } 
   /if "$target(type)"=="Corpse" { 
      /echo Target is Corpse!  Looting.... 
      /varset v20 42 
      /call Loot 
     /goto :mainloop
/return 

sub Hunt 
   :huntloop 
   /doevents 
      /if n $char(ability,"Sense Heading")>0 /doability 4 
          /if "$target(type)"=="Corpse" /call Loot 
      /if "$target(type)"=="NPC" /call Attack 
         /if "$target()"=="FALSE" /if n $char(hp,pct)<20 /call Rest 
        /if "$target()"=="FALSE" /target npc range $calc($char(level)-2) $char(level) radius 1000 
        /delay 5 
        /if "$target()"=="FALSE" { 
           /echo No Targets In Range!  Waiting 10 seconds... 
           /delay 10s 
           } 
      /goto :huntloop 
/return 

sub Follow 
   /echo Following and Assisting "$target(name)"! 
   /attack off 
   :followloop 
      /doevents 
      /if n $v20!=42 /if n $t0<=0 /call Assist 
      /if "$target(type)"=="Corpse" /target $v1 
      /if "$target(name)"=="$char(name)" /target $v1 
      /if "$target()"=="FALSE" /target $v1 
      /if "$target(type)"=="NPC" /call Attack 
      /if n $target(distance)>25 /sendkey down up 
      /if n $target(distance)<20 /sendkey up up 
      /face fast nopredict 
      /delay 50
      /goto :followloop 
/return 

sub Wait 
   :idleloop 
   /doevents 
      /delay 10 
      /if n $char(ability,"Sense Heading")>0 /doability 4
      /goto :idleloop 
/return 

sub Assist 
   /varset t0 3s 
   /assist $v1 
/return 

sub Attack 
   /echo Fighting $target(name,clean). It is level $target(level). 
   /varset v3 "$target(id)" 
   /varset v4 "$target(name,clean)" 
   :attackloop 
      |Check Events 
      /doevents 
      
      |Check Assist, if necessary 
      /if n "$v20"!="42" /if n $t0<=0 /call Assist 
      
      |Check Health 
      |/if n $char(hp,pct)<20 /call Run 

      |Don't Attack Until In Range 
      /if n $target(distance)<=14 /attack on 
      /if n $target(distance)>=20 /attack off 

      |Get Into Range 
      /if n $target(distance)>15 /sendkey down up 
      /if n $target(distance)<10 /sendkey up up 
      /face fast nopredict 

      |If we're too close back up 
      /if n $NoLOS==1 { 
         /echo Cannot see, backing up 
         /face nopredict 
         /sendkey down down 
         /delay 2 
         /sendkey up down 
         /varset NoLOS 0 
         /delay 3 
      } 
      
      |Do Abilities 
      /if n $char(ability,"Sense Heading")>0 /doability 1
/doability 4
/doability 1
/attack off
/doability 2
/attack on
/doability 3
/doability 5
/doability 6
      
      |Check if target is Dead 
      /if n $target(id)!="$v3" /goto :EndAttack 
      /goto :attackloop 
      


:EndAttack 
  /echo $v4 is dead 
  /delay 10 
  /attack off 
  /varset v0 0 
  /target corpse radius 50 
/return 

sub Event_CannotSee 
   /varset NoLOS 1 
/return 

sub Event_HitsYou 
   /varset AttackedMe 1 
   /varset v10 "$left($calc($instr("YOU","$p0")-1),"$p0")" 
   /varset v11 $strlen("$v10") 
    :WalkString 
       /if "$mid($v11,1,"$v10")"==" " { 
          /varset v12 $v11 
          /goto :DoneWalkString 
         } 
   /varsub v11 1 
   /delay 0 
   /goto :WalkString 
    :DoneWalkString 
   /varset Attacker "$left($v12,"$v10")" 
   /echo Attacked by $Attacker! 
   /echo "$id("$Attacker")" 

    
   | Fippys Old Stuff 
   |/if "$combat"=="TRUE" /goto :StillEngaged 
   | /varset AttackedMe 1 
   | /varset v10 "$left($calc($instr("YOU","$p0")-1),"$p0")" 
   | /varset v11 $strlen("$v10") 
   | :WalkString 
   |    /if "$mid($v11,1,"$v10")"==" " { 
   |       /varset v12 $v11 
   |       /goto :DoneWalkString 
   |   } 
   | /varsub v11 1 
   | /delay 0 
   | /goto :WalkString 
   | :DoneWalkString 
   |/varset Attacker "$left($v12,"$v10")" 
   |/if "$Attacker"~~"$target(name,clean) { 
   |   /varset AttackedMe 0 
   |   /goto :StillEngaged 
   |/echo Attacked by $Attacker! 
   |/target $Attacker 
   | I need a way to get the new aggro's target(id) and this doesn't seem to work... 
   |/delay 5 
   |/call AddToHateList $target(id) 
   |/target $v4 
   |:StillEngaged 
    
/return 

Sub Loot 
   /if n $target(distance)>75 /goto :continue 
   /stand 
   /echo Looting $target(name,clean) for anything that weighs less then 5 and has value of more then $p1 copper... 
   /face 
   /if n $target(distance)<15 /goto :CloseEnough 
   /call AutoRun 1 
   /varset t0 3m 
   :CloserAL 
   /face 
   /delay 0 
   /if n $target(distance)>14 /if n $t0>0 /goto :CloserAL 

   :CloseEnough 
   /call AutoRun 0 
   /loot 
   /Delay 10 
   /for v10 0 to 9 
      /Delay 5 
      /click left corpse $v10 
      /Delay 10 
      /if "$cursor(name)"=="NULL" /goto :continue 
      /if "$target(name)"~~$char(name) /click left auto 
      /if n $cursor(weight)>5 /click left destroy 
      /if n $cursor(value)<100 /click left destroy 
      /if "$cursor(name)"!="NULL" /echo looting "$cursor(name)". it has a value of "$cursor(value)"cp. 
      /if n $cursor(value)>9 /click left auto 
      /delay 4 
      /delay $rand(5) 
   /next v10 
   :continue 
   /delay 5 
   /delay $rand(5) 
   /press esc 
/return 

sub Event_Chat 
   /echo Recieved Tell from $p1! 
   /varset v2 "$p1" 
   /varset v3 "$p2" 
   /call Commands 
   /if "$p1"=="$v1" /call Commands 
   /if "$p1"!="$v1" { 
      /mqlog $p0 from $p1: $p2 
      /beep 
      } 
/return 

sub Commands 
/echo Got to Commands sub! 
/if "$v3"~~"attack" { 
   /call Assist 
   /r Attacking your target! 
   /echo $v2 ordered me to attack his target! 
   /call Attack 
   /return 
   } 
/if "$v3"~~"follow" { 
   /target $v2 
   /r Following You! 
   /echo $v2 ordered me to follow him! 
   /call Follow 
   /return 
   } 
/if "$v3"~~"wait" { 
   /r I'll wait here... 
   /echo $v2 ordered me to wait! 
   /call Wait    
   /return 
   } 
/if "$v3"~~"rest" { 
   /echo $v2 ordered me to rest! 
   /delay 1s 
   /r Ok, resting... 
   /call Rest 
/return 

sub Run 
   /echo We're in trouble, lets split... 
   /attack off 
   /press esc 
   /target npc guard 
   /call GotoTarg "$target(name)" 
   /call Rest 
/return 

sub Rest 
/echo Resting... 
/delay 1s 
/sit on 
   :Rest 
      | Check if something has aggroed and attack it if it has. 
      /doevents 
      /if n $AttackedMe==1 { 
         /echo Aggro While Resting! 
         /sit off 
         /goto :NoRest 
      } 
      /delay 5 
      /if n $char(ability,"Sense Heading")>0 /doability sense 
      /if n $char(hp,pct)<50 /goto :Rest 
   /echo Hps at $char(hp,pct) Off hunting again 
} 
:NoRest 
/stand 
/return 

Sub DisplayHateList 
   | Spit out your hate list to the screen 
   /echo 
   /echo ListLen: $HateListLen 
   /echo --------------------- 
   /for v95 1 to $HateListLen 
     /target id $a(0,$v95) 
     /echo $v95 ID: $a(0,$v95) 
     /echo $v95 LV: $target(level) 
     /echo $v95 NM: $target(name) 
     /echo --------------------- 
   /next v95 
   /echo 
/return 

Sub AddToHateList 
   | v90 - Hold ID 
   | v91 - Hold Lvl 
   | v92 - Current HateList Level 
   | v93 - Swap ID 
   | v95 - For Loop Var 

   | Set the new ID into the hold var 
   /varset v90 $p0 
   /echo Adding $v90 to HateList 

   | Get his level into v91 
   /target id $v90 
        /varset v91 $target(level) 

   | If he's not the first, make sure he's put into the right place. 
   | We want to order out hate list in order of strongest mob 
    
   /if $HateListLen>1 { 
     /for v95 1 to $HateListLen 
        
       | Check the level of the current mob 
       /target id $a(0,$HateListLen) 
       /varset v92 $target(level) 
        
       /if $v92<$v91 {        | New guy is stronger, time to reorder 
         /varset v93 $a(0,$v95) | Store old one to Swap ID 
         /varset a(0,$v95) $v90 | Put stronger guy in list 
         /varset v90 $v93        | Put old one into Hold ID 
         /varset v91 $v92        | Old level into Hold Lvl 
       } 
     /next v95 
      
     | Add whats left in Hold ID to the list 
     /varcalc HateListLen $HateListLen+1 
     /varset a(0,$HateListLen) $v90 
   } else { 
     /varcalc HateListLen $HateListLen+1 
     /varset a(0,$HateListLen) $p0 
   } 

Sub Sing
/call sing1 
:Mainloop 
/doevents 
/goto :huntloop


Sub Sing1 
:1 
/varset v0 1 
/stop song 
/delay 2 
/cast 1
/varset SONG1 50s 
/varset SONG2 31 
/goto :Mainloop 


Sub Sing2 
:2 
/varset v0 2 
/stop song 
/delay 2 
/cast 2
|/click left hotkey 6 
|/click left hotkey 8 
|/click left hotkey 9 
|/click left hotkey 7 
/varset SONG2 50s 
/varset SONG3 31 
/goto :Mainloop 


Sub Sing3 
:3 
/varset v0 3 
/stop song 
/delay 2 
/cast 3 
|/click left hotkey 7 
|/click left hotkey 9 
|/click left hotkey 8 
|/click left hotkey 6 
/varset SONG3 50s 
/varset SONG4 31 
/goto :Mainloop 


Sub Sing4 
:4 
/varset v0 4 
/stop song 
/delay 2 
/cast 4 
/varset SONG4 50s 
/varset SONG1 31 
/goto :Mainloop 


Sub Event_Timer 

/if n $SONG1==0 /call Sing1 
/if n $SONG2==0 /call Sing2 
/if n $SONG3==0 /call Sing3 
/if n $SONG4==0 /call Sing4 
/doevents 
/goto :Mainloop 

Sub Event_Missednote 
/varset SONG1 50s 
/varset SONG2 50s 
/varset SONG3 50s 
/varset SONG4 50s 
/goto :$v0 


Sub Event_Stunned 
/varset SONG1 50s 
/varset SONG2 50s 
/varset SONG3 50s 
/varset SONG4 50s 
/goto :$v0 



Sub CleanUpScreen 

   /sendkey up ctrl 
   /sendkey up shift 
   /sendkey up alt 
   /press esc 
   /press esc 
   /press esc 
   /sit off 
   /delay 2 
    
/return

Malachi
a hill giant
a hill giant
Posts: 227
Joined: Tue Nov 19, 2002 1:29 am
Contact:

Post by Malachi » Mon Nov 25, 2002 9:40 pm

#event Stunned "You are unstunned."

Not sure that I've ever seen it say this when I'm no longer stunned...
However, every time, it runs for NO REASON! I just can't seem to find the wrong part...
I also don't understand your question. It sounds like this macro runs automatically without you telling it to?

I didn't look @ the rest of the script.

~Malachi
~Oh danny boy, the pipes the pipes are calling.~

Catt
a lesser mummy
a lesser mummy
Posts: 76
Joined: Mon Sep 16, 2002 2:49 am

Post by Catt » Tue Nov 26, 2002 1:34 am

I to missed your question, however, I did look through the script.

I find too many errors to fix quickly, examples include:

/goto-ing a Sub vs. /call-ing a Sub
/Sub's w/o /returns
/if's using { without a } (i.e. no end)

I would suggest starting with something much smaller, get the structure down then build up to something this size.

I hope your code has tabs, they make it much easier to follow, if you use the code tags (on this board) tabs and spaces are shown like:

Code: Select all

sub Run 
	/echo We're in trouble, lets split... 
	/attack off 
	/press esc 
	/target npc guard 
	/call GotoTarg "$target(name)" 
	/call Rest 
/return 

Iceassassin
a lesser mummy
a lesser mummy
Posts: 49
Joined: Tue Nov 05, 2002 11:40 am

Explain clearly...

Post by Iceassassin » Tue Nov 26, 2002 3:52 pm

Sorry... I copied and pasted and I think I missed some things... I need to slow down!

Ok. So I am in my group, and when we attack it works like a charm. Then, after we kill the creature, my guy starts running like all over the map. My ranger just runs like to the other side of the map and comes back.... I don't know why. So if you can help me with that... Thanks

zertful
orc pawn
orc pawn
Posts: 18
Joined: Thu Oct 31, 2002 2:23 pm
Location: Greensboro, NC
Contact:

problems with macro

Post by zertful » Fri Nov 29, 2002 1:13 am

Hey Iceassassin,

Yea that hunting / bot script is mine with a few parts Fippy and a few parts Nerfy. Pretty much all of the sub event_hitsyou section is broken. It may be bombing out as soon as you get hit if you leave that stuff in there. There are alot of missing returns in Main. (I've learned alot since this script)

I would remove the entire #event HitsYou and also, DisplayHateList AddToHateList. I haven't used the singing code, but it looks like it's setting timers on each song for 50 seconds if you're stunned or you miss a note. Bah I can't figure it out by looking, use the (code) command next time. :)

I have some other versions of this script also if you still want to use it... my reccomendation is to write your own using the examples here, its really helps you figure out why it doesn't work it you wrote it!


Zertful
- those who sling mud, lose ground -