HasteCheck + ClarityCheck + DSCheck + ...

Joined
Jun 7, 2007
Messages
816
Reaction score
3
Points
18
In an effort to share with the community, here are some essential subs i wrote to help in my macros ...... enjoy .. feedback and not flames welcome.

These subs are used to determine the best haste / clarity / DS / heal potion you can use based on your level and what you have in inventory... and uses it.

It assumes you are using spell_routines.inc or mq2cast for the "/call cast" lines.

There are global declares that need to be made like "doCrackCheck" / "doDSCheck" .. etc.. that i use to call the subs within my macros... but this can easily be edited to remove that, however i suggest keeping these varset lines and declaring their variables globaly so you don't keep calling the subs if you don't have any potions on you.

example:

/declare doCrackCheck bool outer TRUE

/if (doCrackCheck) /call SelfClarityCheck

If you don't have any clerity potions at all on you, the varset line in the SelfClarityCheck sub will turn off any further checking for clarity potions.

Code:
|--------------------------------------------------------------------------------
|SUB: UseHealPotion
|-------------------------------------------------------------------------------- 
Sub UseHealPotion 

/declare MyBestHealPotion   string local
/declare LevelMark          string local

/if (${Me.Level}>=1  && (${FindItem[Distillate of Divine Healing I].ID}))  /varset LevelMark I
/if (${Me.Level}>=5  && (${FindItem[Distillate of Divine Healing II].ID}))  /varset LevelMark II
/if (${Me.Level}>=10 && (${FindItem[Distillate of Divine Healing III].ID})) /varset LevelMark III
/if (${Me.Level}>=20 && (${FindItem[Distillate of Divine Healing IV].ID})) /varset LevelMark IV
/if (${Me.Level}>=30 && (${FindItem[Distillate of Divine Healing V].ID})) /varset LevelMark V
/if (${Me.Level}>=40 && (${FindItem[Distillate of Divine Healing VI].ID})) /varset LevelMark VI
/if (${Me.Level}>=50 && (${FindItem[Distillate of Divine Healing VII].ID})) /varset LevelMark VII
/if (${Me.Level}>=55 && (${FindItem[Distillate of Divine Healing VII].ID})) /varset LevelMark VIII
/if (${Me.Level}>=60 && (${FindItem[Distillate of Divine Healing IX].ID})) /varset LevelMark IX
/if (${Me.Level}>=65 && (${FindItem[Distillate of Divine Healing X].ID})) /varset LevelMark X
/if (${Me.Level}>=70 && (${FindItem[Distillate of Divine Healing XI].ID})) /varset LevelMark XI
/if (${Me.Level}>=75 && (${FindItem[Distillate of Divine Healing XII].ID})) /varset LevelMark XII
/if (${Me.Level}>=80 && (${FindItem[Distillate of Divine Healing XIII].ID})) /varset LevelMark XIII
/if (${Me.Level}>=85 && (${FindItem[Distillate of Divine Healing XIV].ID})) /varset LevelMark XIV

/varset MyBestHealPotion "Distillate of Divine Healing ${LevelMark}"
         
    /echo Checking for self healing potions.

    /if (${FindItem[${MyBestHealPotion}].ID})   {
        /echo Using potion: ${MyBestHealPotion}
        /call cast ${MyBestHealPotion} item
        /if (${Cursor.ID}) /autoinventory
    } else {
        /echo I do not have any heal potions !	 	    
    }         	      

/doevents
    
/return 
|--------------------------------------------------------------------------------

Code:
|--------------------------------------------------------------------------------
|SUB: UseHoTPotion
|-------------------------------------------------------------------------------- 
Sub UseHoTPotion 

/declare MyBestHoTPotion   string local
/declare LevelMark          string local

/if (${Me.Level}>=1  && (${FindItem[Distillate of Celestial Healing I].ID}))  /varset LevelMark I
/if (${Me.Level}>=5  && (${FindItem[Distillate of Celestial Healing II].ID}))  /varset LevelMark II
/if (${Me.Level}>=10 && (${FindItem[Distillate of Celestial Healing III].ID})) /varset LevelMark III
/if (${Me.Level}>=20 && (${FindItem[Distillate of Celestial Healing IV].ID})) /varset LevelMark IV
/if (${Me.Level}>=30 && (${FindItem[Distillate of Celestial Healing V].ID})) /varset LevelMark V
/if (${Me.Level}>=40 && (${FindItem[Distillate of Celestial Healing VI].ID})) /varset LevelMark VI
/if (${Me.Level}>=50 && (${FindItem[Distillate of Celestial Healing VII].ID})) /varset LevelMark VII
/if (${Me.Level}>=55 && (${FindItem[Distillate of Celestial Healing VII].ID})) /varset LevelMark VIII
/if (${Me.Level}>=60 && (${FindItem[Distillate of Celestial Healing IX].ID})) /varset LevelMark IX
/if (${Me.Level}>=65 && (${FindItem[Distillate of Celestial Healing X].ID})) /varset LevelMark X
/if (${Me.Level}>=70 && (${FindItem[Distillate of Celestial Healing XI].ID})) /varset LevelMark XI
/if (${Me.Level}>=75 && (${FindItem[Distillate of Celestial Healing XII].ID})) /varset LevelMark XII
/if (${Me.Level}>=80 && (${FindItem[Distillate of Celestial Healing XIII].ID})) /varset LevelMark XIII
/if (${Me.Level}>=85 && (${FindItem[Distillate of Celestial Healing XIV].ID})) /varset LevelMark XIV

/varset MyBestHoTPotion "Distillate of Celestial Healing ${LevelMark}"
         
    /echo Checking for self healing potions.

    /if (${FindItem[${MyBestHoTPotion}].ID})   {
        /echo Using potion: ${MyBestHoTPotion}
        /call cast ${MyBestHoTPotion} item
        /if (${Cursor.ID}) /autoinventory
    } else {
        /echo I do not have any HoT potions !	    
    }         	      

/doevents
    
/return 
|--------------------------------------------------------------------------------

Code:
|--------------------------------------------------------------------------------
|SUB: SelfClarityCheck
|-------------------------------------------------------------------------------- 
Sub SelfClarityCheck 

/declare MyBestClarityPotion  string local
/declare LevelMark            string local

/if (${Me.Level}>=1  && (${FindItem[Distillate of Clarity I].ID}))  /varset LevelMark I
/if (${Me.Level}>=5  && (${FindItem[Distillate of Clarity II].ID}))  /varset LevelMark II
/if (${Me.Level}>=10 && (${FindItem[Distillate of Clarity III].ID})) /varset LevelMark III
/if (${Me.Level}>=20 && (${FindItem[Distillate of Clarity IV].ID})) /varset LevelMark IV
/if (${Me.Level}>=30 && (${FindItem[Distillate of Clarity V].ID})) /varset LevelMark V
/if (${Me.Level}>=40 && (${FindItem[Distillate of Clarity VI].ID})) /varset LevelMark VI
/if (${Me.Level}>=50 && (${FindItem[Distillate of Clarity VII].ID})) /varset LevelMark VII
/if (${Me.Level}>=55 && (${FindItem[Distillate of Clarity VII].ID})) /varset LevelMark VIII
/if (${Me.Level}>=60 && (${FindItem[Distillate of Clarity IX].ID})) /varset LevelMark IX
/if (${Me.Level}>=65 && (${FindItem[Distillate of Clarity X].ID})) /varset LevelMark X
/if (${Me.Level}>=70 && (${FindItem[Distillate of Clarity XI].ID})) /varset LevelMark XI
/if (${Me.Level}>=75 && (${FindItem[Distillate of Clarity XII].ID})) /varset LevelMark XII
/if (${Me.Level}>=80 && (${FindItem[Distillate of Clarity XIII].ID})) /varset LevelMark XIII
/if (${Me.Level}>=85 && (${FindItem[Distillate of Clarity XIV].ID})) /varset LevelMark XIV

/varset MyBestClarityPotion "Distillate of Clarity ${LevelMark}"

/if (!${Me.Buff[Chaotica].ID} && !${Me.Buff[Koadic's Endless Intellect].ID} && !${Me.Buff[Tranquility].ID} && !${Me.Buff[Voice of Quellious].ID} && !${Me.Buff[Aura of Quellious].ID} && !${Me.Buff[Clairvoyance].ID} && !${Me.Buff[Voice of Clairvoyance].ID} && !${Me.Buff[Seer's Intuition].ID} && !${Me.Buff[Seer's Intuition Rk. II].ID} && !${Me.Buff[Seer's Intuition Rk. III].ID} && !${Me.Buff[Voice of Intuition].ID} && !${Me.Buff[Voice of Intuition Rk. II].ID} && !${Me.Buff[Voice of Intuition Rk. III].ID} && !${Me.Buff[Seer's Cognizance].ID} && !${Me.Buff[Seer's Cognizance Rk. II].ID} && !${Me.Buff[Seer's Cognizance Rk. III].ID} && !${Me.Buff[Voice of Cognizance].ID} && !${Me.Buff[Voice of Cognizance Rk. II].ID} && !${Me.Buff[Voice of Cognizance Rk. III].ID} && !${Me.Buff[Prescience].ID} && !${Me.Buff[Prescience Rk. II].ID} && !${Me.Buff[Prescience Rk. III].ID} && !${Me.Buff[Voice of Prescience].ID} && !${Me.Buff[Voice of Prescience Rk. II].ID} && !${Me.Buff[Voice of Prescience Rk. III].ID})  {      

     /if (!${Me.Buff[Elixir of Clarity ${LevelMark}].ID}) {
     	 /echo I am without mind candy !         
         /echo Checking for self clarity potions.
         
	 /if (${FindItem[${MyBestClarityPotion}].ID}) {
	     /echo Using potion: (${MyBestClarityPotion})
	     /call cast ${MyBestClarityPotion} item
	     /if (${Cursor.ID}) /autoinventory
	 } else {
	    /echo I do not have any clarity potions !	 
	    /varset doCrackCheck FALSE	    
	 }         	 
     } 	     
}
   
/doevents
    
/return 
|--------------------------------------------------------------------------------

Code:
|-------------------------------------------------------------------------------- 
|SUB: SelfDSCheck
|--------------------------------------------------------------------------------
Sub SelfDSCheck

/declare MyBestDSPotion     string local
/declare LevelMark          string local

/if (${Me.Level}>=1  && (${FindItem[Distillate of Skinspikes I].ID}))  /varset LevelMark I
/if (${Me.Level}>=5  && (${FindItem[Distillate of Skinspikes II].ID}))  /varset LevelMark II
/if (${Me.Level}>=10 && (${FindItem[Distillate of Skinspikes III].ID})) /varset LevelMark III
/if (${Me.Level}>=20 && (${FindItem[Distillate of Skinspikes IV].ID})) /varset LevelMark IV
/if (${Me.Level}>=30 && (${FindItem[Distillate of Skinspikes V].ID})) /varset LevelMark V
/if (${Me.Level}>=40 && (${FindItem[Distillate of Skinspikes VI].ID})) /varset LevelMark VI
/if (${Me.Level}>=50 && (${FindItem[Distillate of Skinspikes VII].ID})) /varset LevelMark VII
/if (${Me.Level}>=55 && (${FindItem[Distillate of Skinspikes VII].ID})) /varset LevelMark VIII
/if (${Me.Level}>=60 && (${FindItem[Distillate of Skinspikes IX].ID})) /varset LevelMark IX
/if (${Me.Level}>=65 && (${FindItem[Distillate of Skinspikes X].ID})) /varset LevelMark X
/if (${Me.Level}>=70 && (${FindItem[Distillate of Skinspikes XI].ID})) /varset LevelMark XI
/if (${Me.Level}>=75 && (${FindItem[Distillate of Skinspikes XII].ID})) /varset LevelMark XII
/if (${Me.Level}>=80 && (${FindItem[Distillate of Skinspikes XIII].ID})) /varset LevelMark XIII
/if (${Me.Level}>=85 && (${FindItem[Distillate of Skinspikes XIV].ID})) /varset LevelMark XIV

/varset MyBestDSPotion "Distillate of Skinspikes ${LevelMark}"

     /if (!${Me.Buff[Distillate of Skinspikes].ID}) {
     	 /echo I am without DS !         
         /echo Checking for self DS potions.
         
	 /if (${FindItem[${MyBestDSPotion}].ID}) {
	     /echo Using potion: ${MyBestDSPotion}
	     /call cast ${MyBestDSPotion} item
	     /if (${Cursor.ID}) /autoinventory
	 } else {
	    /echo I do not have any DS potions !	 
	    /varset doDSCheck FALSE	    
	 }         	 
     } 	

/doevents   

/return
|--------------------------------------------------------------------------------

Code:
|--------------------------------------------------------------------------------
|SUB: SelfHasteCheck
|-------------------------------------------------------------------------------- 
Sub SelfHasteCheck 

/declare MyBestHastePotion  string local
/declare LevelMark          string local

/if (${Me.Level}>=1  && (${FindItem[Distillate of Alacrity I].ID})) /varset LevelMark I
/if (${Me.Level}>=5  && (${FindItem[Distillate of Alacrity II].ID})) /varset LevelMark II
/if (${Me.Level}>=10 && (${FindItem[Distillate of Alacrity III].ID})) /varset LevelMark III
/if (${Me.Level}>=20 && (${FindItem[Distillate of Alacrity IV].ID})) /varset LevelMark IV
/if (${Me.Level}>=30 && (${FindItem[Distillate of Alacrity V].ID})) /varset LevelMark V
/if (${Me.Level}>=40 && (${FindItem[Distillate of Alacrity VI].ID})) /varset LevelMark VI
/if (${Me.Level}>=50 && (${FindItem[Distillate of Alacrity VII].ID})) /varset LevelMark VII
/if (${Me.Level}>=55 && (${FindItem[Distillate of Alacrity VIII].ID})) /varset LevelMark VIII
/if (${Me.Level}>=60 && (${FindItem[Distillate of Alacrity IX].ID})) /varset LevelMark IX
/if (${Me.Level}>=65 && (${FindItem[Distillate of Alacrity X].ID})) /varset LevelMark X

/varset MyBestHastePotion "Distillate of Alacrity ${LevelMark}"

/if (!${Me.Buff[Celerity].ID} && !${Me.Buff[Swift Like the Wind].ID} && !${Me.Buff[Talisman of Celerity].ID} && !${Me.Buff[Swift Like the Wind].ID} && !${Me.Buff[Aanya's Quickening].ID} && !${Me.Buff[Wonderous Rapidity].ID} && !${Me.Buff[Visions of Grandeur].ID} && !${Me.Buff[Speed of the Brood].ID} && !${Me.Buff[Speed of Vallon].ID} && !${Me.Buff[Vallon's Quickening].ID} && !${Me.Buff[Speed of Salik].ID} && !${Me.Buff[Hastening of Salik].ID} && !${Me.Buff[Speed of Ellowind].ID} && !${Me.Buff[Speed of Ellowind Rk. II].ID} && !${Me.Buff[Speed of Ellowind Rk. III].ID} && !${Me.Buff[Hastening of Ellowind].ID} && !${Me.Buff[Hastening of Ellowind Rk. II].ID} && !${Me.Buff[Hastening of Ellowind Rk. III].ID} && !${Me.Buff[Speed of Erradien].ID} && !${Me.Buff[Speed of Erradien Rk. II].ID} && !${Me.Buff[Speed of Erradien Rk. III].ID} && !${Me.Buff[Hastening of Erradien].ID} && !${Me.Buff[Hastening of Erradien Rk. II].ID} && !${Me.Buff[Hastening of Erradien Rk. III].ID}) {

     /if (!${Me.Buff[Elixir of Speed ${LevelMark}].ID}) {
     	 /echo I am without haste !         
         /echo Checking for self haste potions.
         
	 /if (${FindItem[${MyBestHastePotion}].ID}) {
	     /echo Using potion: ${MyBestHastePotion}
	     /call cast ${MyBestHastePotion} item
	     /if (${Cursor.ID}) /autoinventory
	 } else {
	    /echo I do not have any haste potions !	 
	    /varset doHasteCheck FALSE	    
	 }         	 
     } 	     
}
   
/doevents
    
/return 
|--------------------------------------------------------------------------------
 
Nice ideas, but these can be generalized even more. The honest truth is that there's really no need to even have different subs -- you could do this all in one sub with only a few more lines of code and the addition of arguments to the subroutine call. That said, I would recommend implementing the following change in order to cut down massively on the number of calculations being performed each time.

Code:
Sub UseHealPotion 

/if(!${Defined[${Me.Name}LevelMark]}) {
    /declare ${Me.Name}LevelMark          string global
    /if (${Me.Level}>=1  && (${FindItem[Distillate of Divine Healing I].ID}))  /varset ${Me.Name}LevelMark I
    /if (${Me.Level}>=5  && (${FindItem[Distillate of Divine Healing II].ID}))  /varset ${Me.Name}LevelMark II
    /if (${Me.Level}>=10 && (${FindItem[Distillate of Divine Healing III].ID})) /varset ${Me.Name}LevelMark III
    /if (${Me.Level}>=20 && (${FindItem[Distillate of Divine Healing IV].ID})) /varset ${Me.Name}LevelMark IV
    /if (${Me.Level}>=30 && (${FindItem[Distillate of Divine Healing V].ID})) /varset ${Me.Name}LevelMark V
    /if (${Me.Level}>=40 && (${FindItem[Distillate of Divine Healing VI].ID})) /varset ${Me.Name}LevelMark VI
    /if (${Me.Level}>=50 && (${FindItem[Distillate of Divine Healing VII].ID})) /varset ${Me.Name}LevelMark VII
    /if (${Me.Level}>=55 && (${FindItem[Distillate of Divine Healing VII].ID})) /varset ${Me.Name}LevelMark VIII
    /if (${Me.Level}>=60 && (${FindItem[Distillate of Divine Healing IX].ID})) /varset ${Me.Name}LevelMark IX
    /if (${Me.Level}>=65 && (${FindItem[Distillate of Divine Healing X].ID})) /varset ${Me.Name}LevelMark X
    /if (${Me.Level}>=70 && (${FindItem[Distillate of Divine Healing XI].ID})) /varset ${Me.Name}LevelMark XI
    /if (${Me.Level}>=75 && (${FindItem[Distillate of Divine Healing XII].ID})) /varset ${Me.Name}LevelMark XII
    /if (${Me.Level}>=80 && (${FindItem[Distillate of Divine Healing XIII].ID})) /varset ${Me.Name}LevelMark XIII
    /if (${Me.Level}>=85 && (${FindItem[Distillate of Divine Healing XIV].ID})) /varset ${Me.Name}LevelMark XIV
}

/declare MyBestHealPotion string local "Distillate of Divine Healing ${${Me.Name}LevelMark}"
         
/echo Checking for self healing potions.

/if (${FindItem[${MyBestHealPotion}].ID})   {
    /echo Using potion: ${MyBestHealPotion}
    /call cast ${MyBestHealPotion} item
    /if (${Cursor.ID}) /autoinventory
} else {
    /echo I do not have any heal potions !
}                 

/doevents
    
/return

The changes are:
1) the addition of the ${Defined[]} TLO,
2) switching the LevelMark variable to global, and
3) changing the name of the LevelMark variable to ${Me.Name}LevelMark.

The reason for the first is because it means that you only have to perform all of those calculations the first time you call this subroutine, greatly speeding up its performance. The second change is necessary because local variables are destroyed outside of the subroutine that creates them. The third is necessary because it prevents multiple macros running this same subroutine from overwriting the global value of LevelMark -- each character will have its own value.

Personally, in order to make things prettier, I would make an entirely new subroutine that each of those subs could call that was named "Sub SetLevelMark" and set the global variable ${Me.Name}LevelMark to the correct value. Performance wise, there isn't a *huge* difference, but it means a lot fewer lines of code in your macro file, which adds up to less memory being used for the macro and more for your characters to use. These sorts of optimizations can add up to make a massive difference when applied to an entire macro.

This is untested, but the code for what I suggested would look something like this:

Code:
/call SetLevelMark "Distillate of Divine Healing"
Sub SetLevelMark(String potion)
/if(!${Defined[${Me.Name}LevelMark]}) {
    /declare ${Me.Name}LevelMark          string global
    /if (${Me.Level}>=1  && (${FindItem[${potion} I].ID}))  /varset ${Me.Name}LevelMark I
    /if (${Me.Level}>=5  && (${FindItem[${potion} II].ID}))  /varset ${Me.Name}LevelMark II
    /if (${Me.Level}>=10 && (${FindItem[${potion} III].ID})) /varset ${Me.Name}LevelMark III
    /if (${Me.Level}>=20 && (${FindItem[${potion} IV].ID})) /varset ${Me.Name}LevelMark IV
    /if (${Me.Level}>=30 && (${FindItem[${potion} V].ID})) /varset ${Me.Name}LevelMark V
    /if (${Me.Level}>=40 && (${FindItem[${potion} VI].ID})) /varset ${Me.Name}LevelMark VI
    /if (${Me.Level}>=50 && (${FindItem[${potion} VII].ID})) /varset ${Me.Name}LevelMark VII
    /if (${Me.Level}>=55 && (${FindItem[${potion} VII].ID})) /varset ${Me.Name}LevelMark VIII
    /if (${Me.Level}>=60 && (${FindItem[${potion} IX].ID})) /varset ${Me.Name}LevelMark IX
    /if (${Me.Level}>=65 && (${FindItem[${potion} X].ID})) /varset ${Me.Name}LevelMark X
    /if (${Me.Level}>=70 && (${FindItem[${potion} XI].ID})) /varset ${Me.Name}LevelMark XI
    /if (${Me.Level}>=75 && (${FindItem[${potion} XII].ID})) /varset ${Me.Name}LevelMark XII
    /if (${Me.Level}>=80 && (${FindItem[${potion} XIII].ID})) /varset ${Me.Name}LevelMark XIII
    /if (${Me.Level}>=85 && (${FindItem[${potion} XIV].ID})) /varset ${Me.Name}LevelMark XIV
}
/return

There's a more efficient way of determining the LevelMark number -- something that found the level range first and then found the best potion available, but this will do fine for the example.
 
nice

Thez thanks man... I love it when someone takes an aidea and improves upon it. I havent tested it yet.. but i do thank you for taking a look at it and trying to improve / consolodate it.

Thanks again for the positive feedback / improvements.