Darthfett
Aerospace/Cybersecurity Software Engineer
- Reaction score
- 615
Code:
//====================================================================================
//The following Triggers may be removed if you have Kattana's System already in place.
//====================================================================================
function H2I takes handle H returns integer
return H
return 0
endfunction
function LocalVars takes nothing returns gamecache
return InitGameCache("jasslocalvars.w3v")
//======Replace "InitGameCache("jasslocalvars.w3v")" with a global Variable!======
endfunction
function GetHandleTimer takes handle h, string key returns timer
return GetStoredInteger(LocalVars(),I2S(H2I(h)),key)
return null
endfunction
function GetHandleString takes handle h, string key returns string
return GetStoredInteger(LocalVars(),I2S(H2I(h)),key)
return ""
endfunction
function GetHandleUnit takes handle h, string key returns unit
return GetStoredInteger(LocalVars(),I2S(H2I(h)),key)
return null
endfunction
//====================================================================================
//=============The following functions must be implemented into the map.==============
//====================================================================================
function StopAutoCast takes unit Caster returns nothing
//================Call this function to stop a unit from autocasting.=================
local string S = GetHandleString(Caster,"O")
call DestroyTimer(GetHandleTimer(Caster,S))
call FlushStoredMission(LocalVars(),S)
call FlushStoredMission(LocalVars(),I2S(H2I(Caster)))
set S = ""
endfunction
function AutoCastAbil takes nothing returns nothing
local timer T = GetExpiredTimer()
local unit u = GetHandleUnit(T,"u")
local string O = GetHandleString (T,"O")
call IssueImmediateOrder(u,O)
set T = null
set u = null
endfunction
function AutoCastInit takes unit Caster, string Order, real CoolDown returns nothing
//==========This is the Init function. Call it to start a unit autocasting.==========
local timer T = CreateTimer()
local string O = Order
local string t = I2S(H2I(T))
local unit u = Caster
call StoreInteger(LocalVars(),I2S(H2I(Caster)),O,H2I(T))
call StoreInteger(LocalVars(),t,"O",S2I(Order))
call StoreInteger(LocalVars(),t,"u",H2I(u))
call TimerStart(T,CoolDown + 0.01,true,function AutoCastAbil)
set O = ""
set u = null
set t = ""
set T = null
endfunction
//========Description========//
This is an autocasting system, for any spell. To make a unit start autocasting, simply call the last function (AutoCastInit), with the Caster, Ability order, and the cooldown of the ability. Once you call this function, it will constantly order the unit to cast, but only when the cooldown of the spell has finished. It is compatable with Kattana's Local Handle Variable system, as well as Vexorian's Caster System.
//========Implement Instructions========//
In order to use this in your map, copy and paste the code into your map header, and change the LocalVars function to include your global gamecache. You must also properly initialize the game cache, in a trigger that runs at map initialization, like this:
Code:
Custom Script: call FlushGameCache(InitGameCache("udg_GC"))
Custom Script: set udg_GC = InitGameCache("udg_GC")
When an autocasting unit dies, you will have to call the StopAutoCast function with your dieing unit, so that the function will not keep ordering the dead unit to cast.
//========Features========//
-Accurate timer orders
-Completely MUI (Multi-Instanceable)
-Leakless
-An easy-off function to stop an autocasting unit, and remove all useless attached variables.
-Simple to use
Please give credit if you use this in your map!