• 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.

Problems with the 'Unit - A unit is attacked' Event?

Status
Not open for further replies.
Level 4
Joined
Jun 5, 2007
Messages
65
So I've done a bit of research and experimentation with this event and have come up with three conclusions:

A) This event is fired the second the 'Attacking Unit' is ordered to attack the 'Attacked Unit'.

B) This event is fired the second the 'Attacking Unit' comes within the set range of the 'Attacked Unit'.

C) This event is fired the second the 'Attacked Unit' begins to start the attack animation.

(I believe that C is probably the correct one, but I've uncluded the others just in case.)

Problems with this:

Basically, the problem with this event is that it doesn't fire when a unit takes damage, (yes, I know there is an event for that, but it does ONLY works for specific units - that can get annoying since you have to pre-specify a unit right then and there), and that it's virtually impossible to use in conjunction with a ranged hero.

Basically, I would like some clarification on my 3 conclusions, and also would like to know if theres a better way to do this. Thank you very much.
-Z
 
Level 7
Joined
Jun 10, 2007
Messages
225
This is a known problem, and the reason why there are AttackDetect engines (theres several over at wc3c, but the site is down right now.
Attack detect engines basically allow you to detect when the missile of a unit hits or the damage is dealt.
 
Level 9
Joined
Jul 27, 2006
Messages
652
Hmmm, heres something to play with.
You may remember the "orb of lightning" item has a chance to cast the ability purge on a unit when attacked. The ability is only activated when the unit actualy takes damage ( see what im getting at :wink: ).
So what do you do? Create a dummy defult ability based on a target ability ( i suggest frost nova ) and then make the ability used in the "orb of lightning" item.
Set the ability that is cast to your dummy ability and the chance to 100%.
Then create and initilization trigger that disables the one of the two abilities so that the dummy ability is hidden but still active ( you might have to try both ).
What do you have now? A targeting ability that activates each attack and is hidden.
I have not tested any of this, I'll fiddle around with it tomorrow, at the moment its just a simple idea that might just work :smile:
If it does work I'll post my findings ASAP.
 
Level 4
Joined
Jun 5, 2007
Messages
65
Kixer that works great except for the small problem that the ability I'm trying to use is a trigger-created one, so it would be nearly impossible to get it to work. Thanks though.
 
Level 9
Joined
Jul 27, 2006
Messages
652
Well it seem simple in theory to me, you just set your event to "Unit starts the effect of an ability" and the conditions to "Ability being cast = "Your dummy attack ability" " and "Level of ability "your actual ability" is greater than 0.
 
Level 6
Joined
Apr 16, 2007
Messages
177
Huh? Why that difficult?
Simply use
  • Addall
  • E:Map initialization
  • A:
  • Pick every unit in playable map area and do
    • Trigger - Add event to takedmg: picked unit is dealt damage
  • Addnew
  • E: A unit enters playable map area
  • A:
  • Trigger - Add event to takedmg: entering unit is dealt damage
  • Takedmg
  • E:none
  • A: <your actions here>
 
Level 9
Joined
Jul 27, 2006
Messages
652
Serra,
that leaks more than you could ever imagine, it slows down the game and creates unessisary lag.
Well i spent the afternoon playing around with my theory and came back with depressing results, it appears that there is no way to track the dummy attack ability :sad:
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
The magical Any Unit Takes Damage system, by Shadow1500 (needs CSCache)

The function AnyUnitTakesDamage is run whenever damage is dealt.

Now, just add an if-statement to check for a dummy slow poison buff, and if it's there, remove it, and treat the damage like it was dealt by an attack. Add the slow poison ability to each unit, hidden in a dummy spellbook.

Useful Functions:

GetTriggerUnit: in this case, the damaged unit
GetEventDamageSource: the damaging unit
GetEventDamage: the damage dealt
 
Level 6
Joined
Apr 16, 2007
Messages
177
Serra,
that leaks more than you could ever imagine, it slows down the game and creates unessisary lag.
Well i spent the afternoon playing around with my theory and came back with depressing results, it appears that there is no way to track the dummy attack ability :sad:

The code has only one leak, wich occurs at map init and isn't bad cuz it only occurs once.
Or do you simply do name dropping (you don't know what the correct definition of "leak" is, but to sound kewl and make my triggers bad you say it ?)

Apart from this very light memory leak (wich can be repaired easily), it should not slow the game or lag.
Greets Serra

EDIT:
I've looked into your magical thingie and have seen that it is almost exactly that what I've done.
Just his code has some leaks. You should be VERY glad that JASS doesn't have any garbage collector, else nothing of his code would work.
Greetings Serra.
 
Level 9
Joined
Jul 27, 2006
Messages
652
Serra,
I may not know everything about leaks but Im pretty sure that "Pick every unit - " leaks ALOT when not using a predeclared variable.
It also slowing the game ( and the actual trigger ) down because the event for a dead unit is still attached to the trigger, meaning its simply taking up memory.
And I apologise for forgeting the most important reason why those triggers should not be used, its not what Zoraykos asked for. He/she asked for a way to detect when a unit is attacked, not when he simply takes damage.
Im also sorry that you think I was trying to make you and your trigger(s) look bad, its just that there are much better ways out there.
 
Level 2
Joined
Jun 22, 2007
Messages
10
The major problem is that it sucks. If you want realistic on-hit abilities, use orb effects or an attack detection system.
 
Status
Not open for further replies.
Top