Help with first macro

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

Moderator: MacroQuest Developers

User avatar
aj2k8
a lesser mummy
a lesser mummy
Posts: 56
Joined: Fri Sep 10, 2004 6:58 am

Help with first macro

Post by aj2k8 » Fri Sep 10, 2004 7:01 am

This is my first macro... Well, it'll attack one guy but no others, and it won't sit like I want it to. I know it looks aweful, arent there any while loops in macroquest?

Code: Select all

#event NPCDead "#*#You have slain#*#"
Sub Main
/target npc range 3 5
:loopa
/face
/nomodkey /keypress forward hold
/if (${Target.Distance.Int}<10) {
/nomodkey /keypress forward
/goto :loopb
}
/goto :loopa
:loopb
/if (${Target.Distance.Int}>10) {
/face
/nomodkey /keypress forward hold
:loopd
/if (${Target.Distance.Int}<5) /goto :loopb
/goto :loopd
}
/nomodkey /keypress forward
/attack
/goto :loopb
/return
Sub Event_NPCDead
/sit
:loopc
/if (Me.PctHPs.Equal[100]) {
/stand
/call Main
}
/goto :loopc
/return
 

Sparr
a hill giant
a hill giant
Posts: 159
Joined: Mon Jun 24, 2002 5:41 am

Post by Sparr » Fri Sep 10, 2004 7:13 am

I think this is the best first post ive seen in a while. And in the right forum to boot! Its too early in the morning for me to fix all your mistakes, but here is a start.

/call Main is bad. even if it works its horrible practice. what you should do is set an outer variable named 'killedit', initialized to 0 every time you target a mob. and then set killedit = 1 in the event_dead. then after you do /doevents (which you never do right now, meaning your event will never trigger) you can check the value of killedit to see whether you should keep fighting or start over.
[img]http://www.trifocus.net/~sparr/sparr_rotate_sig_16.gif[/img]

User avatar
fearless
Not a Psychic
Posts: 2684
Joined: Wed Mar 10, 2004 3:52 pm

Post by fearless » Fri Sep 10, 2004 8:12 am

I would take a look at m0nk's stick.macas a fairly good example of some of the things you are trying to do.

User avatar
Cr4zyb4rd
Plugins Czar
Posts: 1449
Joined: Tue Jul 20, 2004 11:46 am

Post by Cr4zyb4rd » Fri Sep 10, 2004 10:40 am

Some indents would make it about 200x easier to follow.

Good first attempt :)

User avatar
fearless
Not a Psychic
Posts: 2684
Joined: Wed Mar 10, 2004 3:52 pm

Post by fearless » Fri Sep 10, 2004 10:54 am

You might also want to check if there is any more npc's with in a certain radius before you sit, so that you don't get smacked all to hell and still be stuck in your sitting sub.

User avatar
aj2k8
a lesser mummy
a lesser mummy
Posts: 56
Joined: Fri Sep 10, 2004 6:58 am

Post by aj2k8 » Fri Sep 10, 2004 1:11 pm

You might also want to check if there is any more npc's with in a certain radius before you sit, so that you don't get smacked all to hell and still be stuck in your sitting sub.
At my level all NPCs are indifferent to me.

Anyways, the reason why i posted this was because it's not working... After killing one guy, he doesn't sit or target anything else... just stands there.

SlimFastForYou
a hill giant
a hill giant
Posts: 174
Joined: Sat Jan 24, 2004 1:38 am

Post by SlimFastForYou » Fri Sep 10, 2004 1:34 pm

I'll just copy and paste what I have in my engage routine (for my almost finished autopull macro, I took out the add handling and other extra stuff that relies on external routines). Has some slightly more advanced stuff, but it should serve as a semi good example =). You could probably add extras like sitting until your full HP or what not from here.

Code: Select all

Sub Main
      :MainLoop
             /call Engage
             /echo Currently have ${Me.CurrentHPs} hitpoints (${Me.PctHPs}%)
       /goto :MainLoop
/return


Sub Engage
	/declare TargetToPull int local
	/stand
	/varset TargetToPull ${NearestSpawn[npc range 3 5].ID}
	/target id ${TargetToPull}
	/attack on
	/face id ${TargetToPull}

	/echo Attacking ${Target.Name}
	/mqlog Engage: Attacking ${Target.Name}


	:AutoAttackLoop

		/face fast

		/call CheckDeath

		/if (${Target.Distance}>12) {
			/keypress forward hold

			:GetCloseLoop
				/face fast
				/if (!${Target.ID}) {
					/keypress forward
					/return
				}
			/if (${Target.Distance}>12) /goto :GetCloseLoop

			/keypress forward
		}

		/if (${Target.Distance}<8) {
			/face fast
			/keypress back hold
			:GetBackLoop
				/face fast
				/if (!${Target.ID}) {
					/keypress back
					/return
				}
			/if (${Target.Distance}<8) /goto :GetBackLoop
			/keypress back
		}


		/if (!${Me.Stunned}) {
			/if (${Me.AbilityReady["Taunt"]}==1) {
				/doability "Taunt"
      		}
			/if (${Me.AbilityReady["Kick"]}==1) {
				/doability "Kick"
      		}
			/if (${Me.AbilityReady["Disarm"]}==1) {
				/doability "Disarm"
      		}
		}


	/if (${Target.Type.Equal["NPC"]}) /goto :AutoAttackLoop

/return
Oh, and to answer your question, you don't have a /doevents call in your macro. In other words, your macro never checks to see if the text "you have slain" was ever sent to the client. The macro I gave doesn't rely on any events. Your macro is somewhat difficult to follow because the gotos jump all over the place and don't really have good names (and the indenting is bad). Therefore, I'm not even quite sure where you would put /doevents. It's your first macro, so I'm not knocking you for it - just giving suggestions to make it 10x easier on yourself when writing them. Overall, you made a damn good first macro.

Edit: One more thing - This wont work.

Code: Select all

/if (Me.PctHPs.Equal[100]) { 
It needs to be.

Code: Select all

/if (${Me.PctHPs}==100) { 
For one, you needed the ${} around your stuff. Also, I don't think .Equal will evaluate numbers but rather strings. I could be mistaken though

User avatar
aj2k8
a lesser mummy
a lesser mummy
Posts: 56
Joined: Fri Sep 10, 2004 6:58 am

Post by aj2k8 » Fri Sep 10, 2004 7:23 pm

Thanx

User avatar
aj2k8
a lesser mummy
a lesser mummy
Posts: 56
Joined: Fri Sep 10, 2004 6:58 am

Post by aj2k8 » Fri Sep 10, 2004 10:05 pm

ok, i took your code and changed it a bit:

Code: Select all

Sub Main
      /declare KillCount int outer
      :MainLoop
             /call Engage
             /echo Currently have ${Me.CurrentHPs} hitpoints (${Me.PctHPs}%)
	     /if (${Me.PctHPs}!=100) {
		/call Sit
	     }
       /goto :MainLoop
/return


Sub Engage
   /declare TargetToPull int local
   /stand
   /varset TargetToPull ${NearestSpawn[npc range 4 5].ID}
   /target id ${TargetToPull}
   /attack on
   /face id ${TargetToPull}

   /echo Attacking ${Target.Name}
   /mqlog Engage: Attacking ${Target.Name}


   :AutoAttackLoop

      /face fast


      /if (${Target.Distance}>12) {
         /keypress forward hold

         :GetCloseLoop
            /face fast
            /if (!${Target.ID}) {
               /keypress forward
               /return
            }
         /if (${Target.Distance}>12) /goto :GetCloseLoop

         /keypress forward
      }

      /if (${Target.Distance}<8) {
         /face fast
         /keypress back hold
         :GetBackLoop
            /face fast
            /if (!${Target.ID}) {
               /keypress back
               /return
            }
         /if (${Target.Distance}<8) /goto :GetBackLoop
         /keypress back
      }



   /if (${Target.Type.Equal["NPC"]}) /goto :AutoAttackLoop

   /varset KillCount ${KillCount}+1

   /echo You have killed ${KillCount} enemies.

/return



Sub Sit
	/sit

	:LoopSit

	/if (${Me.PctHPs}==100) /return

	/goto :LoopSit

/return