spellcast.inc --- This will cast a spell reliably for you.

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot.

Moderator: MacroQuest Developers

ionsf
a ghoul
a ghoul
Posts: 94
Joined: Wed Jan 14, 2004 10:19 pm

spellcast.inc --- This will cast a spell reliably for you.

Post by ionsf » Tue Jan 27, 2004 2:41 am

Figured this is popular too...

Code: Select all

| SpellCast.inc 
| This will cast a spell reliably for you... 
| Usage: 
| /call Cast "spellname" 
| or 
| /call Cast "itemname" [item] 
| example: /call Cast "Death Peace" 
| example: /call Cast " 
| It will return the following values: 
| CAST_SUCCESS 
| CAST_UNKNOWNSPELL 
| CAST_OUTOFMANA 
| CAST_OUTOFRANGE 
| CAST_CANNOTSEE 
| CAST_STUNNED 
| CAST_RESISTED 
| 
| New Vars Modification 
| Plazmic's no globals needed version 
| 

| Oct 9, 2003 - Updated to work with new vars and $char(casting) - gf 
| Oct 11, 2003 - switched some logic, removed defines - gf 
| Oct 15, 2003 - Item support added by EqMule 
|  Modified to add automeming of spells. Goofmester1 
| Dec 26, 2003 fd fail 1 added by m0nk 

#event Fizzle "Your spell fizzles" 
#event Interrupt "Your casting has been interrupted" 
#event Interrupt "Your spell is interrupted." 
#event Recover "You haven't recovered yet..." 
#event Recover "Spell recovery time not yet met." 
#event Resisted "You target resisted the " 
#event OutOfMana "Insufficient Mana to cast this spell!" 
#event OutOfRange "Your target is out of range, get closer!" 
#event NoLOS "You cannot see your target." 
#event Stunned "You cannot cast while stunned" 
#event Standing "You must be standing to cast a spell" 
#event Standing "has fallen to the ground." 
#event Collapse "Your gate is too unstable, and collapses." 

Sub Cast(SpellName,Item) 
   /sendkey up up 
   /sendkey up down 
   /delay 5 
   /if "@Item"=="Item" /goto :StartCast 
   /if n $char(gem,"@SpellName")==0 { 
      /memspell 5 "@SpellName" 
      /delay 5s 
      } 
   :StartCast 
      /if "@Item"=="Item" { 
         /call ClearReturnValue 
         /cast item "@SpellName" 
      } else { 
         /if n $char(gem,"@SpellName")==0 /return CAST_UNKNOWNSPELL 
         /call ClearReturnValue 
         /if n $char(gem,"@SpellName")<0 { 
            /delay 0 
            /goto :StartCast 
            } 
            /cast "@SpellName" 
         } 
   :WaitCast 
      /if "$char(casting)"=="TRUE" { 
      /delay 1 
      /goto :WaitCast 
      } 
   /delay 1 
   /doevents Fizzle 
   /doevents Interrupt 
   /doevents Interrupt 
   /doevents Recover 
   /doevents Standing 
   /doevents OutOfRange 
   /doevents OutOfMana 
   /doevents NoLOS 
   /doevents Resisted 
   /if "$return"=="CAST_RESTART" /goto :StartCast 
   /if "$return"!="CAST_SUCCESS" /return "$return" 
/return CAST_SUCCESS 

Sub ClearReturnValue 
/return NULL 

Sub Event_Fizzle 
/return CAST_RESTART 

Sub Event_Interrupt 
/return CAST_RESTART 

Sub Event_Recover 
   /delay 5 
/return CAST_RESTART 

Sub Event_Standing 
   /stand 
/return CAST_RESTART 

Sub Event_Collapse 
/return CAST_RESTART 

Sub Event_OutOfMana 
/return CAST_OUTOFMANA 

Sub Event_OutOfRange 
/return CAST_OUTOFRANGE 

Sub Event_NoLOS 
/return CAST_CANNOTSEE 

Sub Event_Stunned 
   /delay 1s 
/return CAST_RESTART 

Sub Event_Resisted 
/return CAST_RESISTED 

distler
orc pawn
orc pawn
Posts: 29
Joined: Mon Nov 03, 2003 10:04 am

Post by distler » Fri Feb 06, 2004 6:02 am

Change:

Code: Select all

#event Resisted "You target resisted the " 
To:

Code: Select all

#event Resisted "Your target resisted the " 
A little misspelled your there made me scratch my head a while why it would not give me the proper $return value, but now it works :roll:

LamahHerder
a hill giant
a hill giant
Posts: 299
Joined: Sat Jun 29, 2002 2:37 am

Post by LamahHerder » Sat Feb 07, 2004 3:47 am

Some more updates if anyone wants them.

Logic of CastGiveUpTime is that it will only wait a certain amount of time for gem to become avail before giving up, it will then return CAST_Took2LONG

Have had problems with some long refresh spells killing macros, if you dont want this functionality make sure to edit :StartCast section and set CastGiveUpTime to something drastic like 10m.

Code: Select all

| SpellCast.inc
| This will cast a spell reliably for you...
| Usage:
| /call Cast "spellname"
| or
| /call Cast "itemname" [item]
| example: /call Cast "Death Peace"
| example: /call Cast "
| It will return the following values:
| CAST_SUCCESS
| CAST_UNKNOWNSPELL
| CAST_OUTOFMANA
| CAST_OUTOFRANGE
| CAST_CANNOTSEE
| CAST_STUNNED
| CAST_RESISTED
| CAST_TOOK2LONG 
|
| New Vars Modification
| Plazmic's no globals needed version
|
| Oct 09, 2003 - Updated to work with new vars and $char(casting) -gf
| Oct 11, 2003 - switched some logic, removed defines -gf
| Oct 15, 2003 - Item support added by -EqMule
| XXX xx, xxxx - Modified to add automeming of spells. -Goofmester1
| Dec 26, 2003 - fd fail 1 added -m0nk
| Jan 01, 2004 - timeout(5s) added to stop "dead-time" -m0nk
| Jan 01, 2004 - switchd fdfail to a standing check. -m0nk
| Jan 01, 2004 - added silence checking as a stun check -m0nk

#event Fizzle "Your spell fizzles"
#event Interrupt "Your casting has been interrupted"
#event Interrupt "Your spell is interrupted."
#event Recover "You haven't recovered yet..."
#event Recover "Spell recovery time not yet met."
#event Resisted "Your target resisted the "
#event OutOfMana "Insufficient Mana to cast this spell!"
#event OutOfRange "Your target is out of range, get closer!"
#event NoLOS "You cannot see your target."
#event Stunned "You cannot cast while stunned"
#event Stunned "You *CANNOT* cast spells, you have been silenced!"
#event Standing "You must be standing to cast a spell"
#event Standing "has fallen to the ground."
#event Collapse "Your gate is too unstable, and collapses."

Sub Cast(SpellName,Item)
	/if $defined(CastGiveUpTime)!=TRUE /declare CastGiveUpTime timer
	/sendkey up up
	/sendkey up down
	/delay 5
	/if "@Item"=="Item" /goto :StartCast
	/if n $char(gem,"@SpellName")==0 {
		/memspell 5 "@SpellName"
		/delay 5s
		}
	:StartCast
		/varset CastGiveUpTime 5s
	:CastNow
		/if "@Item"=="Item" {
			/call ClearReturnValue
			/cast item "@SpellName"
		} else {
			/if n $char(gem,"@SpellName")==0 /return CAST_UNKNOWNSPELL
			/call ClearReturnValue
			/if n $char(gem,"@SpellName")<0 {
				/if n @CastGiveUpTime==0 /return CAST_TOOK2LONG
				/delay 0
				/goto :CastNow
				}
			/cast "@SpellName"
			}
	:WaitCast
		/if "$char(casting)"=="TRUE" {
		/delay 0
		/goto :WaitCast
		}
	/delay 1
	/doevents Fizzle
	/doevents Interrupt
	/doevents Interrupt
	/doevents Recover
	/doevents Standing
	/doevents OutOfRange
	/doevents OutOfMana
	/doevents NoLOS
	/doevents Resisted
	/if "$return"=="CAST_RESTART" /goto :StartCast
	/if "$return"!="CAST_SUCCESS" /return "$return"
/return CAST_SUCCESS

Sub ClearReturnValue
/return NULL

Sub Event_Fizzle
/return CAST_RESTART

Sub Event_Interrupt
/return CAST_RESTART

Sub Event_Recover
   /delay 5
/return CAST_RESTART

Sub Event_Standing
   /stand
/return CAST_RESTART

Sub Event_Collapse
/return CAST_RESTART

Sub Event_OutOfMana
/return CAST_OUTOFMANA

Sub Event_OutOfRange
/return CAST_OUTOFRANGE

Sub Event_NoLOS
/return CAST_CANNOTSEE

Sub Event_Stunned
	/delay 1s
/return CAST_RESTART

Sub Event_Resisted
/return CAST_RESISTED

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Tue Feb 17, 2004 7:03 pm

See my later post for the new parm version.
Last edited by ml2517 on Mon Apr 12, 2004 12:23 am, edited 3 times in total.

Guest

CAST_SUCCESS

Post by Guest » Wed Feb 25, 2004 11:18 am

Pretty new to macros and was trying to make some simple stuff with this. Seems to me this macro will never return CAST_SUCCESS without changing this line.

/if "$return"!="CAST_SUCCESS" /return "$return"
to
/if "$return"!="NULL" /return "$return"

If this is completely wrong please respond or delete my post etc but been beating my head on the wall trying figure out why the hell something so simple seeming would not work. Anyway seemed to fix my issues when I changed it but haven't used it much yet so hope it will not cause other problems or that I somehow did not understand how CAST_SUCCESS was being returned. Hope this helps someone.

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Wed Feb 25, 2004 6:41 pm

I see your point , try this:

Code: Select all

/if ("$return"!="CAST_SUCCESS" && "$return"!="NULL") /return "$return" 
/return CAST_SUCCESS 
If it doesn't equal CAST_SUCCESS and doesn't equal NULL it returns whatever the current return value was.

If it equals CAST_SUCCESS or NULL it simply falls through to the second line and returns CAST_SUCCESS.

You might not need the check for CAST_SUCCESS I suppose, but threw it in there for good measure.

frabtik
a ghoul
a ghoul
Posts: 114
Joined: Sat Feb 21, 2004 10:07 am

Post by frabtik » Wed Feb 25, 2004 11:15 pm

Thanks, guess I didn't log in for previous post, anyway after playing a bit tonight seemed to take care of the issues I had and not cause any problems. Changing the line to:

Code: Select all

/if ("$return"!="CAST_SUCCESS" && "$return"!="NULL") /return "$return" 
Will just add extra processing time? Since you have never set anything to CAST_SUCCESS the first comparison will alway be true so is there a point to making it?

Also did small small tweaks some people might be interested in. Been testing and using my small piece of code to do a couple quick buffs and debuffs and found that sometimes the targeting will not work right. I have a tendency to cast a spell on one target then f8 about or esc during the cast etc. This can cause wrong target by time actually cast the spell etc, esp if you have to mem it first. Probly more code than needed to show but for noobs like me I know the extra will help someone.

Store original cast target upon call.

Code: Select all

Sub Cast(SpellName,Item)
   /declare pctargetid local
   /varset pctargetid 0
   /varset pctargetid $target(id)

Do I have to initialize the variable first? took me awhile to get some of this simple targeting figured out so didn't test without initialize yet.

Retarget before actual cast.

Code: Select all

         /target id @pctargetid
         /cast item "@SpellName" 

         /target id @pctargetid
         /alt activate "@SpellName" 

         /target id @pctargetid         
         /cast "@SpellName" 
Never hurts to retarget and check you target name before sending it to a public channel also but that of course is part of the calling routine.
Any opinions welcome, I am very new at this and have not tested the last bit of targeting code yet. Was just an issue I ran into tonight when casting that sometimes I was changing targets during the mem time etc.
Also thanks for such a useful code, just started to use it but sure is making my life simple as a noob.

User avatar
Bad Karma
a snow griffon
a snow griffon
Posts: 346
Joined: Sat Nov 22, 2003 9:34 pm
Contact:

Post by Bad Karma » Mon Mar 01, 2004 5:49 am

ml2517 wrote:I see your point , try this:

Code: Select all

/if ("$return"!="CAST_SUCCESS" && "$return"!="NULL") /return "$return" 
/return CAST_SUCCESS 
If it doesn't equal CAST_SUCCESS and doesn't equal NULL it returns whatever the current return value was.

If it equals CAST_SUCCESS or NULL it simply falls through to the second line and returns CAST_SUCCESS.
Shouldn't it read....?

Code: Select all

/if ("$return"!="CAST_SUCCESS" || "$return"!="NULL") /return "$return" 
[b]- Bad Karma
________________________________________[/b]

In our own quest for excellence, we should strive to take the time to help those who help themselves.

All others should [b]RTFM[/b]!!!!!!!!!

User avatar
Bad Karma
a snow griffon
a snow griffon
Posts: 346
Joined: Sat Nov 22, 2003 9:34 pm
Contact:

Post by Bad Karma » Mon Mar 01, 2004 6:05 am

frabtik wrote:Retarget before actual cast.

Code: Select all

         /target id @pctargetid
         /cast item "@SpellName" 

         /target id @pctargetid
         /alt activate "@SpellName" 

         /target id @pctargetid         
         /cast "@SpellName" 
I'm thinking of how to reduce the code on this...

Code: Select all

Sub ClearReturnValue
  /target id @pctargetid
/return NULL
since that sub is called before each cast attempt, or...

Code: Select all

:CastNow
   /target id @pctargetid
   /if . . .
I'm also trying to justify why you /varset pctargetid 0 before /varset to the ID.... Why do you do it that way?
[b]- Bad Karma
________________________________________[/b]

In our own quest for excellence, we should strive to take the time to help those who help themselves.

All others should [b]RTFM[/b]!!!!!!!!!

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Mon Mar 01, 2004 7:41 pm

Bad Karma wrote:
ml2517 wrote:I see your point , try this:

Code: Select all

/if ("$return"!="CAST_SUCCESS" && "$return"!="NULL") /return "$return" 
/return CAST_SUCCESS 
If it doesn't equal CAST_SUCCESS and doesn't equal NULL it returns whatever the current return value was.

If it equals CAST_SUCCESS or NULL it simply falls through to the second line and returns CAST_SUCCESS.
Shouldn't it read....?

Code: Select all

/if ("$return"!="CAST_SUCCESS" || "$return"!="NULL") /return "$return" 
No it would be &&.. but as I conceded above you'd really only have to:

Code: Select all

/if "$return"!="NULL" /return "$return" 
/return CAST_SUCCESS 

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Mon Apr 12, 2004 12:22 am

Updated for new Parm system: (This version can be used with autodebuff.mac)

See below.

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Mon Apr 12, 2004 8:10 am

Fixed a bug where the return value was being returned with quotes around it. This was throwing off macros if you were using an == operation as opposed to a ~~ on the return result.

Added in a case for slow immunity.

-- See below

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Fri Apr 16, 2004 7:13 pm

Updated:
Removed the /sendkeys and replaced with /keypress.
Last edited by ml2517 on Sat Apr 17, 2004 2:19 am, edited 1 time in total.

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Sat Apr 17, 2004 2:18 am

Updated:
Added a small delay back in if you aren't moving. It seems that sometimes you need a brief moment after standing up or you might interrupt your spell.

See below.
Last edited by ml2517 on Sat Apr 17, 2004 2:40 am, edited 2 times in total.

iluvseq
Clueless Mudslinger
Posts: 269
Joined: Mon Apr 14, 2003 10:05 am

Post by iluvseq » Sat Apr 17, 2004 2:33 am

Whacked. Thanks.
Last edited by iluvseq on Sat Apr 17, 2004 1:07 pm, edited 1 time in total.