• 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] Unit Attacks Event?

Status
Not open for further replies.
Level 6
Joined
May 12, 2013
Messages
90
Hello. I noticed in Event creation there is [Unit - Is Attacked], yet there is no [Unit - Attacks]. So my question is this, what Event does the effect of a unit attack? Because, I want to create a spell which has 15% chance to trigger when a unit, with a fitting spell, attacks another unit. Thanks in advance!
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
use damage detection system. Otherwise your spell is highly abusable by right click->stop spam. Unit - Is Attacked(Attacking Unit is the one that attacks, Triggering Unit is the one that is attacked) will fire when your unit starts the attack animation. However most, if not all units have cast points, which means that the game fires your event, even tho your footman just decided to swing his sword. If I right click, stop, right click, stop, ... spam, it will break your system, cause I never trully attack your unit, yet I generated tons of Unit - Is Attacked events
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Not sure why you can't go with unit is attacked event,

  • Events
    • Unit - A unit is attacked
  • Conditions
    • Attacking unit has your spell
  • Actions
    • ---
 
Level 12
Joined
May 20, 2009
Messages
822
Hmm... I guess this Damage Detection System requires me to use JASS? I'm not really familiar with JASS, so I'm seeking some GUI solution. Is there another option?

Weep's and Bribe's systems require absolutely no knowledge of JASS. looking_for_help's system also basically requires no knowledge of JASS, but you do have to set the spell variables in the system. It explains that pretty nicely though.
 
Level 11
Joined
Nov 15, 2007
Messages
800
Damage detection is just about essential for a lot of things. While "unit is attacked" will technically work, you might as well get familiar with damage detection now and make your life a lot easier.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Be aware that the attack event fires when a unit begins attacking another unit, not when the attack is launched and especially not when the attack damage is dealt.

A common map exploit is to press "stop" a lot when attacking as if the unit has any attack animation delay it will allow you to fire the attack event at a much higher frequency than if you let the unit attack normally. The solution is to either use an attack damage detection system (a combination of attack launch tracking, timing and damage detection) to boost the proc reliability or to make the proc so meaningless that wasting opportunities to deal damage is not worth having the extra procs.
 
Level 7
Joined
Oct 13, 2008
Messages
301
The simplest way is to create a trigger, then refer to that specific trigger like this:

  • Example
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Trigger - Add to Damage Event Trigger <gen> the event (Unit - (Entering unit) Takes damage)
Now whenever a unit which is created on the map takes damage, the ''Damage Event Trigger'' Will launch. Then you can have whatever actions on that trigger, like floating text showing the exact damage dealt etc.

(The unit that took damage is referred to as ''Triggering unit''. )
 
Level 7
Joined
Oct 13, 2008
Messages
301
I guess that's not the best example. How about this:

  • Example 2
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set temp_group[1] = (Units in (Playable map area))
      • Unit Group - Pick every unit in temp_group[1] and do (Actions)
        • Loop - Actions
          • Trigger - Add to Damage Event Trigger <gen> the event (Unit - (Picked unit) Takes damage)
      • Custom script: call DestroyGroup(udg_temp_group[1])
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Each time an event is attached to a trigger a new event object is created. Sadly there is no destructor for event type objects meaning the only way to free them is to destroy the trigger they are attached to. This means that the minimum complexity for a damage detection system is an initializer, a new unit detector and some sort of trigger reconstructor.

However it still is not that easy as blindly destroying triggers attached to damage events can result in a game crash. I am not exactly sure how but a large number of crash problems have been attributed to this in the past.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
afaik you will only desync the game if you go and do TriggerSleepAction inside triggeraction, and destroy the trigger while it is sleeping, and the trigger creates agent variable.

Example:

JASS:
globals
    private trigger t = CreateTrigger()
endglobals

function a takes nothing returns nothing
    call TriggerSleepAction(0.1)
    if (GetWorldBounds() == GetWorldBounds()) then
    endif
endfunction

function b takes nothing returns nothing
    call DestroyTrigger(t)
endfunction

function InitTrig_whatever takes nothing returns nothing
    call TriggerAddAction(t, function a)
    call TimerStart(CreateTimer(), 0, false, function b)
    call TriggerExecute(t)
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
I am not referring to a desyncrhonization problem, I am referring to a application crash. People refused to explain the reason to me behind it but it is along the lines of destroying the trigger while damage events are still queued in it or running causes some very bad stuff to happen inside the application.
 
Status
Not open for further replies.
Top