magefight.mac First test...

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

ImaNoob
a ghoul
a ghoul
Posts: 89
Joined: Mon Mar 08, 2004 4:37 am

magefight.mac First test...

Post by ImaNoob » Tue Mar 23, 2004 12:10 am

Here is my first shot at a real macro that does something other than skillups and forage. It has taken me about 2 days / 4hrs per day to get thus far.

To start this I had to cobble together magecamp.mac and Mckoors run to target with obstacle avoidance.

This is my first version, I haven't had a chance to even test it yet, so I'm asking mostly for extra eyes anything blindingly glaringly obvious that might be missing from this macro. Or more subtle things like missing brackets, misspelled words or what not.

The macro is meant for a level 50ish magician to use a very effective method of hunting, with only a single key press


Code: Select all

|magefight.mac v1.0 Imanoob
|This macro will target a mob, run close enough to pull it.
|Cast a debuff, then run back to safe point sic pet on mob, cast dot, dd then med
|Heal and buff pet if either fails.
|Run and try to gate if mob aggros you
|
|To use this macro
|/macro magefight mobname
|

|Includes and defines
#turbo 50 

#include SpellCast.inc 
#define ENEMY @param0

#Event PetHasteDown   "Your pet's Burnout III spell has worn off." 
#Event PetDSDown   "Your pet's Shield of Lava spell has worn off."
#Event DoTDown      "Your Elemental Maelstrom spell has word off." 
#Event SLAINBY      "You have been slain by " 
#Event EXP      "You gain experience!!" 

|Declarations
/declare DSSpell global
/declare SelfBuffSpell global
/declare DebuffSpell global
/declare DoTSpell global
/declare DDSpell global
/declare PetSpell global
/declare PetBuffSpell global
/declare PetDSSpell global
/declare PetHealSpell global
/declare EvacSpell global
/declare HomeXLOC global
/declare HomeYLOC global
/declare MyXLOC global
/declare MyYLOC global
/declare PetHasteStatus global 
/declare PetDSStatus global 
/declare TargetDead global

|Main macro
Sub Main 
   /call SetGlobals
   /call GetTarget
   /call Pull
   /call killaction
/endmacro

Sub SetGlobals
    /varset DSSpell "Shield of Lava"
    /varset SelfBuffSpell "Greater Shielding"
    /varset DebuffSpell "Malosi"
    /varset DoTSpell "Elemental Maelstrom"
    /varset DDSpell "Shock of Blades"
    /varset PetSpell "Greater Conjuration Earth"
    /varset PetBuffSpell "Burnout III"
    /varset PetDSSpell "Shield of Lava"
    /varset PetHealSpell "Renew Elements"
    /varset EvacSpell "Gate"
    /echo Spells Loaded
    /varset HomeXLOC $char(x)
    /varset HomeYLOC $char(y)
 /return


Sub GetTarget 
   :TargetLoop 
      /press ESC 
      /echo Searching for ENEMY! 
      /target npc ENEMY nopcnear 200 
      /if ("$target()"=="FALSE" || n $target(hp,pct)<=95) { 
         /echo Unable to locate any targets nearby... Will try again in 15 seconds. 
         /if "$char(state)"!="SIT" /sit 
         /delay 15s 
         /goto :TargetLoop 
      } 
   /echo Closing in on $target(name,clean)... 
   /varset DIST 80 
   /call MoveToTarget 
/return

Sub Pull
      |TODO Run to target Malosi and run back
	/face target
        /MoveToMob
	/delay 2s
	/call Cast DebuffSpell
	/call RunForMyLife
/return

Sub RunForMyLife
	
	:keeprunning
		/face fast loc @HomeYLOC,@HomeXLOC 
		if($char(x) != @HomeXLOC) || ($char(y) != @HomeYLOC){
		/sendkey up up
		/goto :keeprunning 
	}
	/sendkey down down
	/face $target
/return

Sub MoveToMob 

  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 
  /varset ObstacleCount 0 

  /if n $target(distance,nopredict)<=15 { 
    /face look 
    /return 
  } 
  /doEvents 
  /sendkey down up 

  :Movementloop 
    /varadd ObstacleCount 1 
    /if $target()=="FALSE" /return 
    /face look 
    /if n $target(distance,nopredict)<= $target(maxrange)-10 { 
      /face look 
      /sendkey up up 
      /varset InCombat 1 
      /return 
    } 
    /if @ObstacleCount>=3 { 
      /call CheckObstacle 
      /goto :Movementloop 
    } 
    /if n $target(distance,nopredict)> $target(maxrange)+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 killaction 
	/doevents 
	/call Castspells 
	/target npc @mob1 radius @area 
	/pet attack 

:MainCombatLoop 
	/call CastSpells 
	/if n $target(id)==0 /varset TargetDead 1 
	/doevents 
	/if n @TargetDead!=1 /goto :maincombatloop 
	/if $target()=="FALSE" /goto :EndKillTarget 

:EndKillTarget 
	/pet follow 
	/goto :Cleanup 
/return 


Sub CastSpells 
:StartSpells
	/sit on 
	/if n $char(mana,pct)<60 /call MedUp 
	/if n $char(buff,DSSpell)==0 {
		/sit off 
		/call Cast DSSpell 
		/delay $spell(DSSpell,casttime)
 		/goto :StartSpells 
	} 

	/if n @PetHasteStatus==0 { 
		/target id $char(pet)
		/sit off 
		/call Cast PetBuffSpell 
		/delay $spell(PetBuffSpell,casttime)
		/varset PetHasteStatus 1 
		/goto :StartSpells 
	} 

| check to see if we need to DS our Pet 
	/if n @PetDSStatus==0 { 
		/target id $char(pet)
		/sit off 
		/call Cast PetDSSpell 
		/delay $spell(PetDSSpell,casttime)
		/varset PetDSStatus 1 
		/goto :StartSpells 
	} 
      
| check to see if we need to heal our pet. 
	/if n $spawn($char(pet),hp,pct)<40 { 
		/target id $char(pet)
		/sit off 
		/call Cast "PetHealSpell" 
		/delay $spell(PetHealSpell,casttime) 
		/goto :StartSpells 
	} 
	/if n @DoTStatus ==0 {
		/target $spawn(@mobid)
		/sit off
		/call Cast DoTSpell
		/delay $spell(DoTSpell,casttime) 
	}
| Check to see if we should nuke the mob. 

	/target npc @ENEMY radius @area 
	/if  n $target(id)==$char(pet) /goto :nonuke 
	/if $target()==FALSE /goto :nonuke 
	/if $spawn(@mobid,hp,pct)==0 /goto :nonuke 
	/if n $spawn(@mobid,hp,pct)<75 { 
		/call Cast DDSpell 
		/delay $spell(DDSpell,casttime)
	} 
      
:nonuke 
	/if DEBUG /echo No Nuke Needed ATM. 
/return 


Sub Event_PetHasteDown 
	/varset PetHasteStatus 0 
/return 

Sub Event_PetDSDown 
	/varset PetDSStatus 0 
/return

Sub Event_DoTDown
	/varset DoTStatus 0
/reutrn

Sub Event_SLAINBY 
	/echo  "Ack I died!" 
	/delay 1m 
	/sit 
	/camp desktop 
	/endmacro 
/return 
EDIT LOG
3-23-04
Began Implementing changes suggested by bonehand
Last edited by ImaNoob on Tue Mar 23, 2004 11:59 am, edited 1 time in total.

bonehand
a lesser mummy
a lesser mummy
Posts: 48
Joined: Tue Feb 17, 2004 5:16 pm

Post by bonehand » Tue Mar 23, 2004 8:24 am

Very dirty...did you test this? If must spit out an error pretty fast. I'll help, but this should be a flame instead about how you need to RTFM.

First:
In Sub Main, make a loop so that you aren't setting all variables every pass through. I could see how the x,y locations could definately wander you into trouble after a while if you constantly reset your anchor.

Sub Main
/call SetGlobals
:loopmain
| Set variables you need to clear every pass here.

/call GetTarget
/call Pull
/call killaction
/if n @EndScriptFlag==TRUE /goto :EndMainLoop
/goto :loopmain
:EndMainLoop
/endmacro

Second:
Clean up these lines!! Here's just one of tons...

if($char(x) != @HomeXLOC) || ($char(y) != @HomeYLOC){

Unneeded parantheticals, missing numeric indicators(n's), missing spaces, and when you use comparisions(ie ==.<=, ...) don't put extra spaces around them...

Third: @Param actually starts at 0, so you are always setting your target to NULL.

Finally(I would help more but I have to get ready for work soon) you will never hit your Anchor with this line:

if($char(x) != @HomeXLOC) || ($char(y) != @HomeYLOC){

Try implimenting $dstance(y,x) in there...oh ya /face x,y is wrong and I may have even fubared that in my own snippet.

In MQ2 Y,X seems to be the standard...

So: /face @HomeXLOC, @HomeYLOC is wrong in a couple ways.

Make it:

/face fast loc @HomeYLOC,@HomeXLOC

All in all, this needs a buttload of work...and much more than I listed due to time constraints. Check your logic, check your command structure, and clean up all the extra and missing spaces.

EDIT: Were the hell did my CODE brackets go?