Bad Karma's ADVANCED SpellCast.inc [03.31.04]

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

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

Post by LamahHerder » Sun Apr 18, 2004 2:58 pm

hrmm actually it should be possible to check if a spell was successfull via mana usage, which would be the best way to do the check, a sub/section that checks resist/slow+movement events/mana consumption at the very end before we do the actuall return

Yes i know different items/aa will lower mana consumption but say we calculate and if mana consued was atleast 40% of what the spell required to call that a cast success.

The actual percentage needs to be figured out but with specialization+focus+aa's I think you can get as high as 60% conservation, and a fizzle i doubt is higher then 10% so i figure it would be somewhere in there, that would seem the most accurate way to verify if the spell was cast or not.

Im still waiting on new system to be fully implemented before i start adding anything to macros or atleast macros to be converted, but I think thats the way we should go.

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

Post by frabtik » Mon Apr 19, 2004 10:17 am

This sounds pretty good to me, fizzles are not really an issue in this area. You always get a msg for fizzles so doesn't really matter. The major issue before I came up with the mana pres idea was that if you do not have los or lose los when casting etc, often you get no msg or indication that the spell did not cast. Sometimes the macro will execute a cast command and eq basically just does nothing, doesn't even start to cast or it starts but just doesn't finish but still gives no msg to let you know this. The macro bases success on the fact that it gets no indication of failure. While checking for a success type msg might appear to be a logical solution, these msgs are not seen if the mob is past say 190ish or which is right on the limits of normal casting range. I will most likely be looking into implementing this since I feel it will fix the minor issue I have now which is the mana pres msgs are not there if you don't have your gear. But if anyone has done this or already and has some code they are testing be great to look at to save some debugging.

Guest

Post by Guest » Mon Apr 19, 2004 1:26 pm

well like i was saying,

I figure the checks for success should be done first for speed, and if those checks are not met then go ahead figure out what went wrong

the logic flow....
after spellcasting stoped....
1. if event "cannot slow" return error
2. if event "cannot change speed" return error
3. if enough mana used "return success"
4. else goto error-check-rotuine

ImaNoob
a ghoul
a ghoul
Posts: 89
Joined: Mon Mar 08, 2004 4:37 am

Number 3 is wrong

Post by ImaNoob » Wed Apr 21, 2004 2:45 am

#3 Needs to be... If (mana consumed) && ( mob HP == previous mob HP) , return CAST_OUT_OF_RANGE, else goto 4.

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 » Wed Apr 21, 2004 4:46 am

Well, I took a shot at converting this to the new system.

I made some notes and changed the version to start at 4.00.00.

If anyone sees something I goofed on or missed, post a reply.

When Bad Karma updates his first post I will delete this one.

Code: Select all

|
| Bad Karma's ADVANCED SpellCast.inc
|
| This will cast a spell - and more - reliably for you...
|
|
|     |=========================================|
|     |  USAGE:                                 |
|     |  ¯¯¯¯¯¯   /call Cast "Spell Name"       |
|     |     or:                                 |
|     |           /call Cast "Item Name" Item   |
|     |     or:                                 |
|     |           /call Cast "AA#" Activate     |
|     |=========================================|
|     |        Reccomended #turbo               |
|     |=========================================|
|
|  It will return the following values:
|     CAST_ABILITYNOTREADY
|     CAST_CANCELLED
|     CAST_CANNOTSEE
|     CAST_FAIL
|     CAST_NOSPELLGIVEN
|     CAST_OUTDOORS
|     CAST_OUTOFMANA
|     CAST_OUTOFRANGE
|     CAST_RESISTED
|     CAST_SILENCED
|     CAST_SUCCESS
|     CAST_TOOK2LONG
|     CAST_TOOPOWERFUL
|     CAST_UNKNOWNSPELL
|     FD_FAILED
|
| 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
| Xxx XX, 2003 - Modified to add automeming of spells. Goofmester1
| Dec 26, 2003 - fd fail 1 added by m0nk
| Dec 28, 2003 - Modded for functionality in a variety of macs for multiple classes - Bad Karma
| Jan 01, 2004 - timeout(5s) added to stop "dead-time" -m0nk
| Feb 09, 2004 - Further updates to include handle a few more events,
|                Mount support, Face target (ml2517), Giveup timer (m0nk)
|                updated MemSpell, and a few minor personalizations. - Bad Karma
| Feb 17, 2004 - added AA activate capabilities -ml2517
| Feb 18, 2004 - More tweaks.  Mostly to casting routine to account for several
|                character states, Spell Memorization, and added a Med sub (also
|                now checks to see if you have enough mana to cast after memming),
|                added more #events & corrected others, commented out the spam,
|                but left it in the script in case you want it or need it for
|                GenBot or whatever....  Little better organized, too.   - Bad Karma
| Feb 28, 2004 - Added support to ensure the right (orginial) target is up before casting. - Frabtik
| Mar 08, 2004 - Now supports /keypress. - Bad Karma
| Mar 14, 2004 - Logic Changes: sit + med wait + fdfail + oor wait + stun + charm / most sits removed
|                Changed Returns for Night Spells + Distracted / @CastGiveUpTime where it was missed. /
|                format changes / face NOT default / /multiline / extra target checks /
|                ver# change (mm.dd.yyx) / <stuff i forgot.> - (m0nk)
| Mar 15, 2004 - Fixed some issues with the new Stun code which was preventing it from triggering.
|                Updated the FACE option.  1=normal, 2=fast, 0 or anything else (including null)= off.
| Mar 19, 2004 - Bad Karma ~ Again, many thanks to m0nk for the updates/suggestions!  (Made a few bug fixes again to them *grin*)
|                Added:  FEARed support, CAST_CANCELLED
|                          To CANCEL a spell, simply DUCK out.
|                             I put this before /cast, and at the start of MedUp, MemSpell, :LoopWaitOFF,
|                             and Event_Interrupt (so it wouldn't unintentially trigger that event and force a re-cast)...
|                             This should cover any last-second cancel attempts.  Let me know if more are needed.
|                Fixed:  STUN & FEAR bugs, CAST_ABILITYNOTREADY,
|                Changed:  StunON/OFF to WaitON/OFF to tie it in with FEAR/CHARM/STUN and possible future updates.
|                          Moved /call FACE to :WaitCast.  Will now face while casting to help speed up the overall casting process.
|                             NOTE:  DEFAULT changed to 1 (FACE SLOW)
|                             Removed version from top of file...too many places to update it!
| Mar 20, 2004 - Bad Karma ~ Will now re-mem any spell that the script had to overwrite while casting.
| Mar 26, 2004 - frabtik   ~ Added check for cast success based on mana preservation item results being displayed.
| Apr 21, 2004 - Wassup    ~ Initial conversion to the MQ2Data format.
|
|
|  NOTE:  All /echo commands are for debugging and feedback only.  They can be safely removed.
|  ¯¯¯¯¯  All /tell commands were left in for bot support (GenBot & BuffBot) - you can safely kill these, also.
|
|
|**
[SpellCast]
Version=04.00.00
**|
|


#event Ability "You can use the ability "
#event Collapse "Your gate is too unstable, and collapses."
#event Distracted "You are too distracted to cast a spell now!"
#event FDFail "You are no longer feigning death"
#event Fizzle "Your spell fizzles"
#event Interrupt "Your casting has been interrupted"
#event Interrupt "Your spell is interrupted."
#event NoLOS "You cannot see your target."
#event NotHold "Your spell would not have taken hold on your target."
#event OnlyAtNight "Spell can only be cast during the night."
#event OutOfMana "Insufficient Mana to cast this spell!"
#event OutOfRange "Your target is out of range, get closer!"
#event Outdoors "You can only cast this spell in the outdoors."
#event Recover "You haven't recovered yet..."
#event Recover "Spell recovery time not yet met."
#event Resisted "Your target resisted the "
#event Silenced "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 Success " flickers with a pale light."
#event TooPowerful "Your spell is too powerful for your intended target."
#event Unknown "You do not seem to have that spell memorized."
#event WaitON "Your mind is wracked by fear."
#event WaitON "You cannot cast while stunned"
#event WaitON "You are stunned"
#event WaitON "You lose control of yourself!"
#event WaitOFF "You are unstunned"
#event WaitOFF "You have control of yourself again."
#event WaitOFF "You are no longer afraid."


Sub Cast(SpellName,Item)
| Can't cast while we're moving, so let's make sure we're not!
   /multiline ; /keypress forward;/keypress back;/keypress left;/keypress right;/keypress strafe_left;/keypress strafe_right;/delay 2
| Store the current Target ID before doing anything, just in case we loose our target before we actually cast.
   /newif (!${Defined[PCTargetID]}) /declare PCTargetID local
   /varset PCTargetID 0
   /varset PCTargetID ${Target.ID}
   /newif (!${String[@SpellName].Length}) {
      /echo ERROR:  Attempted to cast an undefined spell!  ("@SpellName")
      /return CAST_NOSPELLGIVEN
   }
   /newif (!${Defined[CastGiveUpTime]}) /declare CastGiveUpTime timer
   /newif (!${Defined[Item]}) /declare Item local
   /newif (${String[@Item].Equal[Item]} || ${String[@Item].Equal[Activate]}) /goto :StartCast
   /newif (!${Me.Gem[@SpellName]}) /call MemSpell "@SpellName"

   :StartCast
      /newif (${Me.CurrentMana}<${Spell[@SpellName].Mana}) /call MedUp
      /varset CastGiveUpTime 10s
      /echo Casting "@SpellName" on ${Target.NameClean}
|      /tell "@Sender" Casting "@SpellName" on ${Target.NameClean}

   :CastNow
      /newif (!${Me.Mount} && ${Me.State.NotEqual[STAND]}) /stand
      /delay 1
      /newif (!${Target.ID} && ${Target.ID}!=@PCTargetID && ${Target.ID}!=${Me.ID}) /target id @PCTargetID
      /delay 1
      /newif (${String[@Item].Equal[Item]}) {
         /call ClearReturnValue
         /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
         /cast item "@SpellName"
      } else /newif (${String[@Item].Equal[Activate]}) {
         /call ClearReturnValue
         /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
         /alt activate "@SpellName"
      } else {
         /newif (!${Me.Gem[@SpellName]}) /return CAST_UNKNOWNSPELL
         /call ClearReturnValue
         /newif (!${Me.SpellReady[@SpellName]} {
            /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
            /delay 0
            /goto :CastNow
         }
         /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
         /cast "@SpellName"
      }

   :WaitCast
      /newif (${Me.Casting.ID}) {
         /delay 0
| This line handles IF and HOW you will face your spell target (while casting).
| 1 = FACE SLOW (NORMAL SPEED)     2 = FACE FAST     Any other #, 0, or null = DO NOT FACE
| Default:  FACE NORMAL (SLOW).
         /call Face 1
         /goto :WaitCast
      }

   /call ClearReturnValue
   /delay 1

   /doevents Ability
   /doevents Collapse
   /doevents Distracted
   /doevents FDFail
   /doevents Fizzle
   /doevents Interrupt
   /doevents NoLOS
   /doevents NotHold
   /doevents OnlyAtNight
   /doevents OutOfMana
   /doevents OutOfRange
   /doevents Outdoors
   /doevents Recover
   /doevents Resisted
   /doevents Silenced
   /doevents Standing
   /doevents WaitON
   /doevents TooPowerful
   /doevents Unknown
   /doevents Success

   /newif (${Macro.Return.Equal[CAST_ABILITYNOTREADY]}) /return ${Macro.Return}
   /newif (${macro.Return.Equal[CAST_CANCELLED]}) /goto :FixSpell
   /newif (${Macro.Return.Equal[CAST_CANNOTSEE]}) /goto :StartCast
   /newif (${Macro.Return.Equal[CAST_FAIL]}) /goto :FixSpell
   /newif (${Macro.Return.Equal[CAST_NOSPELLGIVEN]}) /goto :FixSpell
   /newif (${Macro.Return.Equal[CAST_OUTDOORS]}) /goto :FixSpell
   /newif (${Macro.Return[CAST_OUTOFMANA]}) /goto :StartCast
   /newif (${Macro.Return.Equal[CAST_OUTOFRANGE]}) /goto :StartCast
   /newif (${Macro.Return.Equal[CAST_RESISTED]}) /goto :StartCast
   /newif (${Macro.Return.Equal[CAST_RESTART]}) /goto :StartCast
   /newif (${Macro.Return.Equal[CAST_SILENCED]}) /goto :StartCast
   /newif (${Macro.Return.Equal[CAST_TOOK2LONG]}) /goto :FixSpell
   /newif (${Macro.Return.Equal[CAST_TOOPOWERFUL]}) /goto :FixSpell
   /newif (${Macro.Return[CAST_UNKNOWNSPELL]}) /goto :FixSpell
   /newif (${Macro.Return.Equal[CAST_WAITOFF]}) /goto :StartCast
   /newif (${Macro.Return.Equal[FD_FAILED]}) /return ${Macro.Return}
   /newif (${Macro.Return.NotEqual[CAST_SUCCESS]} && !${Macro.Return.Length}) /goto :FixSpell

   :FixSpell
|      /newif (${Defined[OldSpellName]}) {
|         /newif (${String[@OldSpellName].NotEqual[@SpellName]} && ${String[@OldSpellName].Length}>0) {
|            /memspell 7 "@OldSpellName"
|            /delay 5
|            /varset @OldSpellName ""
            /return ${Macro.Return}
|         }
|      }
/return CAST_SUCCESS

Sub MemSpell(SpellName)
   /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
   /echo Memorizing:  "@SpellName"...
|  /tell "@Sender" Just a sec...gotta mem "@SpellName"
| Store the current Spell ID before doing anything so we can leave the way we came in.
|   /if $defined(OldSpellName)!=TRUE /declare OldSpellName local
|   /varset @OldSpellName ""
|   /varset "@OldSpellName" "$char(gem,7)"
| Change the # below if you want to put the spell in a different slot.
   /memspell 7 "@SpellName"
   /delay 5

:MemWait
   /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
   /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
   /delay 0
   /newif (${Me.State.Equal[STAND]} && ${Me.Mount}) /return CAST_RESTART
   /newif (!${Me.SpellReady[@SpellName]}) /goto :MemWait
/return CAST_RESTART

Sub MedUp
   /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
   /echo Medding...
   /newif (!${Me.Mount} && ${Me.State.NotEqual[SIT]} /sit on
   /delay 1

:MedStart
   /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
   /delay 0
   /newif (!${Me.Mount} && ${me.State.NotEqual[SIT]}) /return
   /newif (${Me.CurrentMana} <= ${Spell[@SpellName].Mana}) /goto :MedStart
   /newif (!${Me.Mount} && ${Me.State.NotEqual[STAND]}) /sit off
/return

Sub Face(UseFaceFast)
   /declare Angle local
   /declare TX local
   /declare TY local
   /declare TZ local
   /declare FZ local
   /varset TX ${Target.X}
   /varset TY ${Target.Y}
   /varset TZ $(Target.Z}
   /varset FZ ${Me.Z}

   /newif (${Me.FeetWet}) /varadd TZ 5
   /newif (${Me.Levitating}) /varadd TZ 2
   /varset Angle $abs($asin($calc($abs($calc(@FZ-@TZ))/$sqrt($calc($calc($calc($calc(@TX-$char(x))^2)+$calc($calc(@TY-$char(y))^2))+$calc($calc(@TZ-@FZ)^2))))))

   /newif (@UseFaceFast==1) {
      /face nolook loc @TY,@TX
   } else {
      /newif (@UseFaceFast==2) {
         /face fast nolook loc @TY,@TX
      }
   } else {
      /return
   }
   /newif (@TZ<@FZ) {
      /look ${Math.Calc[@Angle*-1]}
   } else /newif (@TZ>@FZ) {
      /look @Angle
   } else {
      /look 0
   }
/return

Sub ClearReturnValue
/return NULL

Sub Event_Ability
|   /echo Event_Ability
|   /tell "@Sender" I cannot use that ability right now!
/return CAST_ABILITYNOTREADY

Sub Event_Collapse
|   /echo Event_Collapse
|   /tell "@Sender" My Gate was too unstable and has collapsed!
/return CAST_RESTART

Sub Event_Distracted
|   /echo Event_Distracted
|   /tell "@Sender" I am too distracted to cast any spells right now!
/return CAST_SUCCESS

Sub Event_FDFail
|   /echo FD_FAILED
|   /tell "@Sender" They didn't buy it, boss!  Feign Death has failed!
    /newif (${Me.State.Equal[FEIGN]}) /stand
/return FD_FAILED

Sub Event_Fizzle
|   /echo Event_Fizzle
|   /tell "@Sender" Damn fizzles!  Trying again...
/return CAST_RESTART

Sub Event_Interrupt
   /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/return CAST_RESTART

Sub Event_NoLOS
|   /echo Event_NoLOS
|   /tell "@Sender" I cannot see ${Target.CleanName}.  Waiting 5 seconds for it to get a little closer before casting again.
    /sit on
    /delay 5s
    /sit off
/return CAST_CANNOTSEE

Sub Event_NotHold
|   /echo Event_NotHold
|   /tell "@Sender" "@SpellName" did not take hold on ${Target.CleanName}.
/return CAST_SUCCESS

Sub Event_OnlyAtNight
|   /echo Event_OnlyAtNight
|   /tell "@Sender" It's too bright out!  "@SpellName" should be cast at night!
/return CAST_SUCCESS

Sub Event_OutOfMana
|   /echo Event_OutOfMana
|   /tell "@Sender" Insufficient mana to cast "@SpellName"!  Medding for a moment and trying again...
   /call MedUp
/return CAST_OUTOFMANA

Sub Event_OutOfRange
|   /echo Event_OutOfRange
|   /tell "@Sender" ${Target.CleanName} is out of range.  Waiting for it to get a little closer before casting again.
   /sit on
:WaitRange
      /delay 0
      /newif (!${Me.Mount} && ${Me.State.NotEqual[SIT]}) /goto :InRange
      /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
      /newif (${Target.Distance}>200) /goto :WaitRange
:InRange
   /sit off
/return CAST_OUTOFRANGE

Sub Event_Outdoors
|   /echo Event_Outdoors
|   /tell "@Sender" Mommy told me only to cast "@SpellName" when I am outside!
/return CAST_OUTDOORS

Sub Event_Recover
|   /echo Event_Recover
|   /tell "@Sender" Oops!  Have't recovered yet...trying again!
   /delay 5
/return CAST_RESTART

Sub Event_Resisted
|   /echo Event_Resisted
|   /tell "@Sender" ${Target.CleanName} resisted my "@SpellName" spell!  Trying again...
   /delay 1s
/return CAST_RESISTED

Sub Event_Silenced
|   /echo Event_Silenced
|   /tell "@Sender" Shh!  I have been SILENCED!!!  Trying again in 3 seconds.
   /delay 3s
/return CAST_SILENCED

Sub Event_Standing
   /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
|   /echo Event_Standing
|   /tell "@Sender" You mean I have to stand up now?  Oh, alright...casting "@SpellName" for you THIS time!
   /stand
/return CAST_RESTART

Sub Event_Success
|  /echo Event_Success
/return CAST_SUCCESS

Sub Event_TooPowerful
|   /echo Event_TooPowerful
|   /tell "@Sender" I am ubah!  My spellz are too powaful 4 ${Target.CleanName}
/return CAST_TOOPOWERFUL

Sub Event_Unknown
|   /echo Event_Unknown
|   /tell "@Sender" You want me to cast WHAT!?!?  I've never heard of a spell called "@SpellName" before.
/return CAST_UNKNOWNSPELL

Sub Event_WaitON
|   /echo Event_Wait
|   /tell "@Sender" I am STUNNED or FEARED!!!  Trying again once I regain control of myself.
   /doevents flush WaitOFF
:LoopWaitOFF
   /newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
   /multiline ; /doevents WaitOFF;/newif (${Macro.Return.Equal[WaitOFF]}) {
      /call ClearReturnValue
      /return CAST_WAITOFF
   }
   /goto :LoopWaitOFF

Sub Event_WaitOFF
|   /echo Recovered from Stun...
/return CAST_WAITOFF

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

Post by frabtik » Thu Apr 22, 2004 10:06 am

This working at all? I am getting subroutine not found when I try it. I can't see any reason why it wouldn't work, I can trade out the other spellcast.inc file and it works so I don't think it is the calling macro. Any help appretiated.

javelinl
a lesser mummy
a lesser mummy
Posts: 70
Joined: Thu Mar 11, 2004 12:40 pm

Not working

Post by javelinl » Thu Apr 22, 2004 11:55 am

I'm getting the same (sub cast not found).

javelinl
a lesser mummy
a lesser mummy
Posts: 70
Joined: Thu Mar 11, 2004 12:40 pm

Fix

Post by javelinl » Thu Apr 22, 2004 12:02 pm

Replacing

|**
[SpellCast]
Version=04.00.00
**|

with

||**
[SpellCast]
Version=04.00.00
**|

will let you find the functions. However, any reference to Me. seems to fail in this and in any macro. Is Me implemented?

javelinl
a lesser mummy
a lesser mummy
Posts: 70
Joined: Thu Mar 11, 2004 12:40 pm

Updated SpellCast.inc

Post by javelinl » Thu Apr 22, 2004 12:27 pm

I've tracked down all the typo's and this script now works for me.




|
| Bad Karma's ADVANCED SpellCast.inc
|
| This will cast a spell - and more - reliably for you...
|
|
| |=========================================|
| | USAGE: |
| | ¯¯¯¯¯¯ /call Cast "Spell Name" |
| | or: |
| | /call Cast "Item Name" Item |
| | or: |
| | /call Cast "AA#" Activate |
| |=========================================|
| | Reccomended #turbo |
| |=========================================|
|
| It will return the following values:
| CAST_ABILITYNOTREADY
| CAST_CANCELLED
| CAST_CANNOTSEE
| CAST_FAIL
| CAST_NOSPELLGIVEN
| CAST_OUTDOORS
| CAST_OUTOFMANA
| CAST_OUTOFRANGE
| CAST_RESISTED
| CAST_SILENCED
| CAST_SUCCESS
| CAST_TOOK2LONG
| CAST_TOOPOWERFUL
| CAST_UNKNOWNSPELL
| FD_FAILED
|
| 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
| Xxx XX, 2003 - Modified to add automeming of spells. Goofmester1
| Dec 26, 2003 - fd fail 1 added by m0nk
| Dec 28, 2003 - Modded for functionality in a variety of macs for multiple classes - Bad Karma
| Jan 01, 2004 - timeout(5s) added to stop "dead-time" -m0nk
| Feb 09, 2004 - Further updates to include handle a few more events,
| Mount support, Face target (ml2517), Giveup timer (m0nk)
| updated MemSpell, and a few minor personalizations. - Bad Karma
| Feb 17, 2004 - added AA activate capabilities -ml2517
| Feb 18, 2004 - More tweaks. Mostly to casting routine to account for several
| character states, Spell Memorization, and added a Med sub (also
| now checks to see if you have enough mana to cast after memming),
| added more #events & corrected others, commented out the spam,
| but left it in the script in case you want it or need it for
| GenBot or whatever.... Little better organized, too. - Bad Karma
| Feb 28, 2004 - Added support to ensure the right (orginial) target is up before casting. - Frabtik
| Mar 08, 2004 - Now supports /keypress. - Bad Karma
| Mar 14, 2004 - Logic Changes: sit + med wait + fdfail + oor wait + stun + charm / most sits removed
| Changed Returns for Night Spells + Distracted / @CastGiveUpTime where it was missed. /
| format changes / face NOT default / /multiline / extra target checks /
| ver# change (mm.dd.yyx) / <stuff i forgot.> - (m0nk)
| Mar 15, 2004 - Fixed some issues with the new Stun code which was preventing it from triggering.
| Updated the FACE option. 1=normal, 2=fast, 0 or anything else (including null)= off.
| Mar 19, 2004 - Bad Karma ~ Again, many thanks to m0nk for the updates/suggestions! (Made a few bug fixes again to them *grin*)
| Added: FEARed support, CAST_CANCELLED
| To CANCEL a spell, simply DUCK out.
| I put this before /cast, and at the start of MedUp, MemSpell, :LoopWaitOFF,
| and Event_Interrupt (so it wouldn't unintentially trigger that event and force a re-cast)...
| This should cover any last-second cancel attempts. Let me know if more are needed.
| Fixed: STUN & FEAR bugs, CAST_ABILITYNOTREADY,
| Changed: StunON/OFF to WaitON/OFF to tie it in with FEAR/CHARM/STUN and possible future updates.
| Moved /call FACE to :WaitCast. Will now face while casting to help speed up the overall casting process.
| NOTE: DEFAULT changed to 1 (FACE SLOW)
| Removed version from top of file...too many places to update it!
| Mar 20, 2004 - Bad Karma ~ Will now re-mem any spell that the script had to overwrite while casting.
| Mar 26, 2004 - frabtik ~ Added check for cast success based on mana preservation item results being displayed.
| Apr 21, 2004 - Wassup ~ Initial conversion to the MQ2Data format.
|
|
| NOTE: All /echo commands are for debugging and feedback only. They can be safely removed.
| ¯¯¯¯¯ All /tell commands were left in for bot support (GenBot & BuffBot) - you can safely kill these, also.
|
|
||**
|[SpellCast]
|Version=04.00.00
**|
|


#event Ability "You can use the ability "
#event Collapse "Your gate is too unstable, and collapses."
#event Distracted "You are too distracted to cast a spell now!"
#event FDFail "You are no longer feigning death"
#event Fizzle "Your spell fizzles"
#event Interrupt "Your casting has been interrupted"
#event Interrupt "Your spell is interrupted."
#event NoLOS "You cannot see your target."
#event NotHold "Your spell would not have taken hold on your target."
#event OnlyAtNight "Spell can only be cast during the night."
#event OutOfMana "Insufficient Mana to cast this spell!"
#event OutOfRange "Your target is out of range, get closer!"
#event Outdoors "You can only cast this spell in the outdoors."
#event Recover "You haven't recovered yet..."
#event Recover "Spell recovery time not yet met."
#event Resisted "Your target resisted the "
#event Silenced "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 Success " flickers with a pale light."
#event TooPowerful "Your spell is too powerful for your intended target."
#event Unknown "You do not seem to have that spell memorized."
#event WaitON "Your mind is wracked by fear."
#event WaitON "You cannot cast while stunned"
#event WaitON "You are stunned"
#event WaitON "You lose control of yourself!"
#event WaitOFF "You are unstunned"
#event WaitOFF "You have control of yourself again."
#event WaitOFF "You are no longer afraid."


Sub Cast(SpellName,Item)
| Can't cast while we're moving, so let's make sure we're not!
/multiline ; /keypress forward;/keypress back;/keypress left;/keypress right;/keypress strafe_left;/keypress strafe_right;/delay 2
| Store the current Target ID before doing anything, just in case we loose our target before we actually cast.
/newif (!${Defined[PCTargetID]}) /declare PCTargetID local
/varset PCTargetID 0
/varset PCTargetID ${Target.ID}
/newif (!${String[@SpellName].Length}) {
/echo ERROR: Attempted to cast an undefined spell! ("@SpellName")
/return CAST_NOSPELLGIVEN
}
/newif (!${Defined[CastGiveUpTime]}) /declare CastGiveUpTime timer
/newif (!${Defined[Item]}) /declare Item local
/newif (${String[@Item].Equal[Item]} || ${String[@Item].Equal[Activate]}) /goto :StartCast
/newif (!${Me.Gem[@SpellName]}) /call MemSpell "@SpellName"

:StartCast
/newif (${Me.CurrentMana}<${Spell[@SpellName].Mana}) /call MedUp
/varset CastGiveUpTime 10s
/echo Casting "@SpellName" on ${Target.NameClean}
| /tell "@Sender" Casting "@SpellName" on ${Target.NameClean}

:CastNow
/newif (!${Me.Mount} && ${Me.State.NotEqual[STAND]}) /stand
/delay 1
/newif (!${Target.ID} && ${Target.ID}!=@PCTargetID && ${Target.ID}!=${Me.ID}) /target id @PCTargetID
/delay 1
/newif (${String[@Item].Equal[Item]}) {
/call ClearReturnValue
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/cast item "@SpellName"
} else /newif (${String[@Item].Equal[Activate]}) {
/call ClearReturnValue
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/alt activate "@SpellName"
} else {
/newif (!${Me.Gem[@SpellName]}) /return CAST_UNKNOWNSPELL
/call ClearReturnValue
/newif (!${Me.SpellReady[@SpellName]}) {
/newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
/delay 0
/goto :CastNow
}
/newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED
/cast "@SpellName"
}

:WaitCast
/newif (${Me.Casting.ID}) {
/delay 0
| This line handles IF and HOW you will face your spell target (while casting).
| 1 = FACE SLOW (NORMAL SPEED) 2 = FACE FAST Any other #, 0, or null = DO NOT FACE
| Default: FACE NORMAL (SLOW).
/call Face 1
/goto :WaitCast
}

/call ClearReturnValue
/delay 1

/doevents Ability
/doevents Collapse
/doevents Distracted
/doevents FDFail
/doevents Fizzle
/doevents Interrupt
/doevents NoLOS
/doevents NotHold
/doevents OnlyAtNight
/doevents OutOfMana
/doevents OutOfRange
/doevents Outdoors
/doevents Recover
/doevents Resisted
/doevents Silenced
/doevents Standing
/doevents WaitON
/doevents TooPowerful
/doevents Unknown
/doevents Success

/newif (${Macro.Return.Equal[CAST_ABILITYNOTREADY]}) /return ${Macro.Return}
/newif (${macro.Return.Equal[CAST_CANCELLED]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_CANNOTSEE]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_FAIL]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_NOSPELLGIVEN]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_OUTDOORS]}) /goto :FixSpell
/newif (${Macro.Return[CAST_OUTOFMANA]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_OUTOFRANGE]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_RESISTED]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_RESTART]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_SILENCED]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_TOOK2LONG]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_TOOPOWERFUL]}) /goto :FixSpell
/newif (${Macro.Return[CAST_UNKNOWNSPELL]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_WAITOFF]}) /goto :StartCast
/newif (${Macro.Return.Equal[FD_FAILED]}) /return ${Macro.Return}
/newif (${Macro.Return.NotEqual[CAST_SUCCESS]} && !${Macro.Return.Length}) /goto :FixSpell

:FixSpell
| /newif (${Defined[OldSpellName]}) {
| /newif (${String[@OldSpellName].NotEqual[@SpellName]} && ${String[@OldSpellName].Length}>0) {
| /memspell 7 "@OldSpellName"
| /delay 5
| /varset @OldSpellName ""
/return ${Macro.Return}
| }
| }
/return CAST_SUCCESS

Sub MemSpell(SpellName)
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/echo Memorizing: "@SpellName"...
| /tell "@Sender" Just a sec...gotta mem "@SpellName"
| Store the current Spell ID before doing anything so we can leave the way we came in.
| /if $defined(OldSpellName)!=TRUE /declare OldSpellName local
| /varset @OldSpellName ""
| /varset "@OldSpellName" "$char(gem,7)"
| Change the # below if you want to put the spell in a different slot.
/memspell 7 "@SpellName"
/delay 5

:MemWait
/newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/delay 0
/newif (${Me.State.Equal[STAND]} && ${Me.Mount}) /return CAST_RESTART
/newif (!${Me.SpellReady[@SpellName]}) /goto :MemWait
/return CAST_RESTART

Sub MedUp
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/echo Medding...
/newif (!${Me.Mount} && ${Me.State.NotEqual[SIT]} /sit on
/delay 1

:MedStart
/newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
/delay 0
/newif (!${Me.Mount} && ${me.State.NotEqual[SIT]}) /return
/newif (${Me.CurrentMana} <= ${Spell[@SpellName].Mana}) /goto :MedStart
/newif (!${Me.Mount} && ${Me.State.NotEqual[STAND]}) /sit off
/return

Sub Face(UseFaceFast)
/declare Angle local
/declare TX local
/declare TY local
/declare TZ local
/declare FZ local
/varset TX ${Target.X}
/varset TY ${Target.Y}
/varset TZ ${Target.Z}
/varset FZ ${Me.Z}

/newif (${Me.FeetWet}) /varadd TZ 5
/newif (${Me.Levitating}) /varadd TZ 2
/varset Angle $abs($asin($calc($abs($calc(@FZ-@TZ))/$sqrt($calc($calc($calc($calc(@TX-$char(x))^2)+$calc($calc(@TY-$char(y))^2))+$calc($calc(@TZ-@FZ)^2))))))

/newif (@UseFaceFast==1) {
/face nolook loc @TY,@TX
} else {
/newif (@UseFaceFast==2) {
/face fast nolook loc @TY,@TX
}
} else {
/return
}
/newif (@TZ<@FZ) {
/look ${Math.Calc[@Angle*-1]}
} else /newif (@TZ>@FZ) {
/look @Angle
} else {
/look 0
}
/return

Sub ClearReturnValue
/return NULL

Sub Event_Ability
| /echo Event_Ability
| /tell "@Sender" I cannot use that ability right now!
/return CAST_ABILITYNOTREADY

Sub Event_Collapse
| /echo Event_Collapse
| /tell "@Sender" My Gate was too unstable and has collapsed!
/return CAST_RESTART

Sub Event_Distracted
| /echo Event_Distracted
| /tell "@Sender" I am too distracted to cast any spells right now!
/return CAST_SUCCESS

Sub Event_FDFail
| /echo FD_FAILED
| /tell "@Sender" They didn't buy it, boss! Feign Death has failed!
/newif (${Me.State.Equal[FEIGN]}) /stand
/return FD_FAILED

Sub Event_Fizzle
| /echo Event_Fizzle
| /tell "@Sender" Damn fizzles! Trying again...
/return CAST_RESTART

Sub Event_Interrupt
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/return CAST_RESTART

Sub Event_NoLOS
| /echo Event_NoLOS
| /tell "@Sender" I cannot see ${Target.CleanName}. Waiting 5 seconds for it to get a little closer before casting again.
/sit on
/delay 5s
/sit off
/return CAST_CANNOTSEE

Sub Event_NotHold
| /echo Event_NotHold
| /tell "@Sender" "@SpellName" did not take hold on ${Target.CleanName}.
/return CAST_SUCCESS

Sub Event_OnlyAtNight
| /echo Event_OnlyAtNight
| /tell "@Sender" It's too bright out! "@SpellName" should be cast at night!
/return CAST_SUCCESS

Sub Event_OutOfMana
| /echo Event_OutOfMana
| /tell "@Sender" Insufficient mana to cast "@SpellName"! Medding for a moment and trying again...
/call MedUp
/return CAST_OUTOFMANA

Sub Event_OutOfRange
| /echo Event_OutOfRange
| /tell "@Sender" ${Target.CleanName} is out of range. Waiting for it to get a little closer before casting again.
/sit on
:WaitRange
/delay 0
/newif (!${Me.Mount} && ${Me.State.NotEqual[SIT]}) /goto :InRange
/newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG
/newif (${Target.Distance}>200) /goto :WaitRange
:InRange
/sit off
/return CAST_OUTOFRANGE

Sub Event_Outdoors
| /echo Event_Outdoors
| /tell "@Sender" Mommy told me only to cast "@SpellName" when I am outside!
/return CAST_OUTDOORS

Sub Event_Recover
| /echo Event_Recover
| /tell "@Sender" Oops! Have't recovered yet...trying again!
/delay 5
/return CAST_RESTART

Sub Event_Resisted
| /echo Event_Resisted
| /tell "@Sender" ${Target.CleanName} resisted my "@SpellName" spell! Trying again...
/delay 1s
/return CAST_RESISTED

Sub Event_Silenced
| /echo Event_Silenced
| /tell "@Sender" Shh! I have been SILENCED!!! Trying again in 3 seconds.
/delay 3s
/return CAST_SILENCED

Sub Event_Standing
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
| /echo Event_Standing
| /tell "@Sender" You mean I have to stand up now? Oh, alright...casting "@SpellName" for you THIS time!
/stand
/return CAST_RESTART

Sub Event_Success
| /echo Event_Success
/return CAST_SUCCESS

Sub Event_TooPowerful
| /echo Event_TooPowerful
| /tell "@Sender" I am ubah! My spellz are too powaful 4 ${Target.CleanName}
/return CAST_TOOPOWERFUL

Sub Event_Unknown
| /echo Event_Unknown
| /tell "@Sender" You want me to cast WHAT!?!? I've never heard of a spell called "@SpellName" before.
/return CAST_UNKNOWNSPELL

Sub Event_WaitON
| /echo Event_Wait
| /tell "@Sender" I am STUNNED or FEARED!!! Trying again once I regain control of myself.
/doevents flush WaitOFF
:LoopWaitOFF
/newif (${Me.State.Equal[DUCK]) /return CAST_CANCELLED
/multiline ; /doevents WaitOFF;/newif (${Macro.Return.Equal[WaitOFF]}) {
/call ClearReturnValue
/return CAST_WAITOFF
}
/goto :LoopWaitOFF

Sub Event_WaitOFF
| /echo Recovered from Stun...
/return CAST_WAITOFF

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

Re: Fix

Post by wassup » Thu Apr 22, 2004 2:54 pm

javelinl wrote:Replacing

|**
[SpellCast]
Version=04.00.00
**|

with

||**
[SpellCast]
Version=04.00.00
**|

will let you find the functions. However, any reference to Me. seems to fail in this and in any macro. Is Me implemented?
I'd be interested in the line numbers if you could post them. I don't think I made any typo's.

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 Apr 22, 2004 2:56 pm

havelinl, could you fix your post using the

Code: Select all

 at the top of the code and 
at the bottom of the code?

Thanks in advance. I want to see what changes you did or what typo's you fixed.

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

Post by frabtik » Thu Apr 22, 2004 6:55 pm

Script works for you now? Could you post a working copy then? Debugging script now but if it works for you I'd rather use that version.

User avatar
Pax
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Dec 19, 2003 11:04 am
Location: Denmark

one fix so far

Post by Pax » Thu Apr 22, 2004 7:32 pm

Code: Select all

  /newif (${Macro.Return.Equal[CAST_ABILITYNOTREADY]}) /return ${Macro.Return}
/newif (${macro.Return.Equal[CAST_CANCELLED]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_CANNOTSEE]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_FAIL]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_NOSPELLGIVEN]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_OUTDOORS]}) /goto :FixSpell
/newif (${Macro.Return[CAST_OUTOFMANA]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_OUTOFRANGE]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_RESISTED]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_RESTART]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_SILENCED]}) /goto :StartCast
/newif (${Macro.Return.Equal[CAST_TOOK2LONG]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_TOOPOWERFUL]}) /goto :FixSpell
/newif (${Macro.Return[CAST_UNKNOWNSPELL]}) /goto :FixSpell
/newif (${Macro.Return.Equal[CAST_WAITOFF]}) /goto :StartCast
/newif (${Macro.Return.Equal[FD_FAILED]}) /return ${Macro.Return}
/newif (${Macro.Return.NotEqual[CAST_SUCCESS]} && !${Macro.Return.Length}) /goto :FixSpell 
should be

Code: Select all

/if (${Macro.Return.Equal[CAST_ABILITYNOTREADY]}) /return ${Macro.Return}
/if (${macro.Return.Equal[CAST_CANCELLED]}) /goto :FixSpell
/if (${Macro.Return.Equal[CAST_CANNOTSEE]}) /goto :StartCast
/if (${Macro.Return.Equal[CAST_FAIL]}) /goto :FixSpell
/if (${Macro.Return.Equal[CAST_NOSPELLGIVEN]}) /goto :FixSpell
/if (${Macro.Return.Equal[CAST_OUTDOORS]}) /goto :FixSpell
/if (${Macro.Return.[CAST_OUTOFMANA]}) /goto :StartCast
/if (${Macro.Return.Equal[CAST_OUTOFRANGE]}) /goto :StartCast
/if (${Macro.Return.Equal[CAST_RESISTED]}) /goto :StartCast
/if (${Macro.Return.Equal[CAST_RESTART]}) /goto :StartCast
/if (${Macro.Return.Equal[CAST_SILENCED]}) /goto :StartCast
/if (${Macro.Return.Equal[CAST_TOOK2LONG]}) /goto :FixSpell
/if (${Macro.Return.Equal[CAST_TOOPOWERFUL]}) /goto :FixSpell
/if (${Macro.Return.[CAST_UNKNOWNSPELL]}) /goto :FixSpell
/if (${Macro.Return.Equal[CAST_WAITOFF]}) /goto :StartCast
/if (${Macro.Return.Equal[FD_FAILED]}) /return ${Macro.Return}
/if (${Macro.Return.NotEqual[CAST_SUCCESS]} && !${Macro.Return.Length}) /goto :FixSpell
and all the /newif's i canged to /if
got it to cast spells but the load spell sequence is bugging me :)

javelinl
a lesser mummy
a lesser mummy
Posts: 70
Joined: Thu Mar 11, 2004 12:40 pm

Here's my complete.

Post by javelinl » Fri Apr 23, 2004 10:14 am

This one is tested to memspells, and recast in the event of a fizzle. It's not tested for stuns, combat etc..

Code: Select all

| 
| Bad Karma's ADVANCED SpellCast.inc 
| 
| This will cast a spell - and more - reliably for you... 
| 
| 
|     |=========================================| 
|     |  USAGE:                                 | 
|     |  ¯¯¯¯¯¯   /call Cast "Spell Name"       | 
|     |     or:                                 | 
|     |           /call Cast "Item Name" Item   | 
|     |     or:                                 | 
|     |           /call Cast "AA#" Activate     | 
|     |=========================================| 
|     |        Reccomended #turbo               | 
|     |=========================================| 
| 
|  It will return the following values: 
|     CAST_ABILITYNOTREADY 
|     CAST_CANCELLED 
|     CAST_CANNOTSEE 
|     CAST_FAIL 
|     CAST_NOSPELLGIVEN 
|     CAST_OUTDOORS 
|     CAST_OUTOFMANA 
|     CAST_OUTOFRANGE 
|     CAST_RESISTED 
|     CAST_SILENCED 
|     CAST_SUCCESS 
|     CAST_TOOK2LONG 
|     CAST_TOOPOWERFUL 
|     CAST_UNKNOWNSPELL 
|     FD_FAILED 
| 
| 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 
| Xxx XX, 2003 - Modified to add automeming of spells. Goofmester1 
| Dec 26, 2003 - fd fail 1 added by m0nk 
| Dec 28, 2003 - Modded for functionality in a variety of macs for multiple classes - Bad Karma 
| Jan 01, 2004 - timeout(5s) added to stop "dead-time" -m0nk 
| Feb 09, 2004 - Further updates to include handle a few more events, 
|                Mount support, Face target (ml2517), Giveup timer (m0nk) 
|                updated MemSpell, and a few minor personalizations. - Bad Karma 
| Feb 17, 2004 - added AA activate capabilities -ml2517 
| Feb 18, 2004 - More tweaks.  Mostly to casting routine to account for several 
|                character states, Spell Memorization, and added a Med sub (also 
|                now checks to see if you have enough mana to cast after memming), 
|                added more #events & corrected others, commented out the spam, 
|                but left it in the script in case you want it or need it for 
|                GenBot or whatever....  Little better organized, too.   - Bad Karma 
| Feb 28, 2004 - Added support to ensure the right (orginial) target is up before casting. - Frabtik 
| Mar 08, 2004 - Now supports /keypress. - Bad Karma 
| Mar 14, 2004 - Logic Changes: sit + med wait + fdfail + oor wait + stun + charm / most sits removed 
|                Changed Returns for Night Spells + Distracted / @CastGiveUpTime where it was missed. / 
|                format changes / face NOT default / /multiline / extra target checks / 
|                ver# change (mm.dd.yyx) / <stuff i forgot.> - (m0nk) 
| Mar 15, 2004 - Fixed some issues with the new Stun code which was preventing it from triggering. 
|                Updated the FACE option.  1=normal, 2=fast, 0 or anything else (including null)= off. 
| Mar 19, 2004 - Bad Karma ~ Again, many thanks to m0nk for the updates/suggestions!  (Made a few bug fixes again to them *grin*) 
|                Added:  FEARed support, CAST_CANCELLED 
|                          To CANCEL a spell, simply DUCK out. 
|                             I put this before /cast, and at the start of MedUp, MemSpell, :LoopWaitOFF, 
|                             and Event_Interrupt (so it wouldn't unintentially trigger that event and force a re-cast)... 
|                             This should cover any last-second cancel attempts.  Let me know if more are needed. 
|                Fixed:  STUN & FEAR bugs, CAST_ABILITYNOTREADY, 
|                Changed:  StunON/OFF to WaitON/OFF to tie it in with FEAR/CHARM/STUN and possible future updates. 
|                          Moved /call FACE to :WaitCast.  Will now face while casting to help speed up the overall casting process. 
|                             NOTE:  DEFAULT changed to 1 (FACE SLOW) 
|                             Removed version from top of file...too many places to update it! 
| Mar 20, 2004 - Bad Karma ~ Will now re-mem any spell that the script had to overwrite while casting. 
| Mar 26, 2004 - frabtik   ~ Added check for cast success based on mana preservation item results being displayed. 
| Apr 21, 2004 - Wassup    ~ Initial conversion to the MQ2Data format. 
| 
| 
|  NOTE:  All /echo commands are for debugging and feedback only.  They can be safely removed. 
|  ¯¯¯¯¯  All /tell commands were left in for bot support (GenBot & BuffBot) - you can safely kill these, also. 
| 
| 
||** 
|[SpellCast] 
|Version=04.00.00 
**|
| 


#event Ability "You can use the ability " 
#event Collapse "Your gate is too unstable, and collapses." 
#event Distracted "You are too distracted to cast a spell now!" 
#event FDFail "You are no longer feigning death" 
#event Fizzle "Your spell fizzles" 
#event Interrupt "Your casting has been interrupted" 
#event Interrupt "Your spell is interrupted." 
#event NoLOS "You cannot see your target." 
#event NotHold "Your spell would not have taken hold on your target." 
#event OnlyAtNight "Spell can only be cast during the night." 
#event OutOfMana "Insufficient Mana to cast this spell!" 
#event OutOfRange "Your target is out of range, get closer!" 
#event Outdoors "You can only cast this spell in the outdoors." 
#event Recover "You haven't recovered yet..." 
#event Recover "Spell recovery time not yet met." 
#event Resisted "Your target resisted the " 
#event Silenced "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 Success " flickers with a pale light." 
#event TooPowerful "Your spell is too powerful for your intended target." 
#event Unknown "You do not seem to have that spell memorized." 
#event WaitON "Your mind is wracked by fear." 
#event WaitON "You cannot cast while stunned" 
#event WaitON "You are stunned" 
#event WaitON "You lose control of yourself!" 
#event WaitOFF "You are unstunned" 
#event WaitOFF "You have control of yourself again." 
#event WaitOFF "You are no longer afraid." 


Sub Cast(SpellName,Item) 
| Can't cast while we're moving, so let's make sure we're not! 
   /multiline ; /keypress forward;/keypress back;/keypress left;/keypress right;/keypress strafe_left;/keypress strafe_right;/delay 2 
| Store the current Target ID before doing anything, just in case we loose our target before we actually cast. 
   /newif (!${Defined[PCTargetID]}) /declare PCTargetID local 
   /varset PCTargetID 0 
   /varset PCTargetID ${Target.ID} 
   /newif (!${String[@SpellName].Length}) { 
      /echo ERROR:  Attempted to cast an undefined spell!  ("@SpellName") 
      /return CAST_NOSPELLGIVEN 
   } 
   /newif (!${Defined[CastGiveUpTime]}) /declare CastGiveUpTime timer 
   /newif (!${Defined[Item]}) /declare Item local 
   /newif (${String[@Item].Equal[Item]} || ${String[@Item].Equal[Activate]}) /goto :StartCast 
   /newif (!${Me.Gem[@SpellName]}) /call MemSpell "@SpellName" 

   :StartCast 
      /newif (${Me.CurrentMana}<${Spell[@SpellName].Mana}) /call MedUp 
      /varset CastGiveUpTime 12s 
      /echo Casting "@SpellName" on ${Target.NameClean} 
|      /tell "@Sender" Casting "@SpellName" on ${Target.NameClean} 

   :CastNow 
      /newif (!${Me.Mount} && ${Me.State.NotEqual[STAND]}) /stand 
      /delay 1 
      /newif (!${Target.ID} && ${Target.ID}!=@PCTargetID && ${Target.ID}!=${Me.ID}) /target id @PCTargetID 
      /delay 1 
      /newif (${String[@Item].Equal[Item]}) { 
         /call ClearReturnValue 
         /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
         /cast item "@SpellName" 
      } else /newif (${String[@Item].Equal[Activate]}) { 
         /call ClearReturnValue 
         /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
         /alt activate "@SpellName" 
      } else { 
         /newif (!${Me.Gem[@SpellName]}) /return CAST_UNKNOWNSPELL 
         /call ClearReturnValue 
         /newif (!${Me.SpellReady[@SpellName]}) { 
            /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG 
            /delay 0 
            /goto :CastNow 
         } 
         /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
         /cast "@SpellName" 
      } 

   :WaitCast 
      /newif (${Me.Casting.ID}) { 
         /delay 0 
| This line handles IF and HOW you will face your spell target (while casting). 
| 1 = FACE SLOW (NORMAL SPEED)     2 = FACE FAST     Any other #, 0, or null = DO NOT FACE 
| Default:  FACE NORMAL (SLOW). 
         /call Face 1 
         /goto :WaitCast 
      } 

   /call ClearReturnValue 
   /delay 1 

   /doevents Ability 
   /doevents Collapse 
   /doevents Distracted 
   /doevents FDFail 
   /doevents Fizzle 
   /doevents Interrupt 
   /doevents NoLOS 
   /doevents NotHold 
   /doevents OnlyAtNight 
   /doevents OutOfMana 
   /doevents OutOfRange 
   /doevents Outdoors 
   /doevents Recover 
   /doevents Resisted 
   /doevents Silenced 
   /doevents Standing 
   /doevents WaitON 
   /doevents TooPowerful 
   /doevents Unknown 
   /doevents Success 

   /newif (${Macro.Return.Equal[CAST_ABILITYNOTREADY]}) /return ${Macro.Return} 
   /newif (${macro.Return.Equal[CAST_CANCELLED]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_CANNOTSEE]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[CAST_FAIL]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_NOSPELLGIVEN]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_OUTDOORS]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_OUTOFMANA]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[CAST_OUTOFRANGE]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[CAST_RESISTED]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[CAST_RESTART]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[CAST_SILENCED]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[CAST_TOOK2LONG]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_TOOPOWERFUL]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_UNKNOWNSPELL]}) /goto :FixSpell 
   /newif (${Macro.Return.Equal[CAST_WAITOFF]}) /goto :StartCast 
   /newif (${Macro.Return.Equal[FD_FAILED]}) /return ${Macro.Return} 
   /newif (${Macro.Return.NotEqual[CAST_SUCCESS]} && !${Macro.Return.Length}) /goto :FixSpell 

   :FixSpell 
|      /newif (${Defined[OldSpellName]}) { 
|         /newif (${String[@OldSpellName].NotEqual[@SpellName]} && ${String[@OldSpellName].Length}>0) { 
|            /memspell 7 "@OldSpellName" 
|            /delay 5 
|            /varset @OldSpellName "" 
            /return ${Macro.Return} 
|         } 
|      } 
/return CAST_SUCCESS 

Sub MemSpell(SpellName) 
   /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
   /echo Memorizing:  "@SpellName"... 
|  /tell "@Sender" Just a sec...gotta mem "@SpellName" 
| Store the current Spell ID before doing anything so we can leave the way we came in. 
|   /if $defined(OldSpellName)!=TRUE /declare OldSpellName local 
|   /varset @OldSpellName "" 
|   /varset "@OldSpellName" "$char(gem,7)" 
| Change the # below if you want to put the spell in a different slot. 
   /memspell 7 "@SpellName" 
   /delay 5 

:MemWait 
   |/newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG 
   /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
   /delay 0 
   /newif (${Me.State.Equal[STAND]} && ${Me.Mount}) /return CAST_RESTART 
   /newif (!${Me.SpellReady[@SpellName]}) /goto :MemWait 
/return CAST_RESTART 

Sub MedUp 
   /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
   /echo Medding... 
   /newif (!${Me.Mount} && ${Me.State.NotEqual[SIT]} /sit on 
   /delay 1 

:MedStart 
   /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG 
   /delay 0 
   /newif (!${Me.Mount} && ${me.State.NotEqual[SIT]}) /return 
   /newif (${Me.CurrentMana} <= ${Spell[@SpellName].Mana}) /goto :MedStart 
   /newif (!${Me.Mount} && ${Me.State.NotEqual[STAND]}) /sit off 
/return 

Sub Face(UseFaceFast) 
   /declare Angle local 
   /declare TX local 
   /declare TY local 
   /declare TZ local 
   /declare FZ local 
   /varset TX ${Target.X} 
   /varset TY ${Target.Y} 
   /varset TZ ${Target.Z} 
   /varset FZ ${Me.Z} 

   /newif (${Me.FeetWet}) /varadd TZ 5 
   /newif (${Me.Levitating}) /varadd TZ 2 
   /varset Angle $abs($asin($calc($abs($calc(@FZ-@TZ))/$sqrt($calc($calc($calc($calc(@TX-$char(x))^2)+$calc($calc(@TY-$char(y))^2))+$calc($calc(@TZ-@FZ)^2)))))) 

   /newif (@UseFaceFast==1) { 
      /face nolook loc @TY,@TX 
   } else { 
      /newif (@UseFaceFast==2) { 
         /face fast nolook loc @TY,@TX 
      } 
   } else { 
      /return 
   } 
   /newif (@TZ<@FZ) { 
      /look ${Math.Calc[@Angle*-1]} 
   } else /newif (@TZ>@FZ) { 
      /look @Angle 
   } else { 
      /look 0 
   } 
/return 

Sub ClearReturnValue 
/return NULL 

Sub Event_Ability 
|   /echo Event_Ability 
|   /tell "@Sender" I cannot use that ability right now! 
/return CAST_ABILITYNOTREADY 

Sub Event_Collapse 
|   /echo Event_Collapse 
|   /tell "@Sender" My Gate was too unstable and has collapsed! 
/return CAST_RESTART 

Sub Event_Distracted 
|   /echo Event_Distracted 
|   /tell "@Sender" I am too distracted to cast any spells right now! 
/return CAST_SUCCESS 

Sub Event_FDFail 
|   /echo FD_FAILED 
|   /tell "@Sender" They didn't buy it, boss!  Feign Death has failed! 
    /newif (${Me.State.Equal[FEIGN]}) /stand 
/return FD_FAILED 

Sub Event_Fizzle 
|   /echo Event_Fizzle 
|   /tell "@Sender" Damn fizzles!  Trying again... 
/return CAST_RESTART 

Sub Event_Interrupt 
   /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
/return CAST_RESTART 

Sub Event_NoLOS 
|   /echo Event_NoLOS 
|   /tell "@Sender" I cannot see ${Target.CleanName}.  Waiting 5 seconds for it to get a little closer before casting again. 
    /sit on 
    /delay 5s 
    /sit off 
/return CAST_CANNOTSEE 

Sub Event_NotHold 
|   /echo Event_NotHold 
|   /tell "@Sender" "@SpellName" did not take hold on ${Target.CleanName}. 
/return CAST_SUCCESS 

Sub Event_OnlyAtNight 
|   /echo Event_OnlyAtNight 
|   /tell "@Sender" It's too bright out!  "@SpellName" should be cast at night! 
/return CAST_SUCCESS 

Sub Event_OutOfMana 
|   /echo Event_OutOfMana 
|   /tell "@Sender" Insufficient mana to cast "@SpellName"!  Medding for a moment and trying again... 
   /call MedUp 
/return CAST_OUTOFMANA 

Sub Event_OutOfRange 
|   /echo Event_OutOfRange 
|   /tell "@Sender" ${Target.CleanName} is out of range.  Waiting for it to get a little closer before casting again. 
   /sit on 
:WaitRange 
      /delay 0 
      /newif (!${Me.Mount} && ${Me.State.NotEqual[SIT]}) /goto :InRange 
      /newif (@CastGiveUpTime==0) /return CAST_TOOK2LONG 
      /newif (${Target.Distance}>200) /goto :WaitRange 
:InRange 
   /sit off 
/return CAST_OUTOFRANGE 

Sub Event_Outdoors 
|   /echo Event_Outdoors 
|   /tell "@Sender" Mommy told me only to cast "@SpellName" when I am outside! 
/return CAST_OUTDOORS 

Sub Event_Recover 
|   /echo Event_Recover 
|   /tell "@Sender" Oops!  Have't recovered yet...trying again! 
   /delay 5 
/return CAST_RESTART 

Sub Event_Resisted 
|   /echo Event_Resisted 
|   /tell "@Sender" ${Target.CleanName} resisted my "@SpellName" spell!  Trying again... 
   /delay 1s 
/return CAST_RESISTED 

Sub Event_Silenced 
|   /echo Event_Silenced 
|   /tell "@Sender" Shh!  I have been SILENCED!!!  Trying again in 3 seconds. 
   /delay 3s 
/return CAST_SILENCED 

Sub Event_Standing 
   /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
|   /echo Event_Standing 
|   /tell "@Sender" You mean I have to stand up now?  Oh, alright...casting "@SpellName" for you THIS time! 
   /stand 
/return CAST_RESTART 

Sub Event_Success 
|  /echo Event_Success 
/return CAST_SUCCESS 

Sub Event_TooPowerful 
|   /echo Event_TooPowerful 
|   /tell "@Sender" I am ubah!  My spellz are too powaful 4 ${Target.CleanName} 
/return CAST_TOOPOWERFUL 

Sub Event_Unknown 
|   /echo Event_Unknown 
|   /tell "@Sender" You want me to cast WHAT!?!?  I've never heard of a spell called "@SpellName" before. 
/return CAST_UNKNOWNSPELL 

Sub Event_WaitON 
|   /echo Event_Wait 
|   /tell "@Sender" I am STUNNED or FEARED!!!  Trying again once I regain control of myself. 
   /doevents flush WaitOFF 
:LoopWaitOFF 
   /newif (${Me.State.Equal[DUCK]}) /return CAST_CANCELLED 
   /multiline ; /doevents WaitOFF;/newif (${Macro.Return.Equal[WaitOFF]}) { 
      /call ClearReturnValue 
      /return CAST_WAITOFF 
   } 
   /goto :LoopWaitOFF 

Sub Event_WaitOFF 
|   /echo Recovered from Stun... 
/return CAST_WAITOFF