• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

How to make "takes damage" event to affect all uni

Status
Not open for further replies.
Level 4
Joined
Nov 22, 2004
Messages
62
heres the deal:
you're going to create 3 triggers

forst one picks the units already in the game
Event
-Map initialization
Actions
-Unit Group - pick every units in playable map area and do actions:
-add to (your trigger) the event [Picked unit takes damage]

secnd one picks each unit as they enter the game

event
-unit enters playable map area
actions
-add to (your trigger) the event [entering unit takes damage]

now you create the last and most important trigger: the one that will trigger the actions based off the damage taken

(Your trigger)
Event
(none)
Actions
-insert whatever you want here that will trigger off damage. any kind of damage, even from spells.

i hope it helps
 
Level 4
Joined
Nov 22, 2004
Messages
62
look, the takes damage event only works on preset units.
the trick i did up there is to set all the units already on the map and the units that enter the map as a preset on the third trigger, so, if you create an action on the third trigger, you can select takes damage

this is the trick to show damage text too.

juts insert in the third trigger the actions for flating text show damage taken and stuff.
 
Level 2
Joined
Jun 7, 2006
Messages
5
Raydrik said:
heres the deal:
you're going to create 3 triggers

forst one picks the units already in the game
Event
-Map initialization
Actions
-Unit Group - pick every units in playable map area and do actions:
-add to (your trigger) the event [Picked unit takes damage]

secnd one picks each unit as they enter the game

event
-unit enters playable map area
actions
-add to (your trigger) the event [entering unit takes damage]

now you create the last and most important trigger: the one that will trigger the actions based off the damage taken

(Your trigger)
Event
(none)
Actions
-insert whatever you want here that will trigger off damage. any kind of damage, even from spells.

i hope it helps
Thanks! It really helps!
 
Level 4
Joined
Nov 22, 2004
Messages
62
yeah, i know that if a hero dies and revives it will have another event for the same unit, triggering itmore than once, thus lagging the map. but this is the way i found.

you can, however, use the custom value of unit and do like , when a hero enters map, if his custom value is 0, then set to 1 and add it to trigger. if its 1, then d nothing.

BTW i think it was you who warned me about the hero reviving stuff, PurplePoot

PS: grats on mod stats
 
Level 11
Joined
Feb 22, 2006
Messages
752
JASS:
function Trig_Damage_Event takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
//this is where you put ur actions concerning the damage event
    call DestroyTrigger(t)
    set t = null
endfunction

function Trig_Damage_Actions takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
    call TriggerAddAction( t, function Trig_Damage_Event )
    set t = null
endfunction

//====================================================================
function InitTrig_Damage takes nothing returns nothing 
    set gg_trg_Damage = CreateTrigger( ) 
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Damage, EVENT_PLAYER_UNIT_ATTACKED ) 
    call TriggerAddAction( gg_trg_Damage, function Trig_Damage_Actions ) 
endfunction

This trigger doesn't have any problems w/ hero revives and stuff. It exploits the fact that the event Unit is Attacked triggers BEFORE the unit actually takes damage and that the TriggerRegisterUnitEvent CAN take a function as its second parameter (don't ask me why blizz made it so that it takes functions but not variables).
 
Level 11
Joined
Jul 12, 2005
Messages
764
I use this in my Damage Delay System:
JASS:
function Trig_Damage_Event_Conditions takes nothing returns boolean
return GetEventDamageSource() == GetHandleUnit(GetTriggeringTrigger(), "Attacker")
endfunction

function Trig_Damage_Event takes nothing returns nothing 
local trigger t = GetTriggeringTrigger() 
//this is where you put ur actions concerning the damage event 
call FlushHandleLocals(t)
call DestroyTrigger(t) 
set t = null 
endfunction 

function Trig_Damage_Actions takes nothing returns nothing 
local trigger t = CreateTrigger() 
call SetHandleHandle(t, "Attacker", GetAttacker())
call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED ) 
call TriggerAddCondition(t, Condition( function Trig_Damage_Event_Conditions))
call TriggerAddAction( t, function Trig_Damage_Event ) 
call TriggerSleepAction(1)
call FlushHandleLocals(t)
call DestroyTrigger(t)
set t = null 
endfunction 

//==================================================================== 
function InitTrig_Damage takes nothing returns nothing 
set gg_trg_Damage = CreateTrigger( ) 
call TriggerRegisterAnyUnitEventBJ( gg_trg_Damage, EVENT_PLAYER_UNIT_ATTACKED ) 
call TriggerAddAction( gg_trg_Damage, function Trig_Damage_Actions ) 
endfunction

See... This would be a solution, but it uses handle vars, that make it a bit laggy. But it works properly.
AND also, if the unit misses or does not deal the damage, the trigger will not be destroyed! So i put a wait in the 'Attacked' trigger. (This is the only "crack" in the script.)
 
Level 11
Joined
Feb 22, 2006
Messages
752
lol paskovich u stole my solution :p, and I don't think it will lag - I use basically the same thing in my map and even when I have like 50 units attacking my hero all at once I can't feel any lag.

If u want spells to trigger this just add in another global trigger with the event UNIT_SPELL_CAST_EVENT(not sure if thts the correct wording...), and have the local trigger's event's second parameter to be GetSpellTargetUnit().

P.S. If for some reason the damage done by a unit is reduced to 0 (i.e. because of the hardened skin ability), the UNIT_TAKES_DAMAGE event will still trigger. Not sure about misses though.
 
Status
Not open for further replies.
Top