Casting a Spell

Cage9d9

Member
Joined
Aug 26, 2008
Messages
210
Reaction score
5
Points
18
So I've mainly done development with non-scripting languages in my past, but I always find it fun to come back to MQ2/EQ to script for automating character activities. One thing I've always noticed is that with MQ2 you generally perform an operation that may take place instantly or take x seconds to complete. Either way, that line of code is executed immediately and we move on.

For example, if I have:

/cast 8
/exit

I cast and instantly exit, instead of waiting for the cast to finish. What do you folks believe the advantage/disadvantages of using something like this:

Code:
|-------------------------------------------------------------------------------- 
|SUB: Cast a spell (int)
|-------------------------------------------------------------------------------- 
Sub CastSpell(int pSpellToCast)
	/declare vAlreadyCasting FALSE 

	|/echo int=${pSpellToCast}

	:StartCasting
	/if ( ${Me.Casting.ID} ) {
		/varset vAlreadyCasting TRUE
		/goto :StartCasting
	}
	/if ( ${vAlreadyCasting} ) {
		/delay 2s
	}
	/cast ${pSpellToCast}

	:StillCasting
	/if ( ${Me.Casting.ID} ) {
		/goto :StillCasting
	}
	|/echo Finished casting!
/return 

|-------------------------------------------------------------------------------- 
|SUB: Cast a spell (string)
|-------------------------------------------------------------------------------- 
Sub CastSpellString(pSpellToCast)
	/declare vAlreadyCasting FALSE 

	|/echo string=${pSpellToCast}

	:StartCasting
	/if ( ${Me.Casting.ID} ) {
		/varset vAlreadyCasting TRUE
		/goto :StartCasting
	}
	/if ( ${vAlreadyCasting} ) {
		/delay 2s
	}
	/cast "${pSpellToCast}"

	:StillCasting
	/if ( ${Me.Casting.ID} ) {
		/goto :StillCasting
	}
	|/echo Finished casting!
/return

In my opinion, the main disadvantage is by using these routines I've created you can't do additional processing while casting. In other words, if I started casting a complete heal, and need to cancel to do a faster heal it won't happen. Aside from not being able to do additional processing, what else am I missing?

Also, feel free to comment on my horrible scripting abilities. This functionality may exist somewhere already and I didn't even need to write this.

NOTE: Some comments about the code. The subs above will wait to cast the spell if you are already casting a spell. We delay 2s after you've finish casting the initial spell because there is the whole "refresh" cycle before spells become available again. Then we cast the spell requested, waiting for it to finish before returning.
 
You are right that the functionality already exists. Look at spellroutines.inc, it handles all of this (I think it's is included in the default install /download).

That said, there is no harm in trying to do stuff yourself even if it has already been done. It's a great way to build up your coding skills, and you never know you might come at it a different way than anyone has ever though and find a better / more efficient method.

To your problem directly, you can see in spellroutines.inc that you can pass a routine name to it. In your :StillCasting loop, you would /call this routine. That way other things can be checked while it is casting, and you can do things like cancel casting to cast another heal or such. Just keep in mind, once the called routine finishes, it's going to return back to the original place it was called. So make sure that is handled by it either not mattering when it returns, or by passing something back letting it know what to do.