• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Trigger Spells - The Elusive Any Unit Takes Damage Trigger

Status
Not open for further replies.
Level 2
Joined
Dec 8, 2005
Messages
9
I've seen so many people tearing their hair out, attempting to find a way to do an Any Unit Takes Damage Event / trigger, for Counter Spells, Channel Breakers, Stun Negation, and many other great ideas. In turn, I myself was unable to find any real help on the topic. As most map developers who know how to do it keep it a secret for whatever reason - maybe not wanting to release their 200 line JASS code they slaved over. Im pretty new to the World Editor, and Ill show you a quick and easy way I've discovered to make a Any Unit Takes Damage Event / Trigger in a matter of seconds in the GUI.

This will allow you to poll you're hero's as units to validate them for Specific Unit Takes Damage. Its so easy, you'll probably be understandably livid when you realize its simplicity.

Easy Enough For Newbs
Lets get started...

First off, Create a map with a tavern and set the dependencies in the Advanced/Gameplay Constants for ALTAR to a circle of power you will create, owned by a player. Delete the Melee triggers, as they are useless at the time. Place some random creeps around to give you some damage.

I wont be adding any trigger spells here, so the only confirmation you'll have is text displays of your heros and how much damage each is taking. Add some actions after you get it built to play aroud with it.

The Triggers

Create two triggers, the First is your initialization trigger for allowing the Any Unit Takes Damage Trigger to work.


Initialization Trigger:
[simplest ever]

Events:
Map Initialization
Unit - A unit Enters (Entire Map)

Conditions: None

Actions: Unit Group - Pick Every unit in (Units in Playable Map Area) and do (Actions)

[loop actions]
Game - Display to (All Player) the Text: ((Name of (Picked Unit)) + Is Alive)
Trigger - Add to ***Name of Other Trigger Here*** the event (unit - (Picked unit) Takes Damage

This adds the events to the second trigger, every time a unit gets spawned, it recalculates the triggers - which the GUI Happily denied you of creating :) Simple Huh? You can add - in a IF for constraining heros, but I like to use creep-damage detection too.


2nd Trigger:

Events: NONE!
Conditions: NONE!
Actions: Game - Display to (All Players) the text: ((Name of (triggering unit)) + (String(Damage Taken))))

Thats pretty much it.. if you want, and I know you will. Many people might say it does nothing at all really - but consider the balance abilites - being able to see so easily all the damage that all units are taking - I add it every time im programming a new trigger - just to be sure the damage is not too extreme. Add some IF's and Actions for you're buffs or abilities you want to constrain the trigger spell for. You can now Freely use (Damage Taken) instead of Attacked Unit / "Wait for Life of attacked unit Less Than Variable"


You can use many other events besides the Unit Takes Damage to make extremely intuitive spells without quite as much line after line after line of validation. I used it for an ability for a Dragoon Knight to have a 20% Chance to block a percentage of the overall damage, regardless of type and Increasing Bounceback damage equal to the amount blocked (100% at level 50, because my maps are always 256x256 Rpg -style maps). The ability passively works against anything but aoe - making you wish you hadn't blasted Level 30 Meteor for 1200 mana just to see it bounce right back in you're face! haha.

I realize this is very simple, but so many people seem not to know how to do it. I know there's probably so many ways to go about it, but this way you dont need any variables or powerfull JASS, so it stays MUI and its so easy to create. Maybe im just super-noob and everyone knows how to do this, but I couldnt find any help on it.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Its imposiable to make a perfect generic a unit takes damage event with out using jass.

Look at yours it leaks.
Do you ever remove that event after it is added or eventualy will you get 1000s of events attached to that 1 trigger? and what about already placed units?
Note im not saying your system is bad.

With jass you can make it alot more complex but thats only needed in advanced maps.

Note im not saying yours is bad im saying with jass it can be made slightly more complex so it has custom effects like reduced damage when near a group of units which would normaly leak with GUI.

Still its not bad for the ordnary map.
 
Level 2
Joined
Dec 8, 2005
Messages
9
Reworked

Yes, ive noticed it runs much better when I added a 'Cycling Redundancy Check' - ensuring that only 1 trigger per hero is made, the trigger is a bit more complex, but currently with the fixed trigger, I have little floating text [Final Fantasy Style] for all damage. I noticed that I was getting a huge amount of triggers made when my creeps respawn, now it only creates 1 trigger for each hero and runs much more smoothly. I should be posting the updated trigger later on today.
 
Level 2
Joined
Dec 8, 2005
Messages
9
Updated Trigger for Any Unit Takes Damage

Ok - here we go the updated trigger.

This trigger will allow for a redundancy check, making sure only one trigger exists for each hero on the map. Only adding events to the secondary trigger when the hero does not already have one.

You will need to create three variables
An Integer variable - I Named it NumberOfHeros
Another Integer variable - I Named it FoundHeros
A Unit Array variable - I Named it UnitArray[#]

Now heres the trigger

Events:

Map Initialization
Unit - A unit enters entire map

Conditions: None

Actions:

Unit Group - Pick every unit in (Units in (Playable Map Area) and do (Actions)
-Loop Actions
If - Conditions
((Picked Unit) is a Hero) Equal to True)
Then - Actions
Set FoundHeros = 0
For Each (Integer A) from 1 to NumberOfHeros , do (Actions)
-Loop Actions
If ((Picked Unit) Equal to UnitArray[(Integer A)] then do (Set FoundHeros = (FoundHeros + 1) else (Do Nothing)
-(end loop action)
If (All conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
FoundHeros = 0
Then - Actions
Game - Display to (All Players) the text: (Creating Trigger for + (Name of (Picked Unit))
Set NumberOfHeros = (NumberofHeros + 1)
Set UnitArray[NumberOfHeros] = (Picked Unit)
Trigger - Add to [your second trigger name] the event (Unit - UnitArray[NumberOfHeros] Takes Damage)
Else - Actions
Game - Display to (All Players) the text: (Trigger Already Exists For = (Name of (Picked Unit))
Else - Actions
Do Nothing

Thats the 1st trigger, which refers to the 2nd trigger to add the events for each hero taking damage, based on none of the picked units equals any value in the UnitArray[#] that each hero has been added to. This allows for each time a hero is spawned, even if they are of the same type, they all have seperate damage readouts, and no duplicated data - like my original trigger's errors. Now the Second Trigger

Trigger 2:

Events - [they'll be added by the 1st trigger] NONE

Conditions - NONE [only heros events will be passed anyway]

Actions -
Floating Text - Create Floating text That reads (String(Integer((Damage Taken)))) above (Triggering Unit) with Z offset 0.00, Using font size 10.00, Color (100%, 0%, 0%) and 0.00% Transparency
Floating Text - Set the Velocity of (Last Created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last Created floating text): Disable Permanence
Floating Text - Change the Lifespan of (Last Created floating text) to 1.00 Seconds
Floating Text - Change the Fading age of (Last Created floating text) to 0.50 Seconds

From here I continue to add the code for all my specialized (damage taken) abilites and such. Like a Block Spell which blocks a percentage of attack damage of any type [even spells] and returns another percentage back to the caster/area. Another is a Critical Negation spell that returns the amount of critical damage but allows the regular damage to pass through. Have fun with it, im sure there are plenty of great ideas stewing around.

Good luck
Cliff
 
Level 2
Joined
Dec 8, 2005
Messages
9
Clarification

Let me clarify that the first Loop Action Embodies the entire rest of the trigger, and the 1st (end loop actions) is for the 2nd set of loop actions.
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
PurplePoot said:
instead of doing that to check if the unit is already registered in the event, you can just have 1 for map initialization ONLY, then another that says

Events - Unit enters entire map

Conditions - none

Actions

TriggerAddEvent(or whatever) that that unit takes damage.

Buggy. When heroes are killed, they are moved outside the map. ;)

~Daelin
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
PurplePoot wrote:
instead of doing that to check if the unit is already registered in the event, you can just have 1 for map initialization ONLY, then another that says

Events - Unit enters entire map

Conditions - none

Actions

TriggerAddEvent(or whatever) that that unit takes damage.

i suppose you could change it to playable map area, but then would this trigger whenever a unit is moved via triggers? in that case, i suppose you could

Unit Is Created

Unit Is Summoned

Unit Finished Construction

Etc.
 
Level 4
Joined
Nov 22, 2004
Messages
62
Code:
set units
    Events
        Time - Elapsed game time is 0.05 seconds
        Unit - A unit enters (Playable map area)
    Conditions
    Actions
        Trigger - Add to return <gen> the event (Unit - (Entering unit) Takes damage)
        Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            Loop - Actions
                Trigger - Add to return <gen> the event (Unit - (Picked unit) Takes damage)


return
    Events
    Conditions
    Actions
        Floating Text - Create floating text that reads (String((Integer((Damage taken))))) above (Triggering unit) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
        Floating Text - Set the velocity of (Last created floating text) to 96.00 towards 90.00 degrees
        Floating Text - Change (Last created floating text): Disable permanence
        Floating Text - Change the lifespan of (Last created floating text) to 0.50 seconds
        Floating Text - Change the fading age of (Last created floating text) to 0.00 seconds

thats my trigger for showing units damages over head. if you change the "return" trigger to ANY action based on damage taken, like give gold equal to damage taken.
 
Status
Not open for further replies.
Top