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

[Solved] Adding "damage" effect to buildings.

Status
Not open for further replies.
I'm experimenting with these two triggers to add effects to damaged structures. Currently they work by abusing a disabled spell book with an aura ability. The issue is that the removal trigger only accounts for if the building is targeted when above 50%, not if the repairs start below 50% - so it will stay forever if it is repaired starting under 50%. How can I deal with this? Test map is attached.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Issued order) Equal to (Order(repair))
      • ((Target unit of issued order) is A structure) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of (Target unit of issued order)) Greater than or equal to (((Max life of (Target unit of issued order)) / 100.00) x 50.00)
          • Or - Any (Conditions) are true
            • Conditions
              • (Level of Spell Book (Lost Damage Burn Small) for (Target unit of issued order)) Greater than 0
        • Then - Actions
          • Unit - Remove Spell Book (Lost Damage Burn Small) from (Target unit of issued order)
        • Else - Actions
  • Untitled Trigger 001 Copy
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Life of (Target unit of issued order)) Less than or equal to (((Max life of (Target unit of issued order)) / 100.00) x 50.00)
          • (Level of Spell Book (Lost Damage Burn Small) for (Target unit of issued order)) Equal to 0
        • Then - Actions
          • Unit - Add Spell Book (Lost Damage Burn Small) to (Triggering unit)
        • Else - Actions
 

Attachments

  • feffewfwf.w3x
    17.6 KB · Views: 77
Level 37
Joined
Mar 6, 2006
Messages
9,243
You can periodically check the building's life.

Or

  • Untitled Trigger 014
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A structure) Equal to True)) and do (Actions)
        • Loop - Actions
          • Trigger - Add to Trigger 1 <gen> the event (Unit - (Picked unit)'s life becomes Less than ((Max life of (Picked unit)) / 2.00))
          • Trigger - Add to Trigger 2 <gen> the event (Unit - (Picked unit)'s life becomes Greater than ((Max life of (Picked unit)) / 2.00))
Add events for constructed units also.

This leaks events when units die, but it doesn't matter much unless you have tons of buildings.

If you want to avoid that then create own triggers (create with a trigger, not manually) for each unit, and destroy the trigger when building dies.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
A 1 second timer would be ok. When a unit is ordered to repair a building, add the building into a group. Loop through the group periodically. If a unit's health is above x%, remove it from the group and remove the effect.

With the other method, use a unit indexing system, like Bribe's unit indexer. Create a trigger array. When a building is constructed, create a trigger in the array. Use custom value of the constructed building as the index. Register the life < 50% event for the trigger. Create another trigger array, do the same, but use life >50% event.

As the action portion, register some function for the triggers.

You also need to pick all existing units at the beginning of the map and create triggers for them.

When a building dies, destroy the unit's triggers.

  • CustomScript: set udg_TriggerArray1[GetUnitUserData(*unit*) = CreateTrigger()]
  • CustomScript: call DestroyTrigger(udg_TriggerArray1[GetUnitUserData(*unit*)])
 
I ended up using the below trigger. Is there a way to add a condition stating that the units be constructed and not constructing?

  • Lost Damage Effect Timer
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Lost_Building_Check_Group = (Units in (Playable map area) matching ((((Matching unit) is A structure) Equal to True) and ((Race of (Owner of (Matching unit))) Equal to Human)))
      • Unit Group - Pick every unit in Lost_Building_Check_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than or equal to (((Max life of (Picked unit)) / 100.00) x 76.00)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Small) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Small) from (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Medium) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Medium) from (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Large) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Large) from (Picked unit)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than or equal to (((Max life of (Picked unit)) / 100.00) x 51.00)
              • (Life of (Picked unit)) Less than (((Max life of (Picked unit)) / 100.00) x 76.00)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Small) for (Picked unit)) Less than 1
                • Then - Actions
                  • Unit - Add Spell Book (Lost Damage Burn Small) to (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Medium) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Medium) from (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Large) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Large) from (Picked unit)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than or equal to (((Max life of (Picked unit)) / 100.00) x 26.00)
              • (Life of (Picked unit)) Less than (((Max life of (Picked unit)) / 100.00) x 51.00)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Small) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Small) from (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Medium) for (Picked unit)) Less than 1
                • Then - Actions
                  • Unit - Add Spell Book (Lost Damage Burn Medium) to (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Large) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Large) from (Picked unit)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than (((Max life of (Picked unit)) / 100.00) x 0.00)
              • (Life of (Picked unit)) Less than (((Max life of (Picked unit)) / 100.00) x 26.00)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Small) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Small) from (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Medium) for (Picked unit)) Greater than 0
                • Then - Actions
                  • Unit - Remove Spell Book (Lost Damage Burn Medium) from (Picked unit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Spell Book (Lost Damage Burn Large) for (Picked unit)) Less than 1
                • Then - Actions
                  • Unit - Add Spell Book (Lost Damage Burn Large) to (Picked unit)
                • Else - Actions
            • Else - Actions
      • Custom script: call DestroyGroup(udg_Lost_Building_Check_Group)
 
You can use this trigger:
  • Construction
    • Events
      • Unit - A unit Begins construction
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Custom script: if GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_START then
      • Unit Group - Add (Triggering unit) to ConGroup
      • Custom script: else
      • Unit Group - Remove (Triggering unit) from ConGroup
      • Custom script: endif
and then use the condition
((Picked unit) is in ConGroup) Equal to False.
 
  • Like
Reactions: Kam
Status
Not open for further replies.
Top