Newbie need some starting out help with a simple macro

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

VertiGOD
a lesser mummy
a lesser mummy
Posts: 66
Joined: Mon Jan 10, 2005 6:19 am

Newbie need some starting out help with a simple macro

Post by VertiGOD » Sun Feb 09, 2014 3:50 pm

Hi,

been trying to make a simple macro which basically just targets nearest npc which are close enough to send pet to and then do a /pet attack

However..my macro writing skills are basically equal to none...so was hoping for someone to give me a few pointers.

This is what I have so far:

Code: Select all

Sub Main
:mainloop

/if (${SpawnCount[npc radius 150]}==0) {
/echo No mobs found..waiting...
/delay 30
/goto :mainloop
/return
}


/if (${Target.ID}) {
/if (!${Me.CombatState.Equal[COMBAT]}) {
/pet attack
}
}

/if (!${Target.ID}) {
/target NPC
}

/delay 3
/goto :mainloop
/return
Any help is greatly appriciated :)

User avatar
MacQ
Macro Author
Macro Author
Posts: 674
Joined: Sat Apr 02, 2005 2:39 pm

Re: Newbie need some starting out help with a simple macro

Post by MacQ » Sun Feb 09, 2014 4:42 pm

The problem is that the simple act of determining an appropriate target, deciding to attack, waiting for the mob to be killed, etc., can in itself be a complex task. So I strongly suggest you become a member of the VIP forums because there are hundreds of macros you can use and an amazing wealth of information you can learn from.

In the mean time, I literally threw this together to show you some basic concepts. I could have made the sample macro shorter, but I wanted to use some concepts like checking to see if the target is in water, target is in line of site, using a target ID variable (to reduce the number of TLO calls), using a /while loop, conditional delays, etc. However, I have not tested this so I can't vouch for its correctness.

Code: Select all

Sub Main
	/declare TargetID	int
	:MainLoop
	/varset TargetID ${NearestSpawn[npc radius 100 zradius 50 los].ID}
	/if ( !${TargetID} || ${Spawn[${TargetID}].FeetWet} ) /goto :MainLoop
	/target id ${TargetID}
	/delay 10 ${Target.ID} == ${TargetID}
	/pet attack
	/while ( ${Spawn[${TargetID}].Type.NotEqual[corpse]} ) {
		/delay 1
	}
	/varset TargetID 0
	/squelch /target clear
	/delay 10 !${Target.ID}
	/goto :MainLoop
/return

VertiGOD
a lesser mummy
a lesser mummy
Posts: 66
Joined: Mon Jan 10, 2005 6:19 am

Re: Newbie need some starting out help with a simple macro

Post by VertiGOD » Mon Feb 10, 2014 4:14 pm

Hey,

thanks for your quick reply :)

Tried your code out. It targets the nearest mob and sends in the pet. However it seems to spam alot /pet attack..and keeps chain re-targeting the mob it seems.

I had to comment out the

Code: Select all

/while ( ${Spawn[${TargetID}].Type.NotEqual[corpse]} ) {
as it gave a "could not parse..." error.

User avatar
MacQ
Macro Author
Macro Author
Posts: 674
Joined: Sat Apr 02, 2005 2:39 pm

Re: Newbie need some starting out help with a simple macro

Post by MacQ » Mon Feb 10, 2014 6:03 pm

If you remove the /while, then you don't have a section of your program to wait for the mob to be killed. That is a very simple form of the /while loop and works fine on my system, I don't know why it does not work on your system.

Anyway, here is a version that works without the /while loop. It has some /echo status messages and a few other programming techniques to keep you occupied. There are a few other techniques that include not spamming the server with unrealistic requests, but you need to figure that stuff out on your own. You should be able to build from this simple macro. Hope to see you in the VIP forums as there a lot of talented folks who can also give you advice.

Code: Select all

| Simple macro to look for an NPC within a certain definable radius and zradius.
| Only select targets you can see (los - line of site) and are not in the water.
| Wait for the target to be killed, then rince and repeat. 

Sub Main
   /declare TargetID	int
   /declare	Radius		int	100
   /declare	ZRadius		int	50
   /echo Starting Simple Targeting and Pet Attack Macro
   /echo Searching a Radius of ${Radius} and a ZRadius of ${ZRadius}

   :MainLoop
   /echo Looking For Target

   :LookForTarget
   /varset TargetID ${NearestSpawn[npc radius ${Radius} zradius ${ZRadius} los].ID}
   /if ( !${TargetID} || ${Spawn[${TargetID}].FeetWet} ) {
| Added this two second delay for the hell of it.
   	/delay 20
   	/goto :LookForTarget
  }
  
   /echo Found Target - Sending Pet
| Set our target to the mob's ID
   /target id ${TargetID}
| It can take a moment for the target to set, so wait up to two seconds
| or until the target ID has been set.
   /delay 20 ${Target.ID} == ${TargetID}
   /pet attack
   
   /echo Waiting for Target to Die
   :WaitForDead
   /if ( ${Spawn[${TargetID}].Type.NotEqual[corpse]} ) {
| Added this two second delay for the hell of it.
   	/delay 20
   	/goto :WaitForDead
  }
   /varset TargetID 0
   /squelch /target clear
| It can take a moment for the target to clear, so wait up to two seconds
| or until thre is no target.
   /delay 20 !${Target.ID}
   /echo Target Dead
   /goto :MainLoop
/return

PeteSampras
a snow griffon
a snow griffon
Posts: 322
Joined: Sat Dec 15, 2007 8:56 pm

Re: Newbie need some starting out help with a simple macro

Post by PeteSampras » Tue Feb 11, 2014 12:42 am

easy pet check is:
/if (!${Me.Pet.Following.ID} && ${Target.ID}==${TargetID}) /pet attack


that way it doesnt spam.

VertiGOD
a lesser mummy
a lesser mummy
Posts: 66
Joined: Mon Jan 10, 2005 6:19 am

Re: Newbie need some starting out help with a simple macro

Post by VertiGOD » Wed Feb 12, 2014 12:26 pm

It seems to be working great. Awesome..thanks alot :)

One more question though (sorry),

I'm trying to add a routine for checking pet hp.. i can do:

Code: Select all

/echo ${Me.Pet.PctHPs}
But if I try:

Code: Select all

if( ${Me.Pet.PctHps} < 40 ){
/echo OMG pet in trouble!
}
I get a "could not parse..." error. Any ideas?

I'm using an older compile btw - Underfoot edition - as I'm playing on an emulator server.

(Joined the vip community now too btw, ty :) )

Maskoi

Re: Newbie need some starting out help with a simple macro

Post by Maskoi » Wed Feb 12, 2014 1:10 pm

if becomes /if
and
${Me.Pet.PctHps} wrong syntax PctHps becomes PctHPs

User avatar
MacQ
Macro Author
Macro Author
Posts: 674
Joined: Sat Apr 02, 2005 2:39 pm

Re: Newbie need some starting out help with a simple macro

Post by MacQ » Wed Feb 12, 2014 2:04 pm

Now it makes sense why the /while did not parse. I wondered why my first macro did not work for you, especially because it worked for me. The /while function is a new feature recently added, so if you're not running the current version, then the /while function probably does not exist in your version of MQ2.

Great to see you in the VIP community. My first suggestion is read, read, and read. There is an amazing knowledge base built up across thousands of posts over more than a decade. I can honestly say that almost every question that could be asked has probably been asked in some form or another, so my next piece of advice is search, search, and search before you ask. You will be presently surprised at how often you will find an answer to your question if you take the time to search and read, of course, this does not mean that folks are unwilling to help, there are a lot of folks who provide kind advice in the VIP forums.

VertiGOD
a lesser mummy
a lesser mummy
Posts: 66
Joined: Mon Jan 10, 2005 6:19 am

Re: Newbie need some starting out help with a simple macro

Post by VertiGOD » Wed Feb 12, 2014 2:15 pm

Maskoi wrote:if becomes /if
and
${Me.Pet.PctHps} wrong syntax PctHps becomes PctHPs
That was a typo in here.. sorry. Had typed it correct in the macro though o.O so guessing it might be due to my mq2 version.. that the hp check syntax was different before? :)

VertiGOD
a lesser mummy
a lesser mummy
Posts: 66
Joined: Mon Jan 10, 2005 6:19 am

Re: Newbie need some starting out help with a simple macro

Post by VertiGOD » Wed Feb 12, 2014 2:16 pm

MacQ wrote:Now it makes sense why the /while did not parse. I wondered why my first macro did not work for you, especially because it worked for me. The /while function is a new feature recently added, so if you're not running the current version, then the /while function probably does not exist in your version of MQ2.

Great to see you in the VIP community. My first suggestion is read, read, and read. There is an amazing knowledge base built up across thousands of posts over more than a decade. I can honestly say that almost every question that could be asked has probably been asked in some form or another, so my next piece of advice is search, search, and search before you ask. You will be presently surprised at how often you will find an answer to your question if you take the time to search and read, of course, this does not mean that folks are unwilling to help, there are a lot of folks who provide kind advice in the VIP forums.
thanks for the advices. I'll be sure to read up on the vip forum :)

screache
decaying skeleton
decaying skeleton
Posts: 7
Joined: Thu May 17, 2018 4:44 pm

Re: Newbie need some starting out help with a simple macro

Post by screache » Sun Jul 04, 2021 12:09 am

/keypress f8
/pet attack