Time for a beta release of a header file I started working with before my lengthy break and finally did get into a stage I can call if beta version. It's a simple header file that can be called from any script. It's purpose is to cast a spell for the parent script and return the time it takes to cast and recover from the spell. Nothing fancy, I know, but it will be the base for the mage's auto-attacker I have pretty well planned already.
At the moment, this header only supports Magery, Necromancy and Chivalry spells, but in due time, I'll try to get Bushido, Ninjutsu and Druid spells along with mounting ethereal mounts in the same header. I also know this does look like the hardest way to do it, but unfortunately, #lSpell isn't used by our server, so it's not possible to poll that system variable, which would indeed make things a lot easier. That being said, this "harder" method seems to be reliable and fast for as long as scripts do the casting. I really do not even want to think about journal scan as an option to see user cast spells, but for those who need that option, it's the only way, really.
Now, here's the header file:
Code: Select all
; Shindaril's Casting Related Subs
; Version: beta 1.1.22
; Date: 11.2.2018
;
; Simple way of casting spells and getting a cast timer value
; to be used in automated casting scripts
;
; Required variables: SubName, SpellNumber (as listed in event macro table), FC, FCR, Protection
; Return variable is *SReturn which contains the casting time in tenths of seconds or SCMissingVariables
; if inappropriate number of variables are used with call
;
; Supports Magery, Necromancy and Chivalry spells
; To be added later
; -Bushido abilities
; -Ninjutsu abilities
; -Druid spells
; -Ethereal mounts (yes, mounting these does act like casting a spell)
;
; Suggested that a global namespace is used when multiple scripts are using spellcasting so that the
; timer can be shared by each of them. This should rely on #sCnt2, which is not set by any of the scripts
; sharing the timers. This is to avoid the need for syncing the timers as #sCnt2 is already in sync between
; the scripts. Global namespace would allow for shared variables for last casting time and casting time.
;
; My apologies for the lack of comments in this script. I have a documentation in a separate file and as there
; is no setup with this header file, I don't see any need for combining the documentation to here as comments.
;
set #lpc 1000
set *SReturn 0
if %0 <> 5
{
set *SReturn SCMissingVariables
exit
}
namespace push
namespace local SCasting
set !SCSubName %1
set !SCSpellNumber %2
set !SCUserFC %3
set !SCUserFCR %4
set !SCProtectionOn %5
gosub !SCSubName
set *SReturn !SCResult
namespace clear
namespace pop
exit
sub CastSpell
set #lSpell !SCSpellNumber
gosub CheckForCasting
while !SCResult = 0
{
wait 1
}
event macro 15 !SCSpellNumber
return
sub CheckForCasting
if #lSpell < 64 ; Magery spells
{
if !SCProtectionOn = #True && !SCUserFC > 0
{
set !SCUserFC 0
}
else if !SCUserFC > 2
{
set !SCUserFC 2
}
gosub MagerySpellCast #lSpell
gosub MageryCastingTime #Result
set !SCResult !SCCastingTime
return
}
if #lSpell > 100 && #lSpell < 117
{
gosub NecromancySpellCast #lSpell
gosub NecromancyCastingTime #Result
set !SCResult !SCCastingTime
return
}
if #lSpell > 200 && < 211
{
if !SCProtectionOn = #True && !SCUserFC > 2
{
set !SCUserFC 2
}
else
{
if !SCUserFC > 4
{
set !SCUserFC 4
}
}
gosub ChivalrySpellCast #lSpell
gosub ChivalryCastingTime #Result
set !SCResult !SCCastingTime
return
}
return
sub MagerySpellCast
if %1 >= 0 && %1 <= 7
{
set #lSpell 255
return 1
}
if %1 >= 8 && %1 <= 15
{
set #lSpell 255
return 2
}
if %1 >= 16 && %1 <= 23
{
set #lSpell 255
return 3
}
if %1 >= 24 && %1 <= 31
{
set #lSpell 255
return 4
}
if %1 >= 32 && %1 <= 39
{
set #lSpell 255
if %1 = 32
{
return 20
}
if %1 = 39
{
return 40
}
return 5
}
if %1 >= 40 && %1 <= 47
{
set #lSpell 255
return 6
}
if %1 >= 48 && %1 <= 55
{
set #lSpell 255
return 7
}
if %1 >= 56 && %1 <= 63
{
set #lSpell 255
return 8
}
set #lSpell 255
return 0
sub MageryCastingTime
set !SCCircle %1
set !SCCastingTime ( ( ( ( 300 + !SCCircle * 100 ) / 4 - ( !SCUserFC * 100 ) / 4 ) + ( 600 - !SCUserFCR * 100 ) / 4 ) )
if !SCCastingTime % 10 <> 0
{
set !SCCastingTime ( !SCCastingTime + 5 )
}
set !SCCastingTime ( !SCCastingTime / 10 + 1 )
return
sub NecromancySpellCast
if %1 in 104_105_115_
{
set #lSpell 225
return 1
}
if %1 = 109
{
set #lSpell 225
return 2
}
if %1 in 101_102_103_108_
{
set #lSpell 225
return 4
}
if %1 in 106_107_110_111_112_113_114_116_
{
set #lSpell 225
return 6
}
return
sub NecromancyCastingTime
set !SCCircle %1
set !SCCastingTime ( ( ( ( 300 + !SCCircle * 100 ) / 4 ) + ( 600 - !SCUserFCR * 100 ) / 4 ) ) ; FC doesn't affect on Necromancy
if !SCCastingTime % 10 <> 0
{
set !SCCastingTime ( !SCCastingTime + 5 )
}
set !SCCastingTime ( !SCCastingTime / 10 + 1 )
return
sub ChivalrySpellCast
if %1 = 204
{
set #lSpell 255
return -1
}
if %1 = 203 || %1 = 206
{
set #lSpell 225
return 0
}
if %1 = 207
{
set #lSpell 225
return 1
}
if %1 = 201 || %1 = 205
{
set #lSpell 225
return 2
}
if %1 in 202_208_209_210_
{
set #lSpell 225
return 4
}
return
sub ChivalryCastingTime
set !SCCircle %1
set !SCCastingTime ( ( ( ( 300 + !SCCircle * 100 ) / 4 - ( !SCUserFC * 100 ) / 4 ) + ( 700 - !SCUserFCR * 100 ) / 4 ) )
if !SCCastingTime % 10 <> 0
{
set !SCCastingTime ( !SCCastingTime + 5 )
}
set !SCCastingTime ( !SCCastingTime / 10 + 1 )
return
Code: Select all
; Test script for SCastingHeader.txt
set *SReturn 0
set %SCastingHeaderPath C:\Users\Xarzith\Desktop\EasyUO , #spc , Macros\SCastingHeaderTemp.txt ; Path to the header file
set #sCnt2 0 ; This shouldn't be used if multiple spellcasting scripts are run simultaneously - refer to the header file
set %CastingTime 0 ;
set %LCastingTime #sCnt2 ;
while #True ; This example script loops endlessly, which has made testing the header possible
{
if ( %LCastingTime + %CastingTime ) <= #sCnt2 ; Let's test if last spell has been cast and recovered from - Can we cast a spell yet?
{
call %SCastingHeaderPath CastSpell 32 2 6 #True ; Example of casting a spell
set %CastingTime *SReturn ; Record the casting time
set %LCastingTime #sCnt2 ; set the time when last spell was cast by this script
; event ExMsg #CharID 0 20 *SReturn ; Used for testing purposes, shows the header file's return variable overhead
set *SReturn 0 ; Obsolete as the header file does this once it's called, added in the testing script only as a precaution
}
}