XeNiM666
I lurk for pizza
- Reaction score
- 138
TriggerRegisterAnyUnitDamageEvent
Well basically this adds an event to a trigger "Any unit Takes Damage" with a small feature.
The small feature is that you can show the damage dealt whether any unit in the map takes damage. You can set it so there's a point in time that no damage is shown.
What to do:
Just copy the code below:
JASS:
scope Damage initializer Initialization
globals
// SELF EXPLANATORY
// SET THIS TO FALSE IF YOU DONT WANT TO SHOW DAMAGE DEALT
public boolean Show_Damage_Dealt = true
// IF Show_Damage_Dealt = true THEN THIS IS THE COLOR OF THE TEXTTAG THAT WILL SHOW THE DAMAGE DEALT
private constant string Damage_dealt_Texttag_color = "|CFF000000"
//********************************************************************//
// TOUCH ONLY IF YOU KNOW WHAT TO DO... //
//********************************************************************//
public constant trigger trig = CreateTrigger()
private constant group Dmg_Grp = CreateGroup()
endglobals
private function Damage_Check takes nothing returns boolean
return IsUnitInGroup( GetTriggerUnit(), Dmg_Grp ) == true and GetEventDamage() > 0.00 and Show_Damage_Dealt == true
endfunction
private function Damage_Show takes nothing returns nothing
local texttag tt = CreateTextTag()
local unit u = GetTriggerUnit()
local real x = GetUnitX( u )
local real y = GetUnitY( u )
call SetTextTagText( tt, Damage_dealt_Texttag_color + I2S( R2I( GetEventDamage() ) ), 0.023 )
call SetTextTagVelocity( tt, 0.06102 * Cos( 90.00 * bj_DEGTORAD ), 0.06102 * Sin( 90.00 * bj_DEGTORAD ) )
call SetTextTagPos( tt, x, y, 0.00 )
call SetTextTagPermanent( tt, false )
call SetTextTagLifespan( tt, 2.50 )
call SetTextTagFadepoint( tt, 1.00 )
set tt = null
set u = null
endfunction
//=================================================================================================
private function Check takes nothing returns boolean
return IsUnitInGroup( GetFilterUnit(), Dmg_Grp ) == false
endfunction
private function Actions takes nothing returns nothing
local group g = CreateGroup()
local unit u = null
call GroupEnumUnitsInRange( g, 0.00, 0.00, 99999.00, Condition( function Check ) )
loop
set u = FirstOfGroup( g )
// REGISTER UNIT DAMAGE EVENTS IN EVERY DAMAGE DETECTION TRIGGER
call TriggerRegisterUnitEvent( trig, u, EVENT_UNIT_DAMAGED )
call GroupAddUnit( Dmg_Grp, u )
exitwhen u == null
call GroupRemoveUnit( g, u )
endloop
call DestroyGroup( g )
set g = null
endfunction
function TriggerRegisterAnyUnitDamageEvent takes trigger t returns nothing
local group g = Dmg_Grp
local unit u = null
loop
set u = FirstOfGroup( g )
exitwhen u == null
call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DAMAGED )
call GroupRemoveUnit( g, u )
endloop
call DestroyGroup( g )
set g = null
set u = null
endfunction
//===========================================================================
private function Initialization takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterTimerEvent( t, 0.50, true )
call TriggerAddAction( t, function Actions )
set t = null
call TriggerAddCondition( trig, Condition( function Damage_Check ) )
call TriggerAddAction( trig, function Damage_Show )
call Preload( Damage_dealt_Texttag_color )
call PreloadStart()
endfunction
endscope
This code contains this function:
Sample:
JASS:
call TriggerRegisterAnyUnitDamageEvent( MyTrigger )
What this does is register "Any unit Takes Damage" to the trigger of your choice.
Features:
As you can see there are 2 configurables, Show_Damage_Dealt and Damage_dealt_Texttag_color.
Show_Damage_Dealt - A boolean whether the damage is shown when any unit in the map takes damage.
Damage_dealt_Texttag_color - A string containing the color of the texttag created to show how much damage is dealt.
To set whether show any damage, do this:
JASS:
set Show_Damage_Dealt = true
if you dont want to show damage, do this:
JASS:
set Show_Damage_Dealt = false
Enjoy!
~ XeNiM666