!@#%! I know this has got to be something stupid..

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

Moderator: MacroQuest Developers

NobodyImportant
a lesser mummy
a lesser mummy
Posts: 46
Joined: Sun Nov 02, 2003 8:42 pm

!@#%! I know this has got to be something stupid..

Post by NobodyImportant » Tue Jun 01, 2004 1:58 am

I have looked over this god damn code 5,000,000,000,000,000,000 times and cannot figure out what in the HELL is wrong with it, the exact same code was working a few nights before just being called from a diffrent mac

Code: Select all

sub MoveToMob(Distancetomob) 

   /if (${Target.Distance}<${Distancetomob}) { 
      /face fast
      /return 
   } 
 
   :Movementloop 

  /if (${Me.Speed}==0) {

/keypress up hold
}
  
      /varcalc ObstCount ${ObstCount}+1 
       /if (${Bool[${Target}]}==0) {  
      /keypress up
          /return 
       } 
       /face fast
       /if (${Target.Distance}<${Distancetomob}) { 
          /face fast
          /keypress up 
          /return 
       } 
       /if (${ObstCount}>=3) { 
         /delay 5
          /call CheckObst 
          /goto :Movementloop 
       } 
   /if (${Target.Distance}>${Distancetomob}) /goto :MovementLoop 
/return 

Sub CheckObst 


/if (${Math.Calc[${Math.Calc[${Math.Calc[${Math.Calc[${Me.Y}-${MyYLoc}]}^2]}+${Math.Calc[${Math.Calc[${MyXLoc}-${Me.X}]}^2]}]}^.5]}<2) /call Hitobst 5

   /varset MyXLoc ${Me.X}
   /varset MyYLoc ${Me.Y} 

/return 

Sub Hitobst(Delayofturn) 
   /keypress up 
   /keypress down hold 
   /if (${Math.Rand[100]}>50) { 
      /Delay 1s 
      /keypress down 
      /keypress Right hold 
      /Delay ${Delayofturn}
      /keypress Right 
      /keypress up hold 
      /Delay 1s 
      /keypress up 
   } else { 
      /Delay 1s 
      /keypress down 
      /keypress left hold 
      /Delay ${Delayofturn} 
      /keypress left 
      /keypress up hold 
      /Delay 1s 
      /keypress up 
   } 
:speedstop
  /if (${Me.Speed}!=0) /goto :speedstop

/return 

I know this code is probably not very clean and could be made much more efficiant, but its what I've come up with so far from looking at example's and surfing around for answers, I'd use a movetomob out of like hunter or something, but it goes to melee range, and im a caster so i need to keep my distance to send pet.. so just a little help on what in the fucking hell is up with this code would be much appreciated.


Oh yes, the error it puts out is: Calculate encountered a bad - formation, then spews out

Code: Select all


/if (${Math.Calc[${Math.Calc[${Math.Calc[${Math.Calc[${Me.Y}-${MyYLoc}]}^2]}+${Math.Calc[${Math.Calc[${MyXLoc}-${Me.X}]}^2]}]}^.5]}<2) /call Hitobst 5
As the problem causing code.

dman
a hill giant
a hill giant
Posts: 181
Joined: Fri Dec 05, 2003 12:54 pm

Post by dman » Tue Jun 01, 2004 4:29 am

I was only able to reproduce this error by /declare'ing the variables ${MyYLoc} and ${MyXLoc} but never setting them to anything. Make sure your code is initializing them to something or /varsetting them to something before it hits that calculate statement.

As another thing, you don't need to nest the Math.Calc's, the parser will evaluate the expression

Code: Select all

 (${Math.Calc[((${Me.Y} - ${MyYLoc})^2 + (${MyXLoc} - ${Me.X})^2)^0.5]}<2)
just as well as it parses

Code: Select all

 (${Math.Calc[${Math.Calc[${Math.Calc[${Math.Calc[${Me.Y}-${MyYLoc}]}^2]}+${Math.Calc[${Math.Calc[${MyXLoc}-${Me.X}]}^2]}]}^.5]}<2)
Its faster (slightly, less parsing) and easier to read the math expression.

Chill
Contributing Member
Contributing Member
Posts: 435
Joined: Fri May 07, 2004 5:06 pm
Location: Erie, PA

Post by Chill » Tue Jun 01, 2004 4:50 am

Not sure whats up with Calculating the square root of the square...I suppose maybe you could put the work into fixing that, but I think it might just be easier to go with newer code from Hunter. Try this:

(untested)

Code: Select all

Sub MoveToMob(Distancetomob)

   /if (${Target.Distance}<${Distancetomob}) { 
      /face fast 
      /return 
   } 

   /varset MyXLOC ${Int[${Me.X}]} 
   /varset MyYLOC ${Int[${Me.Y}]} 
   /declare MF_DistanceTimer timer 10

   /doevents
    
   :MovementLoop 
   /if (${Target.ID}) /face fast

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

   /if (${Target.Distance}<=${Distancetomob}) { 
      /keypress forward
      /return
   } 
   /if (!${MF_DistanceTimer}) { 
      /if ((${MF_MyXLOC}==${Int[${Me.X}]})&&(${MF_MyYLOC}==${Int[${Me.Y}]})) /call CheckObst 
      /varset MF_MyXLOC ${Int[${Me.X}]} 
      /varset MF_MyYLOC ${Int[${Me.Y}]} 
      /varset MF_DistanceTimer 10 
      /goto :Movementloop 
   } 
   /if (${Target.Distance}>${Distancetomob}) /goto :MovementLoop 

/return 

Sub Hitobst(Dly)

   /if (${Corpse.Open}) /notify LootWnd DoneButton leftmouseup

   /echo Obstacle hit, moving around it... 
   /keypress forward 
   /keypress back hold 
   /delay 5 
   /keypress back 
   /if (${Math.Rand[100]}>50) { 
     /keypress strafe_right hold 
   } else { 
     /keypress strafe_left hold 
   } 
   /delay ${dly}
   /keypress strafe_right 
   /keypress strafe_left 
   /keypress forward hold

   /delay 1
   /keypress jump

/return

NobodyImportant
a lesser mummy
a lesser mummy
Posts: 46
Joined: Sun Nov 02, 2003 8:42 pm

Post by NobodyImportant » Tue Jun 01, 2004 11:39 am

The idea is for when you character get stuck on a rock or something, and he moves ever so slightly, just like 10-20 decimals to the left or right, and thats just enough to make the normal checkobst think he's still moving, so your character will sit on a rock moving barely at all left or right for several minutes until he decides to stop being dumb and objhit, with this calc, that doesnt matter, if he is within 2 locs from the last time checkobst runs, he's going to move to avoid it, i was encountering this problem alot so i used the math and it works great.




Thanks Dman for the help! this script was really pissing me off.