• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Trigger] Unit Attacks Event?

Status
Not open for further replies.
Level 7
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!
 
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
 
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
    • ---
 
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.
 
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.
 
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.
 
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''. )
 
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])
 
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.
 
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
 
Status
Not open for further replies.
Back
Top