Need loop/declare help

SneakyDaddy

Lifetimer
Joined
Apr 22, 2006
Messages
275
Reaction score
0
Points
16
I am looking for some macro help with a targetting macro I am making.

Basically I want to skip mobs that I can not hit and bypass mobs that have damaged me with DS.

I would like to reduce the size of the subs. When I try incrementing and adding /next type lines I keep getting errors. I would like to be able to /declare level range at the beginning of mac.

I would like to be able to /declare TargetNPC# type at the beginning of the macro (ie: Druid/Drake/#BigBoy)

The delay (adjustable) at the end of each target sub is to allow me time to damage the mob. If no damage I would move on to the next npc type of target. Being able to /declare the HP% and delay at the beginning of the mac would be great also.

I know there are lots of other thing I could do with a targeting mac but this is also a training mac for me to see how the loop/declare stuff works in a simple mac.

Code:
turbo #40

#Event DS "YOU are burned!"
#Event DS "YOU are tormented!"

Sub Main

   /attack on
   /alert clear 1

:Target

   /call TargetAll

   /delay 1
   /doevents

   /if (!${Target.ID}) /call TargetNPC1

   /delay 1

   /if (!${Target.ID}) /call TargetNPC2

   /delay 1

   /if (!${Target.ID}) /call TargetNPC3

   /delay 1

   /if (!${Target.ID}) /call TargetNPC4

   /delay 1

   /if (!${Target.ID}) /call TargetNPC5

   /delay 5

   /if (!${Target.ID}) /goto :Target

:loop


   /doevents
   /if (${Spawn[gm].ID}) {
      /gsay later
      /clear
      /clean 
      /endmac
      }

:hold

   /if (${SpawnCount[PC]}>6)  {
   /echo Other in zone
   /goto :hold
   }

:Attack

   /if (${Me.PctHPs}<50) {
      /attack off
      /warp wp safe
      /goto :hold
      }
   /stand
   /squelch /attack on
   /if (${Target.ID}) /goto :Loop

/goto :Target

Sub TargetAll

   /if (!${Target.ID}) /tar npc 75 noalert 1
   /if (!${Target.ID}) /tar npc 74 noalert 1
   /if (!${Target.ID}) /tar npc 73 noalert 1
   /if (!${Target.ID}) /tar npc 72 noalert 1
   /if (!${Target.ID}) /tar npc 71 noalert 1
   /if (!${Target.ID}) /tar npc 70 noalert 1
   /if (!${Target.ID}) /tar npc 69 noalert 1
   /if (!${Target.ID}) /tar npc 68 noalert 1
   /if (!${Target.ID}) /tar npc 67 noalert 1
   /if (!${Target.ID}) /tar npc 66 noalert 1
   /delay 2
   /if ${Target.PctHPs}>=98 /target clear
   /return

Sub TargetNPC1

   /if (!${Target.ID}) /tar npc 75 cleric noalert 1
   /if (!${Target.ID}) /tar npc 74 cleric noalert 1
   /if (!${Target.ID}) /tar npc 73 cleric noalert 1
   /if (!${Target.ID}) /tar npc 72 cleric noalert 1
   /if (!${Target.ID}) /tar npc 71 cleric noalert 1
   /if (!${Target.ID}) /tar npc 70 cleric noalert 1
   /if (!${Target.ID}) /tar npc 69 cleric noalert 1
   /if (!${Target.ID}) /tar npc 68 cleric noalert 1
   /if (!${Target.ID}) /tar npc 67 cleric noalert 1
   /if (!${Target.ID}) /tar npc 66 cleric noalert 1
   /delay 2
   /if ${Target.PctHPs}>=98 /target clear
   /return

Sub TargetNPC2

   /if (!${Target.ID}) /tar npc 75 druid noalert 1
   /if (!${Target.ID}) /tar npc 74 druid noalert 1
   /if (!${Target.ID}) /tar npc 73 druid noalert 1
   /if (!${Target.ID}) /tar npc 72 druid noalert 1
   /if (!${Target.ID}) /tar npc 71 druid noalert 1
   /if (!${Target.ID}) /tar npc 70 druid noalert 1
   /if (!${Target.ID}) /tar npc 69 druid noalert 1
   /if (!${Target.ID}) /tar npc 68 druid noalert 1
   /if (!${Target.ID}) /tar npc 67 druid noalert 1
   /if (!${Target.ID}) /tar npc 66 druid noalert 1
   /delay 2
   /if ${Target.PctHPs}>=98 /target clear
   /return

Sub TargetNPC3

   /if (!${Target.ID}) /tar npc 75 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 74 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 73 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 72 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 71 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 70 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 69 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 68 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 67 Wizard noalert 1
   /if (!${Target.ID}) /tar npc 66 Wizard noalert 1
   /delay 2
   /if ${Target.PctHPs}>=98 /target clear
   /return

Sub TargetNPC4

   /if (!${Target.ID}) /tar npc 75 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 74 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 73 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 72 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 71 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 70 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 69 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 68 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 67 Shaman noalert 1
   /if (!${Target.ID}) /tar npc 66 Shaman noalert 1
   /delay 2
   /if ${Target.PctHPs}>=98 /target clear
   /return

Sub TargetNPC5

   /if (!${Target.ID}) /tar npc 75 Magician noalert 1
   /if (!${Target.ID}) /tar npc 74 Magician noalert 1
   /if (!${Target.ID}) /tar npc 73 Magician noalert 1
   /if (!${Target.ID}) /tar npc 72 Magician noalert 1
   /if (!${Target.ID}) /tar npc 71 Magician noalert 1
   /if (!${Target.ID}) /tar npc 70 Magician noalert 1
   /if (!${Target.ID}) /tar npc 69 Magician noalert 1
   /if (!${Target.ID}) /tar npc 68 Magician noalert 1
   /if (!${Target.ID}) /tar npc 67 Magician noalert 1
   /if (!${Target.ID}) /tar npc 66 Magician noalert 1
   /delay 2
   /if ${Target.PctHPs}>=98 /target clear
   /return


Sub Event_DS
   /squelch /alert add 1 id ${Target.ID}
   /squelch /target clear
   /doevents flush
   /delay 1s
/return
 
Code:
#Event DS "YOU are burned!"
#Event DS "YOU are tormented!"


Sub Main
/declare MobTimer timer outer
/declare LastID   int   outer

/attack on
/alert clear 1

/alert add 2 class warrior
/alert add 2 class cleric
/alert add 2 class wizard
:MainLoop
   /if (!${Target.ID} || ${Target.Type.Equal[PC]} || ${Target.Type.Equal[Corpse]}) {
     /squelch /target npc alert 2noalert 1
     /varset LastID ${Target.ID}
     /varset MobTimer 20s
   }
   /doevents 
   /call AlertAddMob
    
  /goto :MainLoop  
    
Sub AlertAddMob
  /if (${Target.ID} && !${MobTimer}) {
    /echo ${Target.CleanName} w/ ID of ${Target.ID}  Has Been on Target for over 20 seconds Adding to Alert List.
    /alert add 1 id ${Target.ID}
    /squelch /target clear
  }
/return    
    
Sub Event_DS
/squelch /alert add 1 id ${Target.ID}
/squelch /target clear
/doevents flush
/delay 1s
/return
 
Code:
turbo #40

#Event DS "YOU are burned!"
#Event DS "YOU are tormented!"

Sub Main
   /declare LowHP int outer 98
   /declare loopcount int outer
   /declare TargetNPC1 string outer cleric
   /declare TargetNPC2 string outer druid
   /declare TargetNPC3 string outer wizard
   /declare TargetNPC4 string outer shaman
   /declare TargetNPC5 string outer magician

   /attack on
   /alert clear 1

:Target

   /call TargetAll

   /delay 1
   /doevents

   /for loopcount 1 to 5
       /if (!${Target.ID}) /call TargetNPC ${loopcount}
   /next loopcount

   /delay 5

   /if (!${Target.ID}) /goto :Target

:loop


   /doevents
   /if (${Spawn[gm].ID}) {
      /gsay later
      /clear
      /clean 
      /endmac
      }

:hold

   /if (${SpawnCount[PC]}>6)  {
   /echo Other in zone
   /goto :hold
   }

:Attack

   /if (${Me.PctHPs}<50) {
      /attack off
      /warp wp safe
      /if (${Me.State.Equal[STAND]}) /sit
:heal
      /goto :heal
      }
   /stand
   /squelch /attack on
   /if (${Target.ID}) /goto :Loop

/goto :Target

Sub TargetAll
   /declare lc int local

   /for lc 75 downto 66
       /if (!${Target.ID}) /tar npc ${loopcount} noalert 1
   /next loopcount
   /delay 2
   /if (${Target.PctHPs} >= ${LowHP}) /target clear
   /return

Sub TargetNPC(int NPCcount)
   /declare lc int local

   /for lc 75 downto 66
       /if (!${Target.ID}) /tar npc ${loopcount} ${TargetNPC${NPCcount}} noalert 1
   /next loopcount
   /delay 2
   /if (${Target.PctHPs} >= ${LowHP}) /target clear
   /return

Sub Event_DS
   /squelch /alert add 1 id ${Target.ID}
   /squelch /target clear
   /doevents flush
   /delay 1s
/return
 
Thx Jim/Taron for your quick responses.

I will play with these for awhile before asking more...
 
Here's my take on this ;)

Beware that's it very untested and I haven't slept yet so please make sure to check it over :)

Code:
#Turbo 40

#Event DS           "YOU are pierced by thorns!"
#Event DS           "YOU are burned!"
#Event DS           "YOU are tormented!"

Sub Main
    |---------------------------------------------------------------------------
    | The alert ID used for the skip list (NPC's with DS etc).
    |---------------------------------------------------------------------------
    /declare Skip           int     outer   1

    |---------------------------------------------------------------------------
    | Level range of NPC's to target.
    |---------------------------------------------------------------------------
    /declare LevelMin       int     local   66
    /declare LevelMax       int     local   75

    |---------------------------------------------------------------------------
    | The order which mobs should be targeted in (by race or class).
    |---------------------------------------------------------------------------
    /declare TargetOrder[5] string  outer
    /varset TargetOrder[1] Class cleric
    /varset TargetOrder[2] Class druid
    /varset TargetOrder[3] Class wizard
    /varset TargetOrder[4] Class shaman
    /varset TargetOrder[5] Class magician

    |---------------------------------------------------------------------------
    | Incremental variables for loops.
    |---------------------------------------------------------------------------
    /declare t              int     local   0
    /declare l              int     local   0


    :Target
        /for t 1 to ${TargetOrder.Size}
            /for l ${LevelMax} downto ${LevelMin}
                /if (${SpawnCount[npc radius 30 zradius 15 noalert ${Skip} ${TargetOrder[${t}]}]}) {
                    /squelch /target npc radius 30 zradius 15 noalert ${Skip} ${TargetOrder[${t}]}
                    /delay 1s (${Target.Type.Equal[NPC]})
                    :Loop
                        /doevents DS
                        /call SafetyCheck -1
                        /if (${Macro.Return[GM]}) {
                            /gsay later
                            /cleanup 
                            /endmacro
                        }
                        :Hold
                            /call SafetyCheck -1
                        /if (${Macro.Return[PC]}) /goto :Hold

                        /if (${Me.PctHPs}<50) {
                            /if (${Me.Combat}) /attack off
                            /squelch /warp wp safe
                            /goto :Hold
                        }
                        /if (!${Me.Standing}) /stand
                        /if (!${Me.Combat}) /attack on
                    /if (${Target.ID}) /goto :Loop
                }
            /next l
        /next t
    /goto :Target
/return

Sub SafetyCheck(int Radius, int Exclude)
    /declare i              int     local   0
    /declare c              int     local   0
    /if (!${Defined[Radius]}) /declare Radius   int     local   500
    /declare SafeSearch     string  local   pc${If[${Radius} == -1,, radius ${Radius} zradius 50]} notid ${Me.ID}
    /if (${Defined[Exclude]}) /varset SafeSearch ${SafeSearch} noalert ${Exclude}

    /if (${SpawnCount[${SafeSearch}]} || ${SpawnCount[gm]}) {
        /if (${SpawnCount[gm]}) {
            /return GM
        } else {
            /for i 1 to ${SpawnCount[${SafeSearch}]}
                /if (${Group.Member[${NearestSpawn[${i}, ${SafeSearch}]}]}) /goto :Continue
                /return PC
                :Continue
            /next i
        }
    }
/return OK

Sub Event_DS
    /if (!${Target.ID}) /goto :End
    /alert add ${Skip} id ${Target.ID}
    /squelch /target clear
    /doevents flush
    /delay 1s
    :End
/return