What needs to be changed?

CJxthree

New member
Joined
Nov 6, 2007
Messages
178
Reaction score
0
Points
0
I can not seem to put my finger on what needs to be fixed in this.
All Im trying to do is, once my current target is dead, to loop and target another so on and so on.

Code:
Sub Main

/echo You're a lazy ass.
/delay 1s
/call Realdeal
/return


Sub Realdeal
	:Target
/tar NPC A Cave
/face fast
/delay 1s
/keypress up hold   
	:Moving
/if (${Target.Distance}>14) /goto :Moving
/keypress up
/delay 1s
/attack
/if (!${Target.ID}) /goto :Target
/return
 
Put a /goto :loop into sub main.

Code:
Sub Main
:loop
/echo You're a lazy ass.
/delay 1s
/call Realdeal
/goto :loop
/return
 
It works if I replace

Code:
/if (!${Target.ID}

for

Code:
/if (!${Target.NULL})

but spams the shit out of mq box with error messages
 
add a Goto in your Sub Main. As you have it now it does the echo then delays 1 second calls your sub. Once sub is called and ran thru and no longer has a target the macro basically ends as it has nothing left to do (it just returns to nothing)

Code:
Sub Main

/echo You're a lazy ass.
:Main
/delay 1s
/call Realdeal
/goto :Main
/return


Sub Realdeal
	:Target
/tar NPC A Cave
/face fast
/delay 1s
/keypress up hold   
	:Moving
/if (${Target.Distance}>14) /goto :Moving
/keypress up
/delay 1s
/attack
/if (!${Target.ID}) /goto :Target
/return <-- This is taking you to the next line that follows the /call Realdeal
 
Ahhh, there we go. I knew it was something small../shrug.
Thanks :).
You put an end to my frustration.
 
Although it's a small thing, this is how I would do it...
Basically I'm moving the loop into the actual target loop and checking if an NPC is targeted rather than just any target. Reason is that I could go and trade you and your target would now be me, which would keep the loop going due to it having a target, but really doing nothing cause I'm PC rather than NPC :)
Code:
Sub Main
    /echo You're a lazy ass.
    /delay 1s
    /call Realdeal
/return

Sub Realdeal
    :Target
        /tar NPC A Cave
        /face fast
        /delay 1s
        /keypress up hold   
        :Moving
        /if (${Target.Distance}>14) /goto :Moving
        /keypress up
        /delay 1s
        /attack
        :Kill
        /if (${Target.Type[NPC]}) /goto :Kill
    /goto :Target
/return
 
you forgot to add the loop to the Sub Main so it will not loop actually =(
 
Thinking about it I would probably still keep the actual loop in the Main sub, as JJ had it, so that the Realdeal sub would return to the Main sub after each kill. Would make it easier to extend later on.

So here's something I put together (untested) which would be what I'd use :p
What = What should be the search pattern (in this case "npc a rat".
Respawn = Does it respawn? TRUE or FALSE. Basically tells the macro to end if no more What matches are found and set to FALSE. Otherwise if set to TRUE it will keep waiting for respawn.

Code:
Sub Main
    /echo You're a lazy ass.
    /delay 1s
    /declare What       string  outer   npc a cave
    /declare Respawn    bool    local   TRUE

    :Loop
        /if (${SpawnCount[${What}]}) /squelch /target ${What}
        /if (${Target.Name.Find[${What}]}) {
            /call Move2Target 14
            /if (${Target.Type.Equal[NPC]}) /call KillTarget
        }
    /if (${Respawn} || ${SpawnCount[${What}]}) /goto :Loop
/return

Sub Move2Target(float MaxDist)
    /if (!${Defined[MaxDist]}) {
        /declare MaxDist    float   local   10
    }
    /declare TmpY           float   local   ${Me.Y}
    /declare TmpX           float   local   ${Me.X}
    /declare Timeout        timer   local   2s
    /declare Dist           float   local   ${Math.Distance[${TmpY},${TmpX}]}
    /if (!${Me.Standing}) /stand
    /squelch /face fast nolook
    /delay 1s
    /if (${Target.Distance} > ${MaxDist}) /nomodkey /keypress FORWARD hold
    :Loop
        /varset Timeout ${StuckTimer.OriginalValue}
        /varset TmpY ${Me.Y}
        /varset TmpX ${Me.X}
        /squelch /face fast nolook target
        /varset Dist ${Math.Distance[${TmpY},${TmpX}]}
        /if (${Target.Distance} > ${MaxDist}) {
            /if (!${Timeout} && ${Dist} <= 5) {
                /echo Seems we're stuck. Trying to correct.
                /nomodkey /keypress BACK
                /nomodkey /keypress BACK hold
                /delay 2s
                /if (${Math.Rand[2]}) {
                    /squelch /face fast nolook heading ${Math.Calc[${Heading[${LocY},${LocX}].DegreesCCW}+45]}
                } else {
                    /squelch /face fast nolook heading ${Math.Calc[${Heading[${LocY},${LocX}].Degrees}+45]}
                }
                /nomodkey /keypress FORWARD
                /nomodkey /keypress FORWARD hold
            }
        }
    /if (${Target.Distance} > ${MaxDist}) /goto :Loop
    /keypress BACK
    /keypress FORWARD
    /delay 1s
/return

Sub Move2Loc(float LocY, float LocX, float MaxDist)
    /if (!${Defined[LocY]} || !${Defined[LocX]}) {
        /echo Move2Loc error. No target coordinates defined.
        /echo Syntax: /call Move2Loc (float)Y (float)X[ (float)MaxDistance]
        /echo Ending macro...
        /endmacro
    }
    /if (!${Defined[MaxDist]}) {
        /declare MaxDist    float   local   10
    }
    /declare TmpY           float   local   ${Me.Y}
    /declare TmpX           float   local   ${Me.X}
    /declare Timeout        timer   local   2s
    /declare Dist           float   local   ${Math.Distance[${TmpY},${TmpX}]}
    /if (!${Me.Standing}) /stand
    /squelch /face fast nolook loc ${LocY},${LocX}
    /delay 1s
    /if (${Math.Distance[${LocY},${LocX}]} > ${MaxDist}) /nomodkey /keypress FORWARD hold
    :Loop
        /varset Timeout ${StuckTimer.OriginalValue}
        /varset TmpY ${Me.Y}
        /varset TmpX ${Me.X}
        /squelch /face fast nolook target
        /varset Dist ${Math.Distance[${TmpY},${TmpX}]}
        /if (${Math.Distance[${LocY},${LocX}]} > ${MaxDist}) {
            /if (!${Timeout} && ${Dist} <= 5) {
                /echo Seems we're stuck. Trying to correct.
                /nomodkey /keypress BACK
                /nomodkey /keypress BACK hold
                /delay 2s
                /if (${Math.Rand[2]}) {
                    /squelch /face fast nolook heading ${Math.Calc[${Heading[${LocY},${LocX}].DegreesCCW}+45]}
                } else {
                    /squelch /face fast nolook heading ${Math.Calc[${Heading[${LocY},${LocX}].Degrees}+45]}
                }
                /nomodkey /keypress FORWARD
                /nomodkey /keypress FORWARD hold
            }
        }
    /if (${Math.Distance[${LocY},${LocX}]} > ${MaxDist}) /goto :Loop
    /nomodkey /keypress FORWARD
    /nomodkey /keypress BACK
/return


Sub KillTarget
    /if (!${Me.Combat}) /attack
    :Kill
        |Could add some doevents or other actions in here, that needs checking or doing, during combat.
    /if (${Target.Type.Equal[NPC]}) /goto :Kill
/return