Page 1 of 1

Spell Training Macro Help, please

Posted: Fri Jul 02, 2004 5:18 am
by A_new_macroer
I have two versions of the macro that I have been attempting to write.

The goal is simply to train Alteration, Divination, etc, whatever. The macro should be able to check how much mana the character still has. If it is less than, say, 10 percent, then have the character sit and med until it has full mana. Once it has full mana, just have it get up and start casting again.

The first version tries to use a pair of while loops. The MQ2 window keeps telling me that it could not parse the first while statement and exits the macro before attempting anything else, of course.

Here is the first version's code:

Code: Select all

Sub Main

:MainLoop

/while (${Me.PctMana}>10)
{
	/docommand /cast 1

	| This delay makes the macro wait until the cast time and
	| the re-cast time have elapsed
	| Granted, this delay would have to be modified according
	| to the length of the cast time and the re-cast time.
	/delay 6s
		
}

/while (${Me.CurrentMana}<${Me.MaxMana})
{
	/if(${Me.Sitting})
	{
		| Already sitting.
		| So, continue to sit.

	}else
	{

		| Standing.  Have a seat.
		/docommand /sit

	}
	
}

/goto :MainLoop

/endmacro
The second version uses a series of if statements to decide whether to cast or sit. This version chokes on the if statements. I get the following error:

Failed to parse /if command. Could not find command to execute.

Naturally, it chokes on the first if statement and exits the macro.
Here is the code for the second version:

Code: Select all

Sub Main

:Loop1

:CastLoop

/if (${Me.PctMana}>10)
{
	/docommand /cast 1

	| This delay makes the macro wait until the cast time and
	| the re-cast time have elapsed
	/delay 6s

	| Go back to the top and re-evaluate the mana remaining
	/goto :CastLoop
}

/if (${Me.PctMana}<11)
{

	| Mana is less than 11 percent
	| Time to med up
	/goto :SitLoop
}

:SitLoop
/if (${Me.CurrentMana}<${Me.MaxMana})
{
	/if (${Me.Sitting})

		| Currently sitting.
		| Go back to the top of this loop and
		| re-evaluate whether to continue medding or no
		/goto :SitLoop
	/if (${Me.Standing})

		| You weren't sitting.
		| Have a seat and med up.
		/docommand /sit

		| Go back to the top of this loop and
		| re-evaluate whether to continue medding or no
		/goto :SitLoop
}


| In going back over this macro, I realized that this next if
| was not required because if CurrentMana !< MaxMana, then
| the macro is going to jump down to /goto :Loop1 without this
| if in the way.
| Leaving this if in the macro simply to be complete and
| thorough.
/if (${Me.CurrentMana}==${Me.MaxMana})
{
	/docommand /sit
	/goto :CastLoop
}

/goto :Loop1

/return
Any help anyone could give me in regards to this would be greatly appreciated. I have spent 3 hours tonight and several hours yesterday going over many of the posts in most of the headings. There are tons of macros to examine and I have clicked on any topics that had a subject line that appeared MIGHT lead to some fruitful discovery and have spent quite a bit of time with the help file, too.

Additionally, I did have a working version that couldn't evaluate how much mana the character had remaining, but it DID cast the spell over and over again. Alas, in my attempts to get this macro working I have over-written the semi-working version. What that version did manage to do, though, is to cast the spell, wait 6s, sit, stand, repeat. If I recall correctly, that version did not use the goto's for :CastLoop and :SitLoop. I simply used effectively ordered and nested if statements to accomplish what I wanted. However, to meditate, I had to end the macro. My goal is to get a macro that I wrote (& thus understand better) that allows me to have my characters practice any spell skills they can outside of combat. I managed to do this with my monk and have posted that macro for others to make use of.

Thanks in advance.

Edit: Added code brackets.

Posted: Fri Jul 02, 2004 8:06 am
by Me.Name
A few things:

1) You need to use the "Code" BBCode tags for your macro code.
2) There is no /while statement in MQ2 (there is a /for though). You need to use labels, /if, and /goto.
3) Alot of what you need is in the very well written manual. Look for the file "readme.chm" in your MQ2 directory.

Here is a spellcast trainer I use from time to time. It just recasts the same spell over and over, but it does med when needed. You need spellcast.inc in your macro directory to use this macro.

I hope this helps.

Code: Select all

| cast.mac
|
| use: /macro cast "spell name"
| Quotes are needed for spell names with more than
| one word.
|
| This macro has random delays and such included
| to simulate someone just hitting a hotkey to
| cast the same spell repeadetly for skillups.
| I use it in PoK with myself targeted. If you
| don't currently have spell memmorized, it will
| mem spell into gem1 then cast.
| If you want summoned items destryed, uncomment
| the line with the "/destroy" command.
|
| This macro uses "spellcast.inc" so be sure it
| is in your macro directory.

#include spellcast.inc

Sub Main
    :loop
    /echo casting "${Param0}"
    /call cast "${Param0}"
    |/destroy
    /if (${Macro.Return.Equal["CAST_OUTOFMANA"]}) /call Med
    /if (${Macro.Return.Equal["CAST_UNKNOWNSPELL"]}) /call Unknown
    /delay ${Math.Calc[5+${Math.Rand[5]}]}
    /goto :loop
/return

Sub Med
    /echo medding...
    /delay ${Math.Calc[10+${Math.Rand[10]}]}
    /sit
    :medloop
    /delay 20
    /if (${Me.PctMana}<100) /goto :medloop
    /delay ${Math.Calc[20+${Math.Rand[50]}]}
/return

Sub Unknown
    /echo You don't seem to have that spell in your spellbook
    /echo Ending macro
    /sit
    /endmacro
/return
EDIT: posted a more readable (and working! :lol: ) version.

Posted: Fri Jul 02, 2004 11:40 am
by A_new_macroer
Thank you very much. I had tried to use a variant of the cast.mac that you provided, but I did not have spellcast.inc and could not find it in any of the topics. Perhaps I was tired or had been looking at the screen for too long.

I wasn't entirely sure if there is a while loop in MQ2 since it wasn't in the readme, but I figured it would be worth a try since the syntax was so much like C++. I did try a /for, but it kept kicking that back at me telling me that I hadn't declared the variable correctly. I had tried:

Code: Select all

/for int aCounter 0 to 1
and a couple other variants of that, but I am not going to cite those here because the example I have given is the closest in syntax to the example in the readme.

Again, thanks very much. This was only the 2nd macro that I had tried to write.

Posted: Fri Jul 02, 2004 8:03 pm
by Me.Name
There is a link to the original spellcast.inc thread in my post.
Here it is again: spellcast.inc
Some people prefer: spell_routines.inc
Both can be used the same way.

Posted: Fri Jul 02, 2004 8:06 pm
by blueninja
I think the brace after /if () needs to be on the same line.

Posted: Fri Jul 02, 2004 8:41 pm
by Space-Boy
this is what i use to skill up my cleric and/ or chain summon food / drink on login. i put /autoinventory in 3 times due to some lag in zones when i summon the food making the items stay on the cursor. works perfectly as long as you check your skill, IE no skill check, just do

/mac chaincast <gem#> example /mac chaincast 1

Code: Select all


#include spellcast.inc 
#event NoComponents "You are missing some required components." 

Sub Main 
   /declare SpellName 
   /varset SpellName ${Me.Gem[${Param0}]} 
   /if (${Me.State.Equal[SIT]}) /stand 

    :CheckMana 
    /if (${Me.PctMana}<20) /goto :SitDown 

   :CastSpell 
   /autoinventory
   /autoinventory
   /autoinventory
   /call cast "${SpellName}" 
   /doevents 
   /goto :CheckMana 
   /goto :castspell

/return   

    :SitDown 
    /if (${Me.State.Equal[STAND]}) /sit on 

    :HowMuchMana 
    /if (${Me.PctMana}<98) /goto :HowMuchMana 
    /goto :CheckMana 
/endmacro 

Sub Event_NoComponents 
   /popup No More Items to Make 
   /endmacro 
/return 
edit- also good for imbueing / enchanting things =) auto stops when youre all out of components

Posted: Fri Jul 02, 2004 9:35 pm
by Drumstix42

Code: Select all

:HowMuchMana 
    /if (${Me.PctMana}<98) /goto :HowMuchMana 
That doesn't really work with your ManaCheck part that checks if you under 20% mana.

That code would going through a quick loop while you stand there until you had 98% mana

Posted: Sun Jul 04, 2004 3:00 am
by Chill
look here. May do what you want or give you some ideas.