Variables added after mac name IE /mac ts comp1 comp2...

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

Trixz
a lesser mummy
a lesser mummy
Posts: 35
Joined: Mon Apr 21, 2003 8:18 am

Variables added after mac name IE /mac ts comp1 comp2...

Post by Trixz » Thu Aug 21, 2003 1:30 pm

I have looked through many scripts posted here with variables after the name of the macro, what I mean by that is a macro where you type /macro macroname somevariablehere. I want to be able to do that in my script and I played around with the $p0 variable and I can't seem to get it to work. What I want is instead of the person who you are /assisting to be hard coded that you add it in after the macro name... so it would be... /macro fight assistname. I read the manual but I don't get the part that explains $p0 so any help would be appreciated.


This is my macro....

Code: Select all

#include spellcast.mac
Sub Main
:start
/if n $char(mana,pct)<25 /call Med
/call Fight
/goto :start

Sub Fight
:tryagain
/assist <name here>
/delay 2
/if $target()!=TRUE /goto :tryagain
/pet attack
:loop
/if n $target(hp,cur)<=50 {
/stand
/delay 1
/call cast "$char(gem,4)"
/sit
/end
}
/goto :loop

Sub Med
/assist <name here>
/if $target()=TRUE /pet attack
:checkmana
/if n $char(mana,pct)>=50 /return
/goto :checkmana
It works fine as is, but every time you change main assists you have to change the code a little.

wassup
Official Guardian and Writer of TFM
Official Guardian and Writer of TFM
Posts: 1487
Joined: Sat Oct 26, 2002 5:15 pm

Post by wassup » Thu Aug 21, 2003 2:07 pm

Most important is that you forgot the /return statement at the end of each Sub. I added them in for you. I'm not sure how the macro works without the /return statements.

I also added in what should work to make the character assist the name you designate.

Code: Select all

#include spellcast.mac
#define TheAssistee v40

Sub Main
   /if $p0=="" {
      /echo Useage: /macro assist <assistname>
      /end
   }
   /varset TheAssistee $p0
   :start 
   /if n $char(mana,pct)<25 /call Med 
   /call Fight 
   /goto :start
/return

Sub Fight 
   :tryagain 
   /assist $TheAssistee 
   /delay 2 
   /if $target()!=TRUE /goto :tryagain 
   /pet attack

   :loop 
   /if n $target(hp,cur)<=50 { 
      /stand 
      /delay 1 
      /call cast "$char(gem,4)" 
      /sit 
      /end 
   } 
   /goto :loop
/return

Sub Med 
   /assist $TheAssistee 
   /if $target()=TRUE /pet attack 
   :checkmana 
   /if n $char(mana,pct)>=50 /return 
   /goto :checkmana
/return
**Woops, caught a mistake in what I added. The /assist in Sub Med was incorrect but is fixed.
Last edited by wassup on Thu Aug 21, 2003 4:15 pm, edited 1 time in total.

Trixz
a lesser mummy
a lesser mummy
Posts: 35
Joined: Mon Apr 21, 2003 8:18 am

Post by Trixz » Thu Aug 21, 2003 2:38 pm

Thanks alot Wassup that worked perfectly. I was trying to just /assist "$p0" and that obviously didn't work. I wasn't aware that $p0 had to be assigned to a variable. Anyway thanks again for your help.

wassup
Official Guardian and Writer of TFM
Official Guardian and Writer of TFM
Posts: 1487
Joined: Sat Oct 26, 2002 5:15 pm

Post by wassup » Thu Aug 21, 2003 4:12 pm

I think the reason /assist $p0 didn't work is because $p0 is also used in Sub methods/events, in that you can pass variables to them.

Whenever you use /call $p0 is probably reset to a null value if a variable isn't passed.

My method keeps a 'permanent' record by assigning $p0 to a defined variable at the start of the macro, so $p0 is not lost so to speak.

You could do the same thing by using /varset v40 $p0, but it's not as easy to understand what v40 is. Obviously defining a variable to an understandable string is more friendly.

No problem though with the help. I don't mind helping others when they make some effort themselves.

PS: I caught a slight typo in the code I posted, so make sure you check it. It was in the Sub Med part of the code.