Moderator
M
Moderator
Damage Over Interval Time. v3 | Reviewed by Maker | 28th May 2013 | ||||
APPROVED | ||||
|
library DamageOverIntervalTime initializer Init /* v 3.00 by Gorillabul
************************************************************************************************************************************************************************************
* A simple system which is able to deal damage over intervals of time, compared to other damage over time systems which deal
* damage every 0.01 second, dealing damage over an interval is idea for things like custom critical strike. Can also handle heals
* over time. You can "stack" multiple instances on one unit however they will not be merged ... yet.
********************************************************************************************************************************************************************************
*/
globals
private unit array doitDamager //The Unit dealing the damage.
private unit array doitTarget // The target Unit
private real array doitDamage //Amount of damage PER INTERVAL
private integer array doitCounting
private integer array doitRecycler
private integer array doitPrev
private integer array doitNext
private integer array doitIterations //Number of times to add 1 to doitCurrentIteration ( interval/0.03125 )
private integer array doitCurrentIteration //Counting variable
private integer array totalCurrentDoitIterations //Total iterations for an instance, if u specify a duration of 15 second and interval of 3 this is 5 (duration/interval)
private integer array doitTci //Used to generate a consecutive Damage over time instance.
private timer doitTimer //Timer to loop through the instances and pause if unused.
private attacktype array doitDamageTypeIndex // the attacktype that deals damage for each instance(hero fortified siege...)
private integer array doitInstanceIndex //the attacktype index is set by the user when using ApplyDotEffect and is set to integer aid
/*
set doitDamageTypeIndex[0] = ATTACK_TYPE_CHAOS
set doitDamageTypeIndex[1] = ATTACK_TYPE_MAGIC
set doitDamageTypeIndex[2] = ATTACK_TYPE_NORMAL
set doitDamageTypeIndex[3] = ATTACK_TYPE_PIERCE
set doitDamageTypeIndex[5] = ATTACK_TYPE_SIEGE
*/
endglobals
/**********************************************************************************************************************************************************************************
*HOW TO USE-
*
*function ApplyDotEffect takes unit damager , unit target , real damg , real duration , real interval, integer attacktypeindex returns nothing
*
* -this function will register a unit to be damaged or healed over time, the names are self explanatory duration is how long
* you want your target to be damaged for and interval is the timeout between dealing damage.
* For example a unit takes damage every 3 seconds for 15 seconds would define an interval of 3 and a duration of 15.
* The aid integer corresponds to doitInstanceIndex and determines the attacktype used per instance, look at how doitDamageTypeIndex
* is set.
*
*****************************************************************************************************************************************************************************
*
*
***********************************************************************************************************************************************************************
*HOW TO IMPORT
*
*Copy this trigger into your map, then call ApplyDotEffect(caster, target, amount , duration , interval ) set amount to a negative value
* for healing over time.
***********************************************************************************************************************************************************************/
private function DoitLoop takes nothing returns nothing
local integer l = doitNext[0]
if l == 0 then
call PauseTimer(doitTimer)
endif
loop
exitwhen l == 0
set doitCurrentIteration[l] =doitCurrentIteration[l] + 1
if doitCurrentIteration[l] == doitIterations[l] then
set doitCurrentIteration[l] = 0
set doitTci[l] = doitTci[l] + 1
if not IsUnitType(doitTarget[l], UNIT_TYPE_DEAD) then
if doitDamage[l] > 0 then
call UnitDamageTarget( doitDamager[l] , doitTarget[l], doitDamage[l] , true, false, doitDamageTypeIndex[doitInstanceIndex[l]], DAMAGE_TYPE_UNIVERSAL, null)
else
call SetWidgetLife(doitTarget[l], GetWidgetLife(doitTarget[l]) + (doitDamage[l] * -1 ))
endif
else
set doitNext[doitPrev[l]] = doitNext[l]
set doitPrev[doitNext[l]] = doitPrev[l]
set doitRecycler[l] = doitRecycler[0]
set doitRecycler[0] = l
set totalCurrentDoitIterations[l] = 0
set doitIterations[l] = 0
set doitTci[l] = 0
endif
endif
if doitTci[l] == totalCurrentDoitIterations[l] and IsUnitType(doitTarget[l], UNIT_TYPE_DEAD) ==false then
set doitNext[doitPrev[l]] = doitNext[l]
set doitPrev[doitNext[l]] = doitPrev[l]
set doitRecycler[l] = doitRecycler[0]
set doitRecycler[0] = l
set totalCurrentDoitIterations[l] = 0
set doitIterations[l] = 0
set doitTci[l] = 0
endif
set l = doitNext[l]
endloop
endfunction
function ApplyDotEffect takes unit damager , unit target , real damg , real duration , real interval, integer attacktypeindex returns nothing
local integer instance = R2I(duration / interval )
local integer id = doitRecycler[0]
call TimerStart(doitTimer, 0.031250000, true , function DoitLoop )
if id == 0 then
set doitCounting[0] = doitCounting[0] + 1
set id = doitCounting[0]
else
set doitRecycler[0] = doitRecycler[id]
endif
set doitNext[id] = 0
set doitPrev[id] = doitPrev[0]
set doitNext[doitPrev[0]] = id
set doitPrev[0] = id
set doitDamager[ id] = damager
set doitTarget[ id] = target
set doitIterations[id] = R2I(interval / 0.03125)
set totalCurrentDoitIterations[id] = R2I(instance)
set doitDamage[id] = damg /instance
set doitInstanceIndex[id] = attacktypeindex
endfunction
private function Init takes nothing returns nothing
local integer l = 0
local trigger t = CreateTrigger( )
set doitRecycler[0] = 0
loop
exitwhen l > 15
set doitCounting [l] = 0
set l = l + 1
endloop
set doitDamageTypeIndex[0] = ATTACK_TYPE_CHAOS
set doitDamageTypeIndex[1] = ATTACK_TYPE_MAGIC
set doitDamageTypeIndex[2] = ATTACK_TYPE_NORMAL
set doitDamageTypeIndex[3] = ATTACK_TYPE_PIERCE
set doitDamageTypeIndex[5] = ATTACK_TYPE_SIEGE
set doitCounting[0] = 0
set doitTimer = CreateTimer()
endfunction
endlibrary