• 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] Detect unit switched it's target or unit with no target

Status
Not open for further replies.
Level 7
Joined
Jun 1, 2009
Messages
125
My goal is to create ability, that increases attack speed with every hit.
But if unit stop attacks for like 2 sec. this attack speed buff falls off (I'm sure this one IS possible, cause I saw it in other maps).

Also I want to create similar ability, but make it's buff reset when unit changes it's target (not sure it even possible at all).

Creating buff was simple:

  • Unit Attacked
    • Events
      • Unit - A unit owned by Player 12 (Brown) Is attacked
    • Conditions
    • Actions
      • -------- Miniguns --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Attacking unit)) Equal to Minigun
        • Then - Actions
          • If ((Level of Minigun barrels for (Attacking unit)) Less than 20) then do (Unit - Increase level of Minigun barrels for (Attacking unit)) else do (Do nothing)
        • Else - Actions
          • Do nothing
But when I'm trying to reset it's level - it fails

  • Loop Units
    • Events
      • Time - Loop_Timer expires
    • Conditions
    • Actions
      • -------- Miniguns --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Minigun) and do (Actions)
        • Loop - Actions
          • If ((Current order of (Picked unit)) Equal to (Order(stop))) then do (Unit - Set level of Minigun barrels for (Picked unit) to 1) else do (Do nothing)
Would be apreciate for help!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Also I want to create similar ability, but make it's buff reset when unit changes it's target (not sure it even possible at all).
There is an event for a specific unit acquires a target. One may be able to work with that to achieve what you want.

Otherwise the safe approach is to test if the new attacked unit is the same as the last one using a standard unit is attacked event.
But when I'm trying to reset it's level - it fails
Did you try starting the timer?

The problem I see is that units which are moving are not considered stopped so players could abuse that approach. A better approach would be to restart a timer every time the unit attacks. If the timer expires then the unit has not attacked for the timeout period and the attack speed buff can be reset/removed.

Since managing timers can be difficult in GUI, another way to implement it is using an array of counters which count down periodically. When the unit attacks the index representing that unit is reset to the appropriate timeout value. When the counter reaches 0 the attack speed buff can be reset/removed. This is slightly less efficient than the timer approach but does not require as much custom scripting.
 
Level 7
Joined
Jun 1, 2009
Messages
125
There is an event for a specific unit acquires a target.
I can't attach it to Unit variable. And units are not placed in map by default.

The problem I see is that units which are moving are not considered stopped.
It is a building, so it ain't moving.

Did you try starting the timer?
I'm trying to avoid them and find less resource-consuming solution. I fear that 100 units with like 0,3 attack rate can cause hard lags with timers attached, and we speaking just for 1 unit-type!

But if nothing left, ill try variable arrays.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
I can't attach it to Unit variable. And units are not placed in map by default.
You can create the event whenever the units are created. There is an action to do so.

Be aware that removing the unit will not destroy the event. Events only get destroyed when their trigger gets destroyed. This can be a potential leak if not used carefully.
I'm trying to avoid them and find less resource-consuming solution.
If the timer is never started the trigger cannot function.
 
Level 7
Joined
Jun 1, 2009
Messages
125
There is an action to do so.
Oh, it seems you're talking about
  • Trigger - Add to (This trigger) the event (Unit - Minigun[Int] Acquires a target)
Got no idea that it can add specific unit events. Thanks alot!


If the timer is never started the trigger cannot function.

Yup, but what if every player got 10-15 of such units?
 
Last edited:
Status
Not open for further replies.
Top