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

[JASS] Checking Whether a Unit is in Combat

Status
Not open for further replies.
Level 4
Joined
Jun 8, 2007
Messages
89
Ok, so basically, I have a Barbarian hero who generates rage on every attack, and is supposed to lose rage over time, but only while he is out of combat.
I am looking for a way that I might go about detecting whether said Barbarian is in combat or not. Currently, all I have thought of is possibly checking to see if there are enemy units nearby, but this is able to be abused by standing withing range of units, but not actually attacking.

Is it possible to maybe do this with timers that reset every time the Barbarian attacks? I would think it is, but I'm relatively new to all the Jass/timer stuff and it sometimes gets a bit confusing.

Thanks in advance!
 
Level 14
Joined
Nov 18, 2007
Messages
816
Theres no direct way to say this unit is currently attacking. But you could use a trigger responding to EVENT_PLAYER_UNIT_ATTACKED and if the attacking unit has rage, start a timer for it lasting about 1 second (or the length of the attack animation) slightly longer than the attack cooldown. When a timer expires you know that unit is not attacking anymore.
 
Last edited:
Level 4
Joined
Jun 8, 2007
Messages
89
Theres no direct way to say this unit is currently attacking. But you could use a trigger responding to EVENT_PLAYER_UNIT_ATTACKED and if the attacking unit has rage, start a timer for it lasting about 1 second (or the length of the attack animation) slightly longer than the attack cooldown. When a timer expires you know that unit is not attacking anymore.

Haha, yeah I was worried someone would say that, it was giving me such a pain trying though. Thanks for the effort though. :wink:

Add a buff when a unit is attacked or being attacked. Check if unit has this buff. Of course your buff will have some duration.

Yeah, that's a great idea, I can't believe I didn't think of that...
Anyhoo, is there a way to give a unit a buff without making a dummy caster/spell that gives the buff? I've been trying to just add it by way of
JASS:
call UnitAddAbility(GetAttacker(), COMBAT_BUFF)
with COMBAT_BUFF being the integer constant 'B000', my buff's id, but it isn't working.

Thanks yet again.
 
Level 11
Joined
Apr 28, 2008
Messages
696
In my map I just restart a timer when my hero is attacked/attacks and set a boolean InFight == true. When the timer exspires I set InFight == false.
 
Level 4
Joined
Jun 8, 2007
Messages
89
In my map I just restart a timer when my hero is attacked/attacks and set a boolean InFight == true. When the timer exspires I set InFight == false.

Yeah, that's a good idea, but in this case, I have more than one active unit that requires this kind of timer (and no real way of telling how many total).

I have everything working now, thanks for the help!:wink:
 
Status
Not open for further replies.
Top