• 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 Event for 'Any' Unit?

Status
Not open for further replies.
Level 1
Joined
Jun 20, 2016
Messages
5
Hey,

So I wanted to make this trigger that makes one of my costum unit die once it reaches 100/100 mana, and spawn another in it's place.

I want to have this effect to a specific -type- of unit, not a specific -one-

upload_2019-5-2_23-26-8.png


So I could select a single Acolyte on my map, but that makes that specific acolyte have the effect. Can anyone help me with this?
 

Attachments

  • upload_2019-5-2_23-24-34.png
    upload_2019-5-2_23-24-34.png
    8.5 KB · Views: 20
Level 45
Joined
Feb 27, 2007
Messages
5,578
That particular even doesn't have a generic 'any unit' version. You can instead add all units of that type to a group and periodically check the mana of units in that group. You will need three triggers:
  • Events
    • Unit - A unit enters (playable map area)
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to Acolyte
  • Actions
    • Unit Group - Add (Triggering Unit) to AcolyteGroup
  • Events
    • Unit - A unit dies
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to Acolyte
  • Actions
    • Unit Group - Remove (Triggering Unit) from AcolyteGroup
  • Events
    • Time - Every 0.50 seconds of game-time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in (AcolyteGroup) and do (Actions)
      • Loop - Actions
        • Set TempUnit = (Picked unit)
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Percentage Mana of TempUnit) greater than or equal to 100.00
          • Then - Actions
            • Set TempPoint = (Position of TempUnit)
            • Unit - Kill TempUnit
            • Unit - Create 1 Mana Anomaly for (Owner of TempUnit) at TempPoint facing (Default building facing degrees)
            • Custom script: call RemoveLocation(udg_TempPoint) //change the variable name to match yours but keep the udg_ prefix
 
Level 1
Joined
Jun 20, 2016
Messages
5
That particular even doesn't have a generic 'any unit' version. You can instead add all units of that type to a group and periodically check the mana of units in that group. You will need three triggers:
  • Events
    • Unit - A unit enters (playable map area)
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to Acolyte
  • Actions
    • Unit Group - Add (Triggering Unit) to AcolyteGroup
  • Events
    • Unit - A unit dies
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to Acolyte
  • Actions
    • Unit Group - Remove (Triggering Unit) from AcolyteGroup
  • Events
    • Time - Every 0.50 seconds of game-time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in (AcolyteGroup) and do (Actions)
      • Loop - Actions
        • Set TempUnit = (Picked unit)
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Percentage Mana of TempUnit) greater than or equal to 100.00
          • Then - Actions
            • Set TempPoint = (Position of TempUnit)
            • Unit - Kill TempUnit
            • Unit - Create 1 Mana Anomaly for (Owner of TempUnit) at TempPoint facing (Default building facing degrees)
            • Custom script: call RemoveLocation(udg_TempPoint) //change the variable name to match yours but keep the udg_ prefix

Thank you for the help, I need to get my head around the third trigger 'tho. I don't really understand the variables, and I can't seem to find the option of the condition there to check for mana percentage for some reason.

Sorry I'm just trying to get into this stuff. :$
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
The TempUnit variable is not explicitly necessary, I just put it in there to slightly reduce the number of function calls relative to just using "Picked Unit" in each case. TempPoint is to remove the point leak that would otherwise happen when creating the Mana Anomaly. If you have no idea what a leak is, read this: Things That Leak

That particular condition is a "Real comparison". You can always see what type of comparison you should be looking under by seeing what kind of object comes after the "greater/less/equal to" bit; in this case it's 100.00 which is a real, so it's a real comparison. Once you have chosen that comparison it should be listed as "Unit - Percentage Mana".
 
Level 1
Joined
Jun 20, 2016
Messages
5
The TempUnit variable is not explicitly necessary, I just put it in there to slightly reduce the number of function calls relative to just using "Picked Unit" in each case. TempPoint is to remove the point leak that would otherwise happen when creating the Mana Anomaly. If you have no idea what a leak is, read this: Things That Leak

That particular condition is a "Real comparison". You can always see what type of comparison you should be looking under by seeing what kind of object comes after the "greater/less/equal to" bit; in this case it's 100.00 which is a real, so it's a real comparison. Once you have chosen that comparison it should be listed as "Unit - Percentage Mana".

Right, I'm making some progress. I did everything like you did in your example, with the variables end everything. That didn't seem to do anything.

However I tryed handling the Unit Groups this way;

Code:
Unit Group - Add (Triggering unit) to (Units of type Acolyte)

Code:
Unit Group - Remove (Triggering unit) from (Units of type Acolyte)

This makes the Acolyte die when it reaches 100% mana, and spawn a Mana Anomaly in it's place, but the process replicated itself, creating infinite amount of Mana Anomalies.

It just seems weird to me how I completely copied your example, and nothing happened, even 'tho now that I look at it, it makes complete sence.

PS; It would be nice to figure out how to make those trigger links hehe.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
How To Post Your Trigger

I can tell you why it didn't work when you post yours ^^. You don't have to use a DestroyGroup on that AcolyteGroup variable because it should exist forever, which is one thing that could cause it to not work. I totally forgot about the "Units of type Acolyte" option, so you could reduce it to one periodic trigger if you use that. Basically that gives you a group of that type of unit, then you have to do something with them; this is why the "pick" action is usually going to be used. You can add and remove units to/from that group but every time you get "units of type..." it will be a new group. That's also a simple illustration of why groups need to be destroyed (cleaned).

Anyway, what I'm trying to suggest you avoid is doing "Units in (Playable Map Area) matching ((Unit type of (Matching Unit)) equal to Acolyte)" because many of those types of checks in large maps will noticeably affect map performance. My initial method is still superior but you can:

  • Events
    • Time - Every 0.50 seconds of game-time
  • Conditions
  • Actions
    • Set TempGroup = (Units of type Acolyte)
    • Unit Group - Pick every unit in TempGroup and do (Actions)
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • (Percentage Mana of (Picked Unit)) greater than or equal to 100.00
        • Then - Actions
          • Set TempPoint = (Position of (Picked Unit))
          • Unit - Kill (Picked Unit)
          • Unit - Create 1 Mana Anomaly for (Owner of (Picked Unit)) at TempPoint facing (Default building facing degrees)
          • Custom script: call RemoveLocation(udg_TempPoint)
    • Custom script: call DestroyGroup(udg_TempGroup)
I suggest using these simple temp variables for each type when you don't really need to store data for too long, just enough to clean up. That way you don't have like +6 variables per trigger, ya know?
 
Level 1
Joined
Jun 20, 2016
Messages
5
How To Post Your Trigger

I can tell you why it didn't work when you post yours ^^. You don't have to use a DestroyGroup on that AcolyteGroup variable because it should exist forever, which is one thing that could cause it to not work. I totally forgot about the "Units of type Acolyte" option, so you could reduce it to one periodic trigger if you use that. Basically that gives you a group of that type of unit, then you have to do something with them; this is why the "pick" action is usually going to be used. You can add and remove units to/from that group but every time you get "units of type..." it will be a new group. That's also a simple illustration of why groups need to be destroyed (cleaned).

Anyway, what I'm trying to suggest you avoid is doing "Units in (Playable Map Area) matching ((Unit type of (Matching Unit)) equal to Acolyte)" because many of those types of checks in large maps will noticeably affect map performance. My initial method is still superior but you can:

  • Events
    • Time - Every 0.50 seconds of game-time
  • Conditions
  • Actions
    • Set TempGroup = (Units of type Acolyte)
    • Unit Group - Pick every unit in TempGroup and do (Actions)
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • (Percentage Mana of (Picked Unit)) greater than or equal to 100.00
        • Then - Actions
          • Set TempPoint = (Position of (Picked Unit))
          • Unit - Kill (Picked Unit)
          • Unit - Create 1 Mana Anomaly for (Owner of (Picked Unit)) at TempPoint facing (Default building facing degrees)
          • Custom script: call RemoveLocation(udg_TempPoint)
    • Custom script: call DestroyGroup(udg_TempGroup)
I suggest using these simple temp variables for each type when you don't really need to store data for too long, just enough to clean up. That way you don't have like +6 variables per trigger, ya know?

Right, so for some reason, I couldn't make your suggestions work which is very weird. However, I simplified them, which is quite against what you suggested, but it still kind of works.

  • Acolyte3 Copy
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Acolyte) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Percentage mana of (Picked unit)) Greater than or equal to 100.00
            • Then - Actions
              • Unit - Kill (Picked unit)
              • Unit - Create 1 Mana Anomaly for (Owner of (Picked unit)) at (Position of (Picked unit)) facing Default building facing degrees
            • Else - Actions
However, this one makes the unit spawn infnite amount of times, just like it did before. The last line just keep repeating itself for some reason.
I tryed mending this issue with another trigger;

  • Acolyte 4
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Acolyte
    • Actions
      • If ((Unit-type of (Triggering unit)) Equal to Acolyte) then do (Unit - Create 1 Mana Anomaly for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees) else do (Do nothing)
      • Unit - Create 1 Mana Anomaly for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees

This kind of works, however this makes the unit spawn the Mana Anomaly regardless how the Acolyte dies, which is not what I'm looking for. I only want it to spawn the unit when it dies because of mana loss.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Right, so for some reason, I couldn't make your suggestions work which is very weird.
What part specifically could you not accomplish? It seems you did everything except clean the leaks.

The problem is that it's picking all the dead acolytes that have 100% mana too. Add the below condition to the if-block in Acolyte3 Copy. It should be a boolean comparison. If you can't find it you could also check that the unit's life is > 0.405 (units die at 0.405 life, not at 0 life, it's a game engine quirk).
  • ((Picked unit) is alive) equal to true
You're still leaking a point (Position of Picked Unit) and a group (Units of type Acolyte). You can clean the group with the bj_wantDestroy trick as illustrated in the leaks tutorial I linked before.
  • Acolyte3 Copy
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Acolyte) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Percentage mana of (Picked unit)) Greater than or equal to 100.00
              • ((Picked unit) is alive) equal to true
            • Then - Actions
              • Unit - Kill (Picked unit)
              • Set TempPoint = (Position of (Picked Unit))
              • Unit - Create 1 Mana Anomaly for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_TempPoint)
            • Else - Actions
 
Level 1
Joined
Jun 20, 2016
Messages
5
What part specifically could you not accomplish? It seems you did everything except clean the leaks.

The problem is that it's picking all the dead acolytes that have 100% mana too. Add the below condition to the if-block in Acolyte3 Copy. It should be a boolean comparison. If you can't find it you could also check that the unit's life is > 0.405 (units die at 0.405 life, not at 0 life, it's a game engine quirk).
  • ((Picked unit) is alive) equal to true
You're still leaking a point (Position of Picked Unit) and a group (Units of type Acolyte). You can clean the group with the bj_wantDestroy trick as illustrated in the leaks tutorial I linked before.
  • Acolyte3 Copy
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Acolyte) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Percentage mana of (Picked unit)) Greater than or equal to 100.00
              • ((Picked unit) is alive) equal to true
            • Then - Actions
              • Unit - Kill (Picked unit)
              • Set TempPoint = (Position of (Picked Unit))
              • Unit - Create 1 Mana Anomaly for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_TempPoint)
            • Else - Actions

Wow. I never thought of that. Works like a charm now. Thank you very much. I'm not sure what I did wrong the first time, but the first few suggesitons you wrote finally worked once I added the Unit is Alive condition.
Thank you very much for the help mate, I really appreciate it. I learned quite a lot of stuff from this. Hope I can count on your again if I hit a wall while I work on my small project. ^^
 
Status
Not open for further replies.
Top