• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Real Reading 0.000?

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
I'm triggering a unit in my map. The drone follows the Medic around. It detects units around the medic who are injured, that is, it is not at 100% health.

Once the unit is damaged, the drone detects the unit's damage. It heals the unit. Then the damaged unit is properly removed from the group. All good? The trigger runs once after this and detects no damaged units. It runs again and then it detects a damaged unit?!?!!

The real initially reads the unit's health at 96.125% (after the unit receives damage) and so the drone heals him. Then the real starts reading 0.000. I assume because the reading is 0%, the Drone think the unit is damaged when he clearly is not. Why is the real giving me a reading of 0%? The unit's health is full so it should be 100%.

  • Heal Drone
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Medic) and do (Actions)
        • Loop - Actions
          • Set TempPoint = (Position of (Picked unit))
          • Unit Group - Pick every unit in (Units within 566.00 of TempPoint) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) belongs to an ally of Player 1 (Red)) Equal to True
                  • (Percentage life of (Picked unit)) Less than 100.00
                • Then - Actions
                  • Unit Group - Add (Picked unit) to DroneInjuredGroup[(Player number of (Owner of DroneMedic[1]))]
                  • Unit Group - Add (Picked unit) to DroneInjuredGroup[(Player number of (Owner of DroneMedic[2]))]
                  • Game - Display to (All players) the text: (Real: + (String((Percentage life of (Picked unit)))))
                  • Game - Display to (All players) the text: (String((Number of units in DroneInjuredGroup[(Player number of (Owner of DroneMedic[1]))])))
                • Else - Actions
          • Custom script: call RemoveLocation (udg_TempPoint)
      • Unit Group - Pick every unit in (Units of type Drone) and do (Actions)
        • Loop - Actions
          • Set DroneUnit[(Player number of (Owner of (Picked unit)))] = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (DroneUnit[(Player number of (Owner of (Picked unit)))] has buff Heal (Drone's Indicator)) Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: Drone's heal is on cooldown
              • -------- Drone has buff so it's heal is on cooldown --------
              • -------- Drone issued a patrol order --------
              • Unit Group - Pick every unit in (Units of type Medic) and do (Actions)
                • Loop - Actions
                  • Game - Display to (All players) the text: (Name of (Picked unit))
                  • Set TempPoint = (Position of (Picked unit))
                  • Set TempPoint2 = (TempPoint offset by (Random real number between 0.00 and 360.00) towards (Random real number between 0.00 and 366.00) degrees)
                  • Unit - Order DroneUnit[(Player number of (Owner of (Picked unit)))] to Move To TempPoint2
                  • Game - Display to (All players) the text: (Name of DroneUnit[(Player number of (Owner of (Picked unit)))])
                  • Custom script: call RemoveLocation (udg_TempPoint)
                  • Custom script: call RemoveLocation (udg_TempPoint2)
            • Else - Actions
              • -------- Drone doesn't have buff so heal is off cooldown --------
              • -------- Drone issued a heal order --------
              • Game - Display to (All players) the text: Drone's heal is ready
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in DroneInjuredGroup[(Player number of (Owner of (Picked unit)))]) Greater than or equal to 1
                • Then - Actions
                  • Game - Display to (All players) the text: A damaged unit is found
                  • Unit Group - Pick every unit in (Random 1 units from DroneInjuredGroup[(Player number of (Owner of (Picked unit)))]) and do (Actions)
                    • Loop - Actions
                      • Unit - Order DroneUnit[(Player number of (Owner of DroneMedic[1]))] to Human Priest - Heal (Picked unit)
                      • Unit - Order DroneUnit[(Player number of (Owner of DroneMedic[2]))] to Human Priest - Heal (Picked unit)
                • Else - Actions
                  • Game - Display to (All players) the text: No damage unit found
                  • -------- Drone's heal is ready but nobody needs healing --------
                  • -------- Drone issued a patrol order --------
                  • Unit Group - Pick every unit in (Units of type Medic) and do (Actions)
                    • Loop - Actions
                      • Game - Display to (All players) the text: (Name of (Owner of DroneUnit[(Player number of (Owner of (Picked unit)))]))
                      • Set TempPoint = (Position of (Picked unit))
                      • Set TempPoint2 = (TempPoint offset by (Random real number between 0.00 and 400.00) towards (Random real number between 0.00 and 360.00) degrees)
                      • Unit - Order DroneUnit[(Player number of (Owner of (Picked unit)))] to Move To TempPoint2
                      • Custom script: call RemoveLocation (udg_TempPoint)
                      • Custom script: call RemoveLocation (udg_TempPoint2)
      • Unit Group - Remove all units from DroneInjuredGroup[(Player number of (Owner of DroneMedic[1]))]
      • Unit Group - Remove all units from DroneInjuredGroup[(Player number of (Owner of DroneMedic[2]))]
      • Game - Display to (All players) the text: (String((Number of units in DroneInjuredGroup[(Player number of (Owner of DroneMedic[1]))])))
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
edit:my bad sorry

Maybe you are picking dead units with your first Unit Group accidently and that is why it is showing 0 health, try adding "((Picked unit) is alive equal to true)"
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
Yeah, the problem looks to be that you also pick dead units into your unit group.

Btw that trigger leaks unit group.
Currently, the trigger can leak [2x(number of medics) + (number of drones)] times up to [3x(number of medics) + (number of drones)] times every 3 seconds, which may turn out to be quite a lot.
Here's how to prevent leaks from creating unit groups: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

The action "pick every unit of type XY and do (actions)" always leaks no matter what, different kind of unit group pick is advised.

The trigger is also quite inefficient - creating unit groups is a costly process and you create too many unit groups. If you are periodically doing something with every Medic unit and Drone unit, then I advise that you save them into their own unique and respective unit groups at map initialization and add/remove them from those groups when they "enter (playable map area)" or when they die.

Also, if you're not going to use loops, then I think using this:
  • Set DroneUnit[(Player number of (Owner of (Picked unit)))] = (Picked unit)
in unit group is useless and unneeded.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Maybe if you use INTEGER.... will become 96

Well, the fact that it reads to 3 decimal places is not my problem. The problem is that it later reads 0. The picked unit does not have 0% HP left. The is something wrong here. Besides, I need this condition. Integers don't check HP, only real conditions do.

  • (Percentage life of (Picked unit)) Less than 100.00
Maybe you are picking dead units with your first Unit Group accidently and that is why it is showing 0 health, try adding "((Picked unit) is alive equal to true)"

No. Under my test circumstances, there are 2 units to be picked from. They are both alive. Ahhhhhhhhhhhhhhhhhhhh this got me thinking. A dummy unit is used in another trigger which fires at the same time as mine. It creates a dummy which expires (and dies). It was picking the Dummy.....oh that feeling when you finally figure it out. Thx very much.

Btw that trigger leaks unit group.

Yeah I know. I like to make the trigger work first before worrying about leaks.
The action "pick every unit of type XY and do (actions)" always leaks no matter what, different kind of unit group pick is advised.

I did not know that. Thanks for pointing that out :)

The trigger is also quite inefficient - creating unit groups is a costly process and you create too many unit groups. If you are periodically doing something with every Medic unit and Drone unit, then I advise that you save them into their own unique and respective unit groups at map initialization and add/remove them from those groups when they "enter (playable map area)" or when they die.

Just goes to show how good I am at coding. Thanks for your tips. Much appreciated.
 
Last edited:
Level 16
Joined
Mar 27, 2011
Messages
1,349
Couple more questions then. If this leaks:

  • Set TempUnitGroup = (Units of type Drone)
Does the following line leak too?

  • Set TempUnitGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Drone))
Also, why does giving my Drone the Locust ability prevent the trigger from working? I wanted to make him unselectable so hes not in the way or accidentely clicked on. Is there a way to make Locust work with my trigger? Creating another trigger which rapidly forces players to unselect the Drone isn't what I had in mind, unless it's the only way.

Here's my updated trigger:

  • Heal Drone
    • Events
      • Time - Every 1.50 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (String(DronePatrolCheck))
      • Unit Group - Pick every unit in DroneMedicGroup and do (Actions)
        • Loop - Actions
          • Set TempPoint = (Position of (Picked unit))
          • Set TempUnitGroup = (Units within 566.00 of TempPoint)
          • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) belongs to an ally of Player 1 (Red)) Equal to True
                  • (Percentage life of (Picked unit)) Less than 100.00
                  • (Unit-type of (Picked unit)) Not equal to Drone
                  • ((Picked unit) is alive) Equal to True
                • Then - Actions
                  • Unit Group - Add (Picked unit) to DroneInjuredGroup[(Player number of (Owner of DroneMedic[1]))]
                  • Unit Group - Add (Picked unit) to DroneInjuredGroup[(Player number of (Owner of DroneMedic[2]))]
                  • Game - Display to (All players) the text: (Real: + (String((Percentage life of (Picked unit)))))
                  • Game - Display to (All players) the text: (Name of (Picked unit))
                • Else - Actions
          • Custom script: call DestroyGroup (udg_TempUnitGroup)
          • Custom script: call RemoveLocation (udg_TempPoint)
      • Set TempUnitGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Drone))
      • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
        • Loop - Actions
          • Set DroneUnit[(Player number of (Owner of (Picked unit)))] = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (DroneUnit[(Player number of (Owner of (Picked unit)))] has buff Heal (Drone's Indicator)) Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: Drone's heal is on ...
              • -------- Drone has buff so it's heal is on cooldown --------
              • -------- Drone issued a patrol order --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DronePatrolCheck Equal to 2
                • Then - Actions
                  • Unit Group - Pick every unit in DroneMedicGroup and do (Actions)
                    • Loop - Actions
                      • Set DronePatrolCheck = 0
                      • Game - Display to (All players) the text: (Name of (Picked unit))
                      • Set TempPoint = (Position of (Picked unit))
                      • Set TempPoint2 = (TempPoint offset by (Random real number between 0.00 and 360.00) towards (Random real number between 0.00 and 366.00) degrees)
                      • Unit - Order DroneUnit[(Player number of (Owner of (Picked unit)))] to Move To TempPoint2
                      • Game - Display to (All players) the text: (Name of DroneUnit[(Player number of (Owner of (Picked unit)))])
                      • Custom script: call RemoveLocation (udg_TempPoint)
                      • Custom script: call RemoveLocation (udg_TempPoint2)
                • Else - Actions
            • Else - Actions
              • -------- Drone doesn't have buff so heal is off cooldown --------
              • -------- Drone issued a heal order --------
              • Game - Display to (All players) the text: Drone's heal is rea...
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in DroneInjuredGroup[(Player number of (Owner of (Picked unit)))]) Greater than or equal to 1
                • Then - Actions
                  • Game - Display to (All players) the text: A damaged unit is f...
                  • Set TempUnitGroup2 = (Random 1 units from DroneInjuredGroup[(Player number of (Owner of (Picked unit)))])
                  • Unit Group - Pick every unit in TempUnitGroup2 and do (Actions)
                    • Loop - Actions
                      • Unit - Order DroneUnit[(Player number of (Owner of DroneMedic[1]))] to Human Priest - Heal (Picked unit)
                      • Unit - Order DroneUnit[(Player number of (Owner of DroneMedic[2]))] to Human Priest - Heal (Picked unit)
                  • Custom script: call DestroyGroup (udg_TempUnitGroup2)
                • Else - Actions
                  • Game - Display to (All players) the text: No damage unit foun...
                  • -------- Drone's heal is ready but nobody needs healing --------
                  • -------- Drone issued a patrol order --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • DronePatrolCheck Equal to 2
                    • Then - Actions
                      • Unit Group - Pick every unit in DroneMedicGroup and do (Actions)
                        • Loop - Actions
                          • Set DronePatrolCheck = 0
                          • Game - Display to (All players) the text: (Name of (Owner of DroneUnit[(Player number of (Owner of (Picked unit)))]))
                          • Set TempPoint = (Position of (Picked unit))
                          • Set TempPoint2 = (TempPoint offset by (Random real number between 0.00 and 400.00) towards (Random real number between 0.00 and 360.00) degrees)
                          • Unit - Order DroneUnit[(Player number of (Owner of (Picked unit)))] to Move To TempPoint2
                          • Custom script: call RemoveLocation (udg_TempPoint)
                          • Custom script: call RemoveLocation (udg_TempPoint2)
                    • Else - Actions
      • Custom script: call DestroyGroup (udg_TempUnitGroup)
      • Unit Group - Remove all units from DroneInjuredGroup[(Player number of (Owner of DroneMedic[1]))]
      • Unit Group - Remove all units from DroneInjuredGroup[(Player number of (Owner of DroneMedic[2]))]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DronePatrolCheck Equal to 2
        • Then - Actions
        • Else - Actions
          • Set DronePatrolCheck = (DronePatrolCheck + 1)
 
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,378
The second way of unit group picking does not permanently leak so it should be ok.

You cannot pick units with locust ability into unit group with the "Pick every unit in region/range". You can try to "Pick every unit owner by player", which should also pick locust units. Or you do it with the unique group like I wrote before -> this could be done by not giving the unit locust ability in object editor, but by adding the ability through triggers once the unit has been add to unit group.
 
Status
Not open for further replies.
Top