• 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] Removing Ability from unit

Status
Not open for further replies.
Level 2
Joined
Jun 15, 2012
Messages
20
ok so i have been messing around with a trigger for 3 days now and have done a lot of research on different ways of doing it and so far this seems the best way because as far as i know your not "upgrading the unit" so i am assuming the the ability effect can be taken away.
:vw_sad:
so basically the trigger grants a unit a custom "shadow orb ability" which is located under abilities>items in the object editor. but what fails to happen is after a duration of time (even if the player/unit decides not to attack back) after it gains the ability i want it to lose the "shadow orb ability" and go back to only being able to attack ground units. normally the if/then/else statement would have just been a different event trigger so i do not know if i should go back to having 2 triggers that sort of overlap each other or squish everything into one trigger like i am showing now.
:vw_wtf:
so in summary if a ground unit is attacked by a flying unit then the ground unit is permitted to retaliate but is only able to retaliate back for a short time and loses the ability to retaliate against flying units unless it is attacked again by a flying unit. my trigger adds the ability but never removes it. i have taken a ground unit and a flying unit and have them both attack each other. i have then taken the ground unit and both continued to attack/kill flying unit and had the units back off. both tests after 5 seconds show the shadow orb ablility model animation spinning around the ground unit. i have also taken that ground unit and attacked a different flying unit ,after backing off from the first one, while the different flying unit stayed stationary. five seconds after this and the unit still had the shadow orb animation spinning around the unit.
:vw_unimpressed:
sorry if i am not clear about everything and hopefully i can clear up any questions.




  • Events
    • Unit - A unit Is attacked
  • Conditions
    • ((Attacking unit) is A flying unit) Equal to True
    • ((Attacked unit) is A flying unit) Equal to False
  • Actions
    • Unit - Add Retaliation Ability FINAL? to (Attacked unit)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Attacking unit) is A ground unit) Equal to True
      • Then - Actions
        • Wait 5.00 seconds
        • Unit - Remove Retaliation Ability FINAL? from (Attacking unit)
      • Else - Actions
        • Do nothing
 
Last edited:
Level 8
Joined
Sep 7, 2008
Messages
320
ok so i have been messing around with a trigger for 3 days now and have done a lot of research on different ways of doing it and so far this seems the best way because as far as i know your not "upgrading the unit" so i am assuming the the ability effect can be taken away.
:vw_sad:
so basically the trigger grants a unit a custom "shadow orb ability" which is located under abilities>items in the object editor. but what fails to happen is after a duration of time (even if the player/unit decides not to attack back) after it gains the ability i want it to lose the "shadow orb ability" and go back to only being able to attack ground units. normally the if/then/else statement would have just been a different event trigger so i do not know if i should go back to having 2 triggers that sort of overlap each other or squish everything into one trigger like i am showing now.
:vw_wtf:
so in summary if a ground unit is attacked by a flying unit then the ground unit is permitted to retaliate but is only able to retaliate back for a short time and loses the ability to retaliate against flying units unless it is attacked again by a flying unit. my trigger adds the ability but never removes it. i have taken a ground unit and a flying unit and have them both attack each other. i have then taken the ground unit and both continued to attack/kill flying unit and had the units back off. both tests after 5 seconds show the shadow orb ablility model animation spinning around the ground unit. i have also taken that ground unit and attacked a different flying unit ,after backing off from the first one, while the different flying unit stayed stationary. five seconds after this and the unit still had the shadow orb animation spinning around the unit.
:vw_unimpressed:
sorry if i am not clear about everything and hopefully i can clear up any questions.




  • Events
    • Unit - A unit Is attacked
  • Conditions
    • ((Attacking unit) is A flying unit) Equal to True
    • ((Attacked unit) is A flying unit) Equal to False
  • Actions
    • Unit - Add Retaliation Ability FINAL? to (Attacked unit)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Attacking unit) is A ground unit) Equal to True
      • Then - Actions
        • Wait 5.00 seconds
        • Unit - Remove Retaliation Ability FINAL? from (Attacking unit)
      • Else - Actions
        • Do nothing


My eyes hurt :ogre_hurrhurr: Didnt read
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
ok so i have been messing around with a trigger for 3 days now and have done a lot of research on different ways of doing it and so far this seems the best way because as far as i know your not "upgrading the unit" so i am assuming the the ability effect can be taken away.

so basically the trigger grants a unit a custom "shadow orb ability" which is located under abilities>items in the object editor. but what fails to happen is after a duration of time (even if the player/unit decides not to attack back) after it gains the ability i want it to lose the "shadow orb ability" and go back to only being able to attack ground units. normally the if/then/else statement would have just been a different event trigger so i do not know if i should go back to having 2 triggers that sort of overlap each other or squish everything into one trigger like i am showing now.

so in summary if a ground unit is attacked by a flying unit then the ground unit is permitted to retaliate but is only able to retaliate back for a short time and loses the ability to retaliate against flying units unless it is attacked again by a flying unit. my trigger adds the ability but never removes it. i have taken a ground unit and a flying unit and have them both attack each other. i have then taken the ground unit and both continued to attack/kill flying unit and had the units back off. both tests after 5 seconds show the shadow orb ablility model animation spinning around the ground unit. i have also taken that ground unit and attacked a different flying unit ,after backing off from the first one, while the different flying unit stayed stationary. five seconds after this and the unit still had the shadow orb animation spinning around the unit.

sorry if i am not clear about everything and hopefully i can clear up any questions.

Finally, I got to read them in "Go Advanced" section.

So I skim through your trigger and was stunned for awhile;
- In your Conditions, it evaluates both (Attacking) and (Attacked) unit right ?
(Attacking) is Flying and (Attacked) is Ground.
In your next Condition, (Attacking) is Ground.

How can a unit be a flying unit and at the same time, ground unit ?
It's a contradiction.
 
Level 2
Joined
Jun 15, 2012
Messages
20
Finally, I got to read them in "Go Advanced" section.

So I skim through your trigger and was stunned for awhile;
- In your Conditions, it evaluates both (Attacking) and (Attacked) unit right ?
(Attacking) is Flying and (Attacked) is Ground.
In your next Condition, (Attacking) is Ground.

How can a unit be a flying unit and at the same time, ground unit ?
It's a contradiction.

i had figured the first conditions had to apply before you could check for the second conditions. so i was hoping that how it was being set up is when a ground is attacked by a flying and then after those conditions are true that if the ground attacking then do rest of actions. i did mention in my thread that i didnt think the formatting was right and maybe i should have two triggers instead.
so ummm thanks everyone for mentioning what i am doing wrong but does anyone unerstand what solution i might be looking for.
 
Level 14
Joined
Aug 30, 2004
Messages
909
Shadowlord, that is a very interesting idea. There are a few problems though:

1. As mentioned, the conditions aren't right, your trigger will only fire when two flying units attack each other.

2. The trigger will fire every time a flier attacks a ground unit. That means if a ground and air unit are fighting, the trigger will fire over and over again continually adding the ability, and then 5 seconds later removing it. For example, A (a ground unit) is attacking B (an air unit).
second 1 - trigger fires, giving A the orb ability
second 2 - A attacks B
second 5 - B attacks A again, firing the trigger a second time.
second 6 - first trigger done waiting, it removes the orb ability
second 8 - B attacks A again, adding the orb ability
second 10 - the second firing of the trigger ends, removing the orb...

and so on.

3. I may be wrong about this, but I'm pretty sure that "attacked unit" and "attacking unit" can be overwritten during the wait. In other words, if A attacks B the trigger will fire. If during those 5 seconds, C attacks D as well the variable "attacked unit" will now be D not B. In other words, when the first trigger is done waiting and attempts to remove the orb ability from the "attacked unit" it will actually remove it from D, not B. This is probably what's happening to you so that people keep the ability forever.

A long story short, here's what you can do:

  • Gain Air Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) is A flying unit) Equal to True
      • ((Attacked unit) is A ground unit) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Attacked unit) is in UnitGroup) Equal to False
        • Then - Actions
          • Unit Group - Add (Attacked unit) to UnitGroup
          • Unit - Add Orb of Lightning (new) to (Attacked unit)
        • Else - Actions
      • Unit - Set the custom value of (Attacked unit) to 5
  • Lose Air Attack
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in UnitGroup and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of (Picked unit)) Equal to 0
            • Then - Actions
              • Unit - Remove Orb of Lightning (new) from (Picked unit)
              • Unit Group - Remove (Picked unit) from UnitGroup
            • Else - Actions
I tested this and it works. If you're using Custom Values for some other reason then this will be a problem; but I suspect you aren't. If you want the ability to last longer or shorter change the time on the periodic trigger.

Keep in mind that the orb ability activates the second attack of the unit. So if you give it to a footman, it won't do anything. If you give it to a hero it will. you can get it to work on a footman, you just have to fill in the second attack in the object editor.
 
Level 2
Joined
Jun 15, 2012
Messages
20
hmm thanks i like this idea. i figured at some point i would use some arrays to store units but other than that i have no experience with unit groups. so i dont imagine i will use custom values just maybe some arrays. so your saying to make a unit group variable and store these units there, so should i check the box next to the array and give it the array a size? couldnt u also juss change the periodic event to say 5 seconds and then juss minus the custom value by 5 so that the trigger isnt firing off as often?
 
Level 14
Joined
Aug 30, 2004
Messages
909
hmm thanks i like this idea. i figured at some point i would use some arrays to store units but other than that i have no experience with unit groups. so i dont imagine i will use custom values just maybe some arrays. so your saying to make a unit group variable and store these units there, so should i check the box next to the array and give it the array a size? couldnt u also juss change the periodic event to say 5 seconds and then juss minus the custom value by 5 so that the trigger isnt firing off as often?

The unit groups doesn't need to be an array, just a plain unit group variable. An array of unit groups gives you many different groups...you just want 1 group.

Changing the periodic event to 5 seconds wouldn't work. Depending on when the unit is attacked, their orb ability might vanish immediately, or it might last as long as 9 seconds without being attacked.
 
Level 2
Joined
Jun 15, 2012
Messages
20
The unit groups doesn't need to be an array, just a plain unit group variable. An array of unit groups gives you many different groups...you just want 1 group.

Changing the periodic event to 5 seconds wouldn't work. Depending on when the unit is attacked, their orb ability might vanish immediately, or it might last as long as 9 seconds without being attacked.

well as far as i can tell i have duplicated your triggers except that im using my custom shadow orb ability instead of your lightning orb ability and changed the custom value to 3 instead of 5. well its not working. now it wont even grant the ability to the unit like before.
 
Level 14
Joined
Aug 30, 2004
Messages
909
well as far as i can tell i have duplicated your triggers except that im using my custom shadow orb ability instead of your lightning orb ability and changed the custom value to 3 instead of 5. well its not working. now it wont even grant the ability to the unit like before.

Can you post your triggers here to be sure? I tested the ones I posted and they worked in a new map.
 
Level 2
Joined
Jun 15, 2012
Messages
20
  • Events
    • Unit - A unit Is attacked
  • Conditions
    • ((Attacking unit) is A flying unit) Equal to True
    • ((Attacked unit) is A ground unit) Equal to True
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Attacked unit) is in UnitGroup) Equal to False
      • Then - Actions
        • Unit Group - Add (Attacked unit) to UnitGroup
        • Unit - Add Retaliation Ability FINAL? to (Attacked unit)
      • Else - Actions
        • Unit - Set the custom value of (Attacked unit) to 3
and
  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in UnitGroup and do (Actions)
      • Loop - Actions
        • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 1)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Custom value of (Picked unit)) Equal to 0
          • Then - Actions
            • Unit - Remove Retaliation Ability FINAL? from (Picked unit)
            • Unit Group - Remove (Picked unit) from UnitGroup
          • Else - Actions
its probably something stupid but as far as i can tell its set up correctly.
 
Level 5
Joined
Sep 28, 2010
Messages
75
Try this
  • Events
    • Unit - A unit is attacked
  • Conditions
    • ((Attacking unit) is A flying unit) Equal to True
    • ((Triggering Unit) is A ground unit) Equal to True
  • Actions
    • Custom script: if UnitAddAbility(GetTriggerUnit(), 'XXXX') then
    • Wait 5.00 seconds
    • Unit - Remove Retaliation Ability FINAL? from (Triggering Unit)
    • Custom script: endif
XXXX is to be replaced with raw code of your Retaliation Ability FINAL?.
In case you don't know how to find the raw code of your ability, here are the instructions:

-In your Object editor, press on your keyboard Ctrl + D. The name of units / items / abilities / buffs etc will change into "weird" codes.
-Go to your ability. Replace XXXX with the 4-digit code you see in your ability name. (for example, A002)
-When replacing XXXX with the code, make sure to include ' ' too. (e.g. 'A002')
 
Level 2
Joined
Jun 15, 2012
Messages
20
Try this
  • Events
    • Unit - A unit is attacked
  • Conditions
    • ((Attacking unit) is A flying unit) Equal to True
    • ((Triggering Unit) is A ground unit) Equal to True
  • Actions
    • Custom script: if UnitAddAbility(GetTriggerUnit(), 'XXXX') then
    • Wait 5.00 seconds
    • Unit - Remove Retaliation Ability FINAL? from (Triggering Unit)
    • Custom script: endif
XXXX is to be replaced with raw code of your Retaliation Ability FINAL?.
In case you don't know how to find the raw code of your ability, here are the instructions:

-In your Object editor, press on your keyboard Ctrl + D. The name of units / items / abilities / buffs etc will change into "weird" codes.
-Go to your ability. Replace XXXX with the 4-digit code you see in your ability name. (for example, A002)
-When replacing XXXX with the code, make sure to include ' ' too. (e.g. 'A002')

umm its not working :/
and now all my custom made stuff is like TGRSTR_012 ect. so i guess i have to rename them?

  • Events
    • Unit - A unit Is attacked
  • Conditions
    • ((Attacked unit) is A ground unit) Equal to True
    • ((Attacking unit) is A flying unit) Equal to True
  • Actions
    • Custom script: if UnitAddAbility(GetTriggerUnit(), 'A001') then
    • Wait 3.00 seconds
    • Unit - Remove Retaliation Final? from (Attacked unit)
    • Custom script: endif
i thought changing it to (Attacked Unit) would help but it didnt...also in the script should it be GetAttackedUnit? idk what to do
 
Level 2
Joined
Jun 15, 2012
Messages
20
k well regardless it didnt worked and only thing accomplished is all my inputed text such as the name of my units are changed to things like TRIGSTR_012 :|
 
Level 2
Joined
Jun 15, 2012
Messages
20
If the event is Attacked Unit then Triggering unit is refering to the same unit. However you have to use attacking unit for the attacker :)

ok well regardless, neither triggering or attacking work in this case. all this trigger did was change my text data for all my units...the first trigger i was being helped with was more of what i was looking for but he stopped helping me. idk what to do and without this trigger my map will be very unbalanced. :pcry:
 
Level 5
Joined
Sep 28, 2010
Messages
75
If it didn't work, let's try using local variables instead to store the data of (Triggering Unit) and (Attacking Unit).

  • Events
    • Unit - A unit Is attacked
  • Conditions
    • ((Triggering Unit) is A ground unit) Equal to True
    • ((Attacking Unit) is A flying unit) Equal to True
  • Actions
    • Custom script: local unit victim = GetTriggerUnit()
    • Custom script: if UnitAddAbility(victim, 'A001') then
    • Wait 3.00 seconds
    • Custom script: call UnitRemoveAbility(victim, 'A001')
    • Custom script: endif
    • Custom script: set victim = null
Using (Triggering Unit) is more efficient.

There is another possible reason for your problem.
I don't know how the system detects a unit as "Ground" or "Flying". Maybe it is detected by the Movement Type of the unit?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I don't know how the system detects a unit as "Ground" or "Flying". Maybe it is detected by the Movement Type of the unit?
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Triggering unit) is A ground unit) Equal to True
    • Then - Actions
      • Game - Display to (All players) the text: GROUND UNIT
    • Else - Actions
      • Game - Display to (All players) the text: FLYING UNIT
 
Level 2
Joined
Jun 15, 2012
Messages
20
If it didn't work, let's try using local variables instead to store the data of (Triggering Unit) and (Attacking Unit).

  • Events
    • Unit - A unit Is attacked
  • Conditions
    • ((Triggering Unit) is A ground unit) Equal to True
    • ((Attacking Unit) is A flying unit) Equal to True
  • Actions
    • Custom script: local unit victim = GetTriggerUnit()
    • Custom script: if UnitAddAbility(victim, 'A001') then
    • Wait 3.00 seconds
    • Custom script: call UnitRemoveAbility(victim, 'A001')
    • Custom script: endif
    • Custom script: set victim = null
Using (Triggering Unit) is more efficient.

There is another possible reason for your problem.
I don't know how the system detects a unit as "Ground" or "Flying". Maybe it is detected by the Movement Type of the unit?

lol o great more custom script. alright well i will give it a try
 
Level 2
Joined
Jun 15, 2012
Messages
20
has anyone tried testing these triggers out on maps? cuz at this point i must be doing something very wrong with the data if by the 3rd or more trigger nothing is working. i know for sure the second combat data is filled out for the unit i am testing.
 
Level 2
Joined
Jun 15, 2012
Messages
20
for the newest one try changing the A001 to the rawcode of your ability
for finding raw code of ability go to object editor, abilitez press CTRL+D and find the ability you want to add to the unit

i did do that and thats where i got the A001 from and also is what changed the text i have entered, such as unit names and descriptions, to text like TRIGSTR_012
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Do not rely on thread suspension for this kind of task.

Have 2 parts to the system.

Part 1 adds the ability to the unit.
Part 2 removes the ability after 5 seconds from it being attacked.

A good idea would be to start a timer that gets refreshed every time the unit is attacked. If the timer expires you then remove the ability.

Unit is attacked
If no timer for unit then add ability and make timer for unit.
Else refresh duration of timer for unit.

A timer for a unit expires
Remove ability from unit and free timer resources.
 
Level 2
Joined
Jun 15, 2012
Messages
20
Do not rely on thread suspension for this kind of task.

Have 2 parts to the system.

Part 1 adds the ability to the unit.
Part 2 removes the ability after 5 seconds from it being attacked.

A good idea would be to start a timer that gets refreshed every time the unit is attacked. If the timer expires you then remove the ability.

Unit is attacked
If no timer for unit then add ability and make timer for unit.
Else refresh duration of timer for unit.

A timer for a unit expires
Remove ability from unit and free timer resources.

where do i find "if no timer for unit then add ability...for unit." in condition? boolean comparison? unit comparison? or a specific comparison for timers?
 
Last edited:
Level 2
Joined
Jun 15, 2012
Messages
20
ok so i wanted to check and see if there was something wrong with the conditions so i made a trigger

Event
Unit is Attacked
Condition
Triggering Unit is a Ground Unit Equal to False
Action
Display to All Players: GROUND UNIT

so when my flyer attacks my so called ground unit it displays this message. so i am assuming that means that my map doesnt consider the unit a ground unit. i checked the data for the unit and the box is checked for ground under its classification. so what would cause this unit not to be considered a ground unit?
 
Level 2
Joined
Jun 15, 2012
Messages
20
You are checking if the unit is not a ground unit and display "GROUND UNIT" if that is the case. So an air unit will show "GROUND UNIT" but a ground unit will not. Your condition is inverted.

point was to juss display a message when a ground unit was attacked...well the flying unit attacks the ground unit thus the ground unit being the attacked unit. so i have the condition so it displays when it isnt a ground unit that has been attacked.
so it displays the message when the ground unit is attacked when it shouldnt display anything at all
 
Status
Not open for further replies.
Top