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

cChange of ownership of units

Status
Not open for further replies.
Level 2
Joined
Jan 18, 2024
Messages
2
Hello, I've been trying to figure it out myself for a long time, but I can't. I have a problem with one trigger.
The principle is that after the HP of the Town hall unit drops to 100 HP, all buildings in the vicinity, including the Town hall, become owners of attacking units.
I want only these buildings to change ownership and not the other units around the Town hall.
Thank you very much for any advice, I really don't know anymore.

IMG_20240118_175501_edit_544860634237171.jpg
IMG_20240118_175448_edit_544879973191334.jpg
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,876
Hello, I appreciate the photos taken with your phone, that takes me back :p

But here's how you can post your triggers to Hive:

Anyway, you're making a few major mistakes in your triggers.

1) The whole turn off/turn on mechanic doesn't really make sense. When the Town Hall is attacked with <= 100 hp you should simply run all of the actions right then and there. There's no need for the Untitled Trigger 003 trigger (please name these to something that makes sense, lol). Also, you're turning on Untitled Trigger 003, which means that the Town Hall will need to get attacked AGAIN for the ownership changes to take place.

2) "A unit is attacked" is not a reliable way to detect life loss since it occurs at the start of an attack and well before any damage was dealt. For example, a Catapult's missile colliding with the town hall happens a good 2 seconds after the "attacK" was made. Even worse, if the Catapult is using the Attack Ground ability then it'll NEVER fire the event. In your case it's possible to actually kill the Town Hall before the changing/healing occurs. Instead, you should use the Event "A unit takes damage".

3) For your ownership changing logic you should filter your Unit Group to only modify structures. This can be done with an If Then Else action or by using the (Matching) function -> Pick every unit in range matching...

4) Removing all Gryphon Riders while looping inside of the Unit Group doesn't make sense. You should never be referencing (Last created unit group) while running through that very same Unit Group. Plus we can simply filter out non-buildings (#3).

Here's how you can clean it up and get it working nicely:
  • Town Hall Ownership Changes
    • Events
      • Unit - A unit Takes damage
    • Conditions
      • (Unit-type of (Damage Target)) Equal to Town Hall
    • Actions
      • -------- (Damage Target) is the Unit that took the damage. --------
      • -------- (Damage source) is the Unit that dealt the damage. --------
      • -------- --------
      • Set VariableSet OS_Town_Hall = (Damage Target)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Life of OS_Town_Hall) - (Damage taken)) Less than or equal to 100.00
        • Then - Actions
          • -------- Set the damage dealt to 0 since we're now fully healing the buildings: --------
          • Event Response - Set Damage of Unit Damaged Event to 0.00
          • -------- --------
          • -------- Keep track of the old owner of the Town Hall and it's new owner: --------
          • Set VariableSet OS_Old_Player = (Owner of OS_Town_Hall)
          • Set VariableSet OS_New_Player = (Owner of (Damage source))
          • -------- --------
          • -------- Track the units near the town hall: --------
          • Set VariableSet OS_Point = (Position of OS_Town_Hall)
          • Set VariableSet OS_Group = (Units within 1000.00 of OS_Point.)
          • -------- --------
          • -------- Change ownership of all nearby buildings: --------
          • Unit Group - Pick every unit in OS_Group and do (Actions)
            • Loop - Actions
              • Set VariableSet OS_Nearby_Unit = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (OS_Nearby_Unit is A structure) Equal to True
                  • (OS_Nearby_Unit belongs to an ally of OS_Old_Player.) Equal to True
                  • (OS_Nearby_Unit is alive) Equal to True
                • Then - Actions
                  • Unit - Change ownership of OS_Nearby_Unit to OS_New_Player and Change color
                  • Unit - Set life of OS_Nearby_Unit to 100.00%
                  • Unit - Make OS_Nearby_Unit Vulnerable
                • Else - Actions
          • -------- --------
          • -------- Clean up the memory leaks (helps keep the map running smooth over time): --------
          • Custom script: call RemoveLocation( udg_OS_Point )
          • Custom script: call DestroyGroup( udg_OS_Group )
        • Else - Actions
My usage of variables ensures that everything runs efficiently and without bugs.

Note that this trigger setup is only possible on patch 1.31+. On older versions you can rely on a Damage Engine. Also, the map was saved on version 1.36, which you'll need to be on to open it.
 

Attachments

  • Change Ownership 1.w3m
    18.8 KB · Views: 4
Last edited:
Level 2
Joined
Jan 18, 2024
Messages
2
Thank you very much for the advice. I suspected that I was doing it very inefficiently, but it was the only thing I could think of and it partially worked. I'm not the best at English, and sometimes I miss some meanings. Even with logical thinking, I'm probably not as good as I thought. 😃
I didn't have the names because it was a test trigger. Otherwise, I describe them all to keep things in order.
Anyway, thank you, from the principle you showed me, I take lessons and a different insight into how to make triggers and different conditions.
 
Status
Not open for further replies.
Top