• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How to find damaged structures? Life percent is not working!

Level 3
Joined
May 10, 2024
Messages
9
Hi. In the code bellow I issue build order to peasant. Near the farm I have Town Hall with 100% health and Guard Tower with 50% health.

I Have two problems with the code:
1. When builder finishes his order percentage life of the farm is still less than 100% while text message shows that it is 100%. See screenshot. What is it? :grin:
2. While farm is under construction it is "damaged structure" since it has less than 100% of hp. How to check that it is not under construction in one clean IF statement.

  • Find Damaged Structures
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order Peasant 0000 <gen> to build a Farm at (Position of Peasant 0000 <gen>)
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to True
              • ((Picked unit) is alive) Equal to True
              • (Percentage life of (Picked unit)) Less than 100.00
            • Then - Actions
              • Game - Display to (All players) the text: (Damaged structure: + (Name of (Picked unit)))
              • Game - Display to (All players) the text: (Life percent: + (String((Percentage life of (Picked unit)))))
            • Else - Actions
      • Game - Display to (All players) the text: =============
 

Attachments

  • .png
    .png
    7.9 MB · Views: 10

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,688
I guess a structure is considered to be at 100% life while building. Anyway, is #1 a problem? It sounds like all you need to do is solve #2 since you won't be checking "under construction" buildings.

A good solution to #2 involves using a Unit Indexer, a lightweight yet powerful system that can solve a huge portion of your advanced triggering problems. The idea is simple, use the Unit Indexing method to keep track of each structure's build status in a Boolean array variable.

Set this Boolean's status to true when the structure begins building:
  • Events
    • Unit - A unit Begins construction
  • Conditions
  • Actions
    • Set Variable CV = (Custom value of (Triggering unit))
    • Set Variable Building_Is_Constructing[CV] = True
CV is an Integer variable, I find it easier to understand with this extra variable but you don't need it.

Set this Boolean's status to false when the structure is finished building:
  • Events
    • Unit - A unit Finishes construction
  • Conditions
  • Actions
    • Set Variable CV = (Custom value of (Triggering unit))
    • Set Variable Building_Is_Constructing[CV] = False
Now you can check for this Boolean in your Find Damaged Structures trigger along with your other Conditions:
  • Find Damaged Structures
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order Peasant 0000 <gen> to build a Farm at (Position of Peasant 0000 <gen>)
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to True
              • ((Picked unit) is alive) Equal to True
              • (Percentage life of (Picked unit)) Less than 100.00
              • Building_Is_Constructing[(Custom value of (Picked unit))] Equal to False
            • Then - Actions
              • Game - Display to (All players) the text: (Damaged structure: + (Name of (Picked unit)))
              • Game - Display to (All players) the text: (Life percent: + (String((Percentage life of (Picked unit)))))
            • Else - Actions
      • Game - Display to (All players) the text: =============
Regarding the Unit Indexer, all you have to do is copy and paste the system folder (it's one trigger) into your map. It will automatically run at the start of the game and do it's thing. The only requirement of using this system is that you never use this Action yourself:
  • Unit - Set the custom value of (Triggering unit) to 0
The system relies on setting custom value in order to work. But don't worry, the system replaces the need for you to EVER use this yourself.
 
Last edited:
Level 3
Joined
May 10, 2024
Messages
9
I never tried Unit Indexer before. I did the same with the help of hashtable. It solves my #2 problem. However if (Percentage life of (Picked unit) < 100) when Percentage life of (Picked unit) is 100 still resolves to true. So It keeps showing Damaged Structure: Farm. Life Percent: 100 in the chat.

  • Begins Construction
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • Hashtable - Save True as (Key (Constructing structure).) of 0 in (Last created hashtable).
  • Finishes Construction
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Hashtable - Save False as (Key (Constructed structure).) of 0 in (Last created hashtable).
  • Find Damaged Structures
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order Peasant 0000 <gen> to build a Farm at (Position of Peasant 0000 <gen>)
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to True
              • ((Picked unit) is alive) Equal to True
              • (Percentage life of (Picked unit)) Less than 100.00
              • (Load (Key (Picked unit).) of 0 from hashtable.) Equal to False
            • Then - Actions
              • Game - Display to (All players) the text: (Damaged structure: + (Name of (Picked unit)))
              • Game - Display to (All players) the text: (Life percent: + (String((Percentage life of (Picked unit)))))
            • Else - Actions
      • Game - Display to (All players) the text: =============
 

Attachments

  • DamagedStructuresTest.w3m
    17.7 KB · Views: 1
Top