Mem Spell if not already loaded.

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

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 » Tue Dec 30, 2003 7:17 am

No idea why that didn't work. It should work fine.

Would help if you posted the macro using this SpellCast.inc so we could see where or what is causing the problem.

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 » Tue Dec 30, 2003 7:56 pm

This is a cross-post from a PM I just sent to Goofmester1. This thread has gotten pretty choppy, so this should put everything in one place:

Thanks for all you're help. Even though this isn't working, I'm still learning a lot about the way this should be done. First, the SpellCast.inc. There's some extra stuff in the one I'm trying to get working. Anything that is |commented out can be deleted...it's just for troubleshooting and testing right now. I tried the one you posted, also, and even that does not work, so I'm pretty sure this one should work. Try it out yourself and see what happens. The code is pretty much the same, just expanded a little in how it will handle results. The end macro will be similar to GenBot, but more specific to the classes I play.

Code: Select all

| SpellCast.inc
| This will cast a spell reliably for you...
|
| Usage:
|      /call Cast "spellname"
|   or
|      /call Cast "itemname" [item]
|
| It will return the following values:
|    CAST_SUCCESS
|    CAST_UNKNOWNSPELL
|    CAST_OUTOFMANA
|    CAST_OUTOFRANGE
|    CAST_CANNOTSEE
|    CAST_STUNNED
|    CAST_RESISTED
|    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
|  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
|
|  NOTE:  All /echo commands are for debugging and feedback only.  They can be safely removed.
|

#event Collapse "Your gate is too unstable, and collapses."
#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 Recover "You haven't recovered yet..."
#event Recover "Spell recovery time not yet met."
#event Resisted "You target resisted the "
#event Standing "You must be standing to cast a spell"
#event Standing "has fallen to the ground."
#event Stunned "You cannot cast while stunned"
#event TooPowerful "You spell is too powerful for your intended target."

Sub Cast(SpellName,Item)
|   /sendkey up up
|   /sendkey up down
/if n $char(gem,"@SpellName")==0 {
  /memspell 8 "@SpellName"
  /delay 5s
}
:StartCast
|   /if $char(state)!="STAND" /stand
|   /face
|   /look 0      Temporary fix to the "stare at the sky" issue.
|   /delay 2s
|   /echo Incoming @SpellName to %T
   /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 
      }
   /doevents Fizzle
   /doevents Interrupt
   /doevents Recover
   /doevents Resisted
   /doevents OutOfMana
   /doevents OutOfRange
   /doevents NoLOS
   /doevents Stunned
   /doevents Standing
   /doevents Collapse
   /doevents OnlyAtNight
   /doevents NotHold
   /doevents TooPowerful
   /doevents FDFail

   /if "$return"=="CAST_RESTART" /goto :StartCast
   /if "$return"!="CAST_SUCCESS" /return "$return"
   /if "$return"=="CAST_OUTOFMANA" /goto :StartCast
   /if "$return"=="CAST_STUNNED" /goto :StartCast
   /if "$return"=="CAST_RESISTED" /goto :StartCast
   /if "$return"=="CAST_OUTOFRANGE" /goto :StartCast
   /if "$return"=="CAST_CANNOTSEE" /goto :StartCast
   /if "$return"=="FD_FAILED" /return "$return"
/return CAST_SUCCESS

Sub ClearReturnValue 
/return CAST_SUCCESS 


Sub Event_Fizzle
   /echo Event_Fizzle
/return CAST_RESTART

Sub Event_Interrupt
   /echo Event_Interrupt
/return CAST_RESTART

Sub Event_Recover
   /echo Waiting for recovery...
   /delay 5
/return CAST_RESTART

Sub Event_Standing
   /echo Event_Standing
   /stand
/return CAST_RESTART

Sub Event_Collapse
   /echo Event_Collapse
/return CAST_RESTART

Sub Event_OutOfMana
   /echo Event_OutOfMana
   /tell "@Sender" "I'm out of mana at the moment.  Let me med for 10 seconds and I'll try again!"
   /sit
   /delay 10s
   /stand
/return CAST_OUTOFMANA

Sub Event_OutOfRange
   /echo Event_OutOfRange
   /tell "@Sender" "%T is out of range.  Waiting for it to get a little closer before casting again."
   /sit
   /delay 10s
   /stand
/return CAST_OUTOFRANGE

Sub Event_NoLOS
   /echo Event_NoLOS
   /tell "@Sender" "I cannot see %T.  Waiting for it to get a little closer before casting again."
   /sit
   /delay 10s
   /stand
/return CAST_CANNOTSEE

Sub Event_Stunned
   /echo Event_Stunned
   /tell "@Sender" "I am STUNNED at the moment!  I will try again in 5 seconds."
   /sit
   /delay 5s
   /stand
/return CAST_STUNNED

Sub Event_Resisted
   /echo Event_Resisted
   /tell "@Sender" "%T resisted my spell.  Trying again..."
   /sit
   /delay 5s
   /stand
/return CAST_RESISTED

Sub Event_OnlyAtNight
   /echo Event_OnlyAtNight
/return CAST_SUCCESS

Sub Event_NotHold
   /echo Event_NotHold
/return CAST_SUCCESS

Sub Event_TooPowerful
   /echo Event_TooPowerful
/return CAST_SUCCESS

Sub Event_FDFail
   /echo FD_FAILED
   /stand
/return FD_FAILED
As for the macro itself, it's still a loooong way from being ready. For space, I'll post the copy of Canni.mac that I'm using, since that is what I'm using to test the SpellCast.inc. It's short, simple, and generally works. Plus, I use it ALL the time while grouping to keep up on mana.

Code: Select all

| Canni.mac 
| Autocanni and heal for a 65 with Q and C4 
| Usage: /macro canni.mac 
|   Parameters... 
|   help   - Display this information 
|   noheal - Canni and dont stop. Good for slow groups with a cleric healing you. 
|   nostop - Do not end the canni loop when you are done. It will continue to 
|            loop and canni as necissary to keep you up on mana. 
|   nosit  - Perform basic, but do not sit between casts. 
|   Note: Noheal will still heal if you hit 35%, there is some sanity to it. 
| 
| Brought to you by MoonRaverX 


| Used for all my spell macros. 
#include SpellCast.inc 

   /declare Canni_nosit  global 
   /declare Canni_noheal global 
   /declare Canni_nostop global 
   /declare SpellName global
   /declare Item global

   /varset Canni_nosit 0 
   /varset Canni_noheal 0 
   /varset Canni_nostop 0

|Main Loop 
Sub Main 
|  Lets check out paramters. 
   /if "@Param0"=="help"   /call Canni_Syntax 

   /if "@Param0 @Param1 @Param2"~~"nosit" /varset Canni_nosit 1 
   /if "@Param0 @Param1 @Param2"~~"noheal" /varset Canni_noheal 1 
   /if "@Param0 @Param1 @Param2"~~"nostop" /varset Canni_nostop 1 
    
:loopstart 
|  If your hp are less than 35% start a heal first. 
   /if n $char(hp,pct)<35 /call Canni_CastHeal 

|  If your mana is more than 5%, and hp are between 25 and 50%, heal. 
   /if (n $char(mana,pct)>5 && n $char(hp,pct)>25 && n $char(hp,pct)<50) /call Canni_CastHeal 

|  If hp are more than 40% and mana is under 90%, canni. 
   /if (n $char(hp,pct)>40 && n $char(mana,pct)<90) /call Canni_CastCanni 

|  If your done canni'ing stop the macro. 
   /if (n $char(mana,pct)>90 && Canni_nostop==0) /call Canni_AllDone 

   /doevents 
   /delay 1 
   /goto :loopstart 

/return 


Sub Canni_CastCanni 
   :tryagain 
   /delay 1 
   /if n $char(gem,"Cannibalize III")<1 /goto :tryagain 
   /sit off

|   /varset "@SpellName"="Cannibalize III"		FOR TESTING
   /call Cast "Cannibalize III"
   /if $return==CAST_RESTART /call CastCanni
   /if $return==CAST_OUTOFMANA /call ErrorTrap
   /if $return==CAST_OUTOFRANGE /call ErrorTrap
   /if $return==CAST_CANNOTSEE /call ErrorTrap
   /if $return==CAST_STUNNED /call ErrorTrap
   /if $return==CAST_RESISTED /call ErrorTrap
   /if Canni_nosit==0 /sit on
   /delay 1
/call Main

Sub Canni_CastHeal 
|  Noheal catch, with stupidity checking 
   /if (Canni_noheal==1 && n $char(hp,pct)>35) /call Canni_CastCanni 
    
   :tryagain 
   /delay 1 
   /if n $char(gem,"Superior Healing")<1 /goto :tryagain
   /sit off 
   /target myself 

|   /varset "@SpellName"="Superior Healing"		FOR TESTING
   /call Cast "Superior Healing"
   /if $return==CAST_RESTART /call CastHeal
   /if $return==CAST_OUTOFMANA /call ErrorTrap
   /if $return==CAST_OUTOFRANGE /call ErrorTrap
   /if $return==CAST_CANNOTSEE /call ErrorTrap
   /if $return==CAST_STUNNED /call ErrorTrap
   /if $return==CAST_RESISTED /call ErrorTrap
   /delay 1
   /if Canni_nosit==0 /sit on
   /delay 90
/call Main

Sub Canni_Syntax 
   /echo Canni..Syntax (Brought to you by MoonRaverX) 
   /echo help   - Display this information 
   /echo noheal - Canni and dont stop. Good for slow groups with a cleric healing you. 
   /echo nostop - Do not end the canni loop when you are done. It will continue to 
   /echo .        loop and canni as necissary to keep you up on mana. 
   /echo nosit  - Perform basic, but do not sit between casts. 
   /echo Note: Noheal will still heal if you hit 35%, there is some sanity to it. 
   /endmacro 
/call Main 

Sub Canni_ErrorTrap 
   /echo Something went wrong with the macro. Killing now. 
   /endmacro 
/call Main 

Sub Canni_AllDone 
   /delay 1 
   /sit off 
   /echo Cannidance done. 
   /endmacro 
/return
What happens is, it just sits there, making stuipd faces at me if either of the 2 spells it wants to cast are not loaded. If I manually mem the spell, it picks right up and casts away. If I type /memspell 1 "Superior Healing" in the chat window, the spell loads into slot 1 and the macro resumes. (that works for any spell, just using this as an example.) So, I'm 99% sure the /call and SpellCast.inc is functioning properly. Just, for some reason, it won't work when the /call is made from the Macro. I've tried it with other macros, and the same symptoms happen with them.

Finally, and not really a huge issue at this point, if I try to pass an Item to SpellCast.inc, it just says something like "no such spell" and barfs out. This happens when called from a macro, or passed via the chat window. (Tested with "Black Fur Boots" for the SOW effect.) I just tested this for shits and grins - it's not really needed for me (yet), but once the macro I'm working on is ready for release, I will need it. It's a backburner issue for now.

Again, thanks for all your help! I can cross-post this to the thread if you think it's a good idea. This pretty much sums up everything I've tried in one message, with actual full code I'm working with. Oh, and I have recompiled. There is a net .zip out today, which just finished downloading. Will let you know if that fixes this. It's possible I missed something somewhere, but I searched every thread I have access to on the site, and could not find anything. I read every thread every day to learn as much as I can about all this. I don't like asking for help unless I've exhausted every resource I can come up with. ;)

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

Post by LamahHerder » Wed Dec 31, 2003 8:14 am

try this for a test
first with the spell mem'd in any slot
then with the spell unmem'd

copy and paste, do not edit anything.

t.mac

Code: Select all

#include spellcastTEST.inc

sub main
 /call cast "Cannibalize III"
 /echo Canni was Cast
 /target myself
 /delay 1s
 /call cast "Black Fur Boots" item
 /echo Black Fur Boots item was cast
/end
spellcastTEST.inc

Code: Select all

| SpellCast.inc
| This will cast a spell reliably for you...
| Usage:
| /call Cast "spellname"
| or
| /call Cast "itemname" [item]
| 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)
	/echo Cast @SpellName
	/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
let us know the results.

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 Dec 31, 2003 10:11 am

I think adding a Sub specifically for casting using right click item's might be a good idea.

Combining Casting and right clicking in one sub sounds great, but seems to be causing you a problem.

Code: Select all

Sub UseItem
   /echo UseItem @Param0 
   /sendkey up up 
   /sendkey up down 
   /delay 5 
   :StartCast 
   /cast item "@Param0" 
   :WaitCast 
   /if "$char(casting)"=="TRUE" { 
      /delay 1 
      /goto :WaitCast 
   } 
   /delay 1 
   /doevents Interrupt 
   /doevents Recover 
   /doevents Standing 
   /doevents OutOfRange 
   /doevents NoLOS 
   /doevents Resisted 
   /if "$return"=="CAST_RESTART" /goto :StartCast 
   /if "$return"!="CAST_SUCCESS" /return "$return" 
/return CAST_SUCCESS
Also, not sure what the reason is for having two events with the same name, but different text triggers. Was this intentional or just an oversight?

Code: Select all

#event Fizzle "Your spell fizzles"
[color=cyan] 
#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."
[/color]
#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"
[color=cyan]
#event Standing "You must be standing to cast a spell" 
#event Standing "has fallen to the ground."
[/color]
#event Collapse "Your gate is too unstable, and collapses."

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Post by EqMule » Wed Dec 31, 2003 4:24 pm

Wassup wrote:Combining Casting and right clicking in one sub sounds great, but seems to be causing you a problem.
Ehmm... FYI "casting" an item effect is not done by rightclicking... actually Im using the same function "Cast" as casting a spell uses... just that it needs other parameters... dont know if that makes sence... but triggering a effect on an item does not involve a click at all...

so I could change your quote and it would read
Combining Casting and Casting in one sub sounds great, but seems to be causing you a problem
and that... doesnt make sense...
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

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 » Wed Dec 31, 2003 6:10 pm

Ok...here's what I come up with...

First, the reason there are multiple events with the same name:

Code: Select all

[color=cyan]#event Standing "You must be standing to cast a spell"
#event Standing "has fallen to the ground." [/color]
The purpose of this is to cut down on code. Both triggers would have the same result, and require the same follow-up actions. Why I have it coded like this is simply because that is the way it was in the SpellCast.inc that I took from these forums, and the many other versions I've been provided by other people.

Which leads me to the results of the t.mac:

This works. lol I tried it with spell mem'd and unmem'd. It does exactly what it should. Item works, too. Compairing the code to what's in Canni.mac and the only difference to the /call is that cast is all lowercase in yours, and is spelled with a capital C in canni.mac. I changed this, and it still didn't work. So now I'm 99% certain that canni.mac is broken. There is a new version posted just today, so I will be trying that one out.

The question remains, however, why don't other macros using spellcast.inc work? Everything looks good in the code.

I've tried some other mac's that mem the spell and cast without spellcast.inc. They work. I'll have to do some more research and testing on this to get a better grasp of what's happening/not happening before I waste more of anyone else's time on this.

One last question, though...aside from using /echo messages to inform me of what's happening, is there any way to trace what the macro is doing? Any way to display what line of a macro is currently being executed? It'd be nice to see exactly where the thing is getting stuck.

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 Dec 31, 2003 8:11 pm

EqMule wrote:
Wassup wrote:Combining Casting and right clicking in one sub sounds great, but seems to be causing you a problem.
Ehmm... FYI "casting" an item effect is not done by rightclicking... actually Im using the same function "Cast" as casting a spell uses... just that it needs other parameters... dont know if that makes sence... but triggering a effect on an item does not involve a click at all...

so I could change your quote and it would read
Combining Casting and Casting in one sub sounds great, but seems to be causing you a problem
and that... doesnt make sense...
I know EQMule, I just meant for the purpose of casting using a right click item. I just meant that as a reference to right click items.

Anyway, I might try to help and make a Sub that might work a bit better or in this case... work.

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 » Thu Jan 01, 2004 11:21 am

Been playing around with Cannibalize-Inc.mac and that works like a charm. I'm going to go over all my macros and make sure all /calls to SpellCast.inc follow the exact syntax of this macro. Canni.mac posted above does, but for some reason, it does not want to mem spells, just cast them. I'm abandonint it completely, though, as it's a mess to start with...took sevearal modifications to get it to do that much. If I can get GenBot to work properly, then I'll be good to go on the mac I'm writing. For now, however, my attention has turned to more mundane items in that macro until I get this figured out.

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 Jan 01, 2004 6:37 pm

Bad Karma wrote: One last question, though...aside from using /echo messages to inform me of what's happening, is there any way to trace what the macro is doing? Any way to display what line of a macro is currently being executed? It'd be nice to see exactly where the thing is getting stuck.
You would have to add /echo's or /mqlog <text> in the code to track it. That is the only way I know of to find out while the macro is running.

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 » Thu Jan 01, 2004 9:26 pm

eww...I was afraid someone was going to say that.
I've been using /echo <line #> <copy of next line of code to execute> for testing... That way I can jump right to that line in OE and fix it...or see on the screen what is about to happen/expect.

Does nothing for my filesizes while working on things, let alone my fingers with all the extra work...and cleaning it all up after? lol

fryfrog
a hill giant
a hill giant
Posts: 271
Joined: Fri Jun 20, 2003 5:37 am

Post by fryfrog » Thu Jan 01, 2004 10:50 pm

I always do something like define a "Debug" variable and just leave testing code in. A simple "/if n @Debug==1 /echo Trying to do this" and setting Debug to 1 (or 0) somewhere and you have debug info that is easy to turn on and off, for anyone.