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

Integer / Real Variables Returning to 0 (?)

Status
Not open for further replies.
Level 2
Joined
Dec 24, 2022
Messages
3
Hey folks,

Long-time user, first-time poster. I currently have within my Map a trigger which respawns all Creep units within the map once the total number of Creeps left is equal to or below 80 (this is triggered via Real_CreepTotalNumber becomes equal to or less than 80 ... 143 Creep units are spawned upon map initialisation). The way I track how many Creep units are dead / alive is by removing Creep units from UnitGroup_Creeps upon death and running a p/s Event to set UnitGroup_Creeps to all alive units owned by the Creep Players (10 - 16). I currently having a transmission informing me of both the Real and Integer variables and they work perfectly for a few minutes before they both return to zero for no reason. At first I thought this was because I had reached a cap on either variable, but each transmission I have received has never exceed 143 and perfectly logs killed units (e.g., when I kill a Creep unit the next transmission will show 142 versus 143). Obviously this is affecting my creep respawn system as it is dependent on the Real variable dropping from 143 to 80 and then triggering the respawn, but it cannot do so when each variable is permanently set to 0. I can provide screenshots of each trigger if necessary. Thanks in advance.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Hello, I have a question. Why are you using a Real variable (if that's what you were implying)? There can't be a fraction of a Unit so an Integer is the only thing that really makes sense.

Also, you can use an Integer to track the number of Dead creeps which will be far more efficient than constantly rebuilding a Unit Group. Simply subtract the Integer by 1 whenever a Creep dies and then check if it's <= 80.

Here's what I would do:
Give all of your Creep unit-types a hidden passive ability, we can base it on Storm Hammers since that ability has no effect. This ability will be called "Creep Classification". Now whenever a unit dies we can simply check for this ability to determine if it was a Creep or not:
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of Creep Classification for (Triggering unit) Equal to 1)
  • Actions
    • Set Variable Creep = (Triggering unit)
    • Set Variable CreepCount = (CreepCount - 1)
    • Unit Group - Remove Creep from CreepGroup_Alive
    • Unit Group - Add Creep to CreepGroup_Dead
Using this ability we can easily define which units can be respawned and which cannot.

Then simply check if CreepCount is Equal to 80, and if it is Loop over CreepGroup_Dead and Create new copies of each dead unit and Add them to CreepGroup_Alive. Then Clear CreepGroup_Dead so it's empty and reset CreepCount to it's original value.

HOWEVER, that solution is not perfect. Remember that a dead unit will eventually decay and be removed from the game. If this happens it will no longer be "revivable". A solution to this would be to use Arrays which store the data of your Dead units. Then you can recreate the Units using said data:
  • Creep Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Level of Creep Classification for (Triggering unit)) Equal to 1
    • Actions
      • Set VariableSet Creep = (Triggering unit)
      • -------- --------
      • Unit Group - Remove Creep from Creep_AliveGroup.
      • -------- --------
      • Set VariableSet Creep_DeadCount = (Creep_DeadCount + 1)
      • -------- --------
      • Set VariableSet Creep_ArrayUnitType[Creep_DeadCount] = (Unit-type of Creep)
      • Set VariableSet Creep_ArrayPlayer[Creep_DeadCount] = (Owner of Creep)
      • Set VariableSet Creep_ArrayPoint[Creep_DeadCount] = (Position of Creep)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Creep_DeadCount Greater than or equal to Creep_DefaultCreepCount
        • Then - Actions
          • Trigger - Run Creep Respawn <gen> (ignoring conditions)
        • Else - Actions
Creep_ArrayUnitType is a Unit-Type array. Each [Index] in the array will store a different Dead creep's Unit-type. To "revive" all of the units in the array you would use a For Loop like so:
  • Actions
    • For each (Integer Creep_Loop) from 1 to Creep_DeadCount, do (Actions)
      • Loop - Actions
        • Unit - Create 1 Creep_ArrayUnitType[Creep_Loop] for Creep_ArrayPlayer[Creep_Loop] at Creep_ArrayPoint[Creep_Loop] facing Default building facing degrees
        • -------- --------
        • Custom script: call RemoveLocation(udg_Creep_ArrayPoint[udg_Creep_Loop])
    • -------- --------
    • Set VariableSet Creep_DeadCount = 0
Creep_ArrayPoint and Creep_ArrayPlayer are Arrays as well which contain data about where the Creep died and who owned the Creep.
  • Creep Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Creep_AliveGroup = (Units in (Playable map area) matching ((Level of Creep Classification for (Matching unit)) Equal to 1))
      • Set VariableSet Creep_DefaultCreepCount = (Number of units in Creep_AliveGroup)
^ This should happen before any Creeps can die.
 

Attachments

  • Creep Respawn Example 1.w3m
    19.9 KB · Views: 2
Last edited:
Level 2
Joined
Dec 24, 2022
Messages
3
Thanks for your reply, Uncle.

I will give that a try. Regarding the respawn, I have different factions and up to 33 different creep-types. For instance, the Troll faction consists of UnitTypes 1 through to 7, whereas the Kul Tiran factions consists of UnitTypes 8 - 16, etc. I had it set up to run a random number integer when respawning a unit from a respective faction that would spawn a random creep within that faction. Is there a way I could implement that feature into your version?

*Edit: I supposed I should mention that upon spawning each unit into the map I have already set their UnitTypes, though some units are not spawned in upon Map Initialisation, such as certain Elites and Rare Elites which would be too difficult for a Player to kill until after one or two respawns. I have also already successfully stored their location and facing angle so that upon respawn a random unit will revive at the initial location of the creep (and not where it happened to die, as shown in your trigger). I guess my only problem here was that after a certain amount of time had passed, the variable keeping score of the CreepCount would return to 0, despite their being a full map of creeps.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I imagine you can still avoid the need to use Unit Groups / Counting units in said groups. Just have an Integer representing each Faction and an Integer array to track how many have died in each Faction:
  • Actions
  • Set Variable Key_Troll = 1
  • Set Variable Key_KulTiran = 2
Tracking when a Troll dies:
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of Troll Faction for (Triggering unit)) Equal to 1
  • Actions
    • Set Variable Creep_Count[Key_Troll] = Creep_Count[Key_Troll] - 1
Tracking when a Kul Tiran dies:
  • Events
    • Unit - A unit dies
  • Conditions
    • (Level of Kul Tiran Faction for (Triggering unit)) Equal to 1
  • Actions
    • Set Variable Creep_Count[Key_KulTiran] = Creep_Count[Key_KulTiran] - 1
Maybe you don't even need to separate these factions, the main idea is that you should track the number of dead units using an Integer and not by Creating/Checking a Unit Group constantly.

Also, I can't say for certain why your variable would go to 0 without seeing your triggers but I assume it's because the Unit Group you're referencing is empty.
 
Last edited:
Level 2
Joined
Dec 24, 2022
Messages
3
Great - thank you again, Uncle.

One last thing: I believe the root issue is that respawning units fail to be added to the "Alive" UnitGroup, hence why I have been resetting the UnitGroup variable upon each respawn. It appears that the action Unit Group - Add (Triggering Unit) (or Last Created / Picked, etc.) isn't adding my newly created units into the existing Unit Group, therefore when the next respawn is triggered they aren't removed. To clarify why I need all remaining alive units removed when the death count hits, for example, 80, is so that respawning units don't double up with the existing units in the map.

E.g., 143 total units spawned upon map initialisation. Players kill 63 units, bringing CreepAliveCount to 80, or rather CreepDeathCount to 63. Then, ALL units in UnitGroup_CreepAlive (the remaining 80 units) are removed, so that 143 units can be respawned in their exact positioning and facing as per map initialisation - though they come back as UnitType(Random number between 1 - 7), or any other interval pertaining to their faction (to randomise the respawn and introduce rares / elites). The issue arises in the SECOND respawn, as because there are no units in UnitGroup_CreepAlive, no units are being removed - therefore there is a double up of the 80 remaining units.
 
Status
Not open for further replies.
Top