Gtam
Lerning how to write and read!! Yeah.
- Reaction score
- 164
Damage Counter
By Gtam
By Gtam
This is a nice little snippet.
Requires:
NewGen
AIDS made by Jesus4Lyf
Damage made by Jesus4Lyf
Event made by Jesus4Lyf
This snippet can detect how many damage a unit has taken over a period of time.
Use the function DamageCountAddUnit(whichunit) to start counting all the damage the unit took
Use the function GetDamageCount(whichunit) to get the amount whichunit has taken for adding to the function call
Use the function ResetDamageCount(whichunit) to set the damagecount of a unit to back to 0.
Here is the snippet
JASS:
library DamageCounter initializer DC_Init requires AIDS, Damage, Event
//======================================================================================\\
//======================================================================================\\
//== Damage Counter v1.06 ==\\
//== Created by Gtam ==\\
//== Functions ==\\
//== DamageCountAddUnit() takes unit. ==\\
//== Use this function to add a unit and start counting the taken damage ==\\
//== ResetDamageCount() takes unit. ==\\
//== Use this to set the damage counter of a unit to 0 ==\\
//== GetDamageCount() takes unit returns real ==\\
//== Use this to get the current damage taken by a unit ==\\
//== DamagecountRemoveUnit() takes unit ==\\
//== Use this to remove a unit from counting damage ==\\
//======================================================================================\\
//======================================================================================\\
//== Dont Touch
globals
group DCG = CreateGroup()
trigger DCT = CreateTrigger()
endglobals
struct DC extends array
//! runtextmacro AIDS()
real Damage
method AIDS_onCreate takes nothing returns nothing
set this.Damage = 0
endmethod
endstruct
private function DC_Actions takes nothing returns nothing
local DC d = DC[GetTriggerUnit()]
if IsUnitInGroup( GetTriggerUnit(), DCG) == true then
set d.Damage = d.Damage + GetEventDamage()
endif
endfunction
private function DC_Init takes nothing returns nothing
call Damage_RegisterEvent(DCT)
call TriggerAddAction( DCT, function DC_Actions)
endfunction
function DamageCountAddUnit takes unit added returns nothing
if IsUnitInGroup(added, DCG) == false then
call GroupAddUnit(DCG, added)
endif
endfunction
function GetDamageCount takes unit damage returns real
return DC[damage].Damage
endfunction
function ResetDamageCount takes unit reset returns nothing
set DC[reset].Damage = 0
endfunction
function DamageCountRemoveUnit takes unit remove returns nothing
if IsUnitInGroup(remove, DCG) == true then
call GroupRemoveUnit(DCG, remove)
endif
endfunction
endlibrary
Hope its help full.
Credits not needed incase you wanted to know
Code:
Changelog
v1.00 Released
v1.01 Spell target added
v1.02 Complete revamp
v1.03 Uses only 1 trigger now
v1.04 Leakless
v1.05 AIDS Struct
v1.06 Little update