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

Detecting how many units are loaded in a transport

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
I attached a map with an example of how you can do this.

It's very simple.
I use a Unit Indexer to keep track of an Integer (array) called LoadCount.
Then I set each Transport Unit's LoadCount value to how many units are loaded inside of it.
In order to do this I need to detect when a Unit is Loaded/Unloaded from a Transport Unit and increase/decrease LoadCount accordingly.
Finally, I run a periodic timer every 10 seconds that adds Income to each Player based on the sum of their LoadCount values.

Here are the triggers:

This trigger runs when a unit enters a transport. This increases the Transport's LoadCount by 1.
  • Load
    • Events
      • Unit - A unit Is loaded into a transport
    • Conditions
    • Actions
      • Set CustomValue = (Custom value of (Transporting unit))
      • Set LoadCount[CustomValue] = (LoadCount[CustomValue] + 1)
This trigger runs when a unit leaves a transport. This decreases the Transport's LoadCount by 1.
  • Unload
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Issued order) Equal to (Order(unload))
      • ((Target unit of issued order) is loaded into (Ordered unit)) Equal to True
    • Actions
      • Set CustomValue = (Custom value of (Ordered unit))
      • Set LoadCount[CustomValue] = (LoadCount[CustomValue] - 1)
Then every 10 seconds we pick through every player's Transport units and find the sum of their LoadCount values, adding Gold equal to this amount.
  • Income
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set PlayerNumber = (Player number of (Picked player))
          • Set Income = 0
          • Unit Group - Pick every unit in TransportUG[PlayerNumber] and do (Actions)
            • Loop - Actions
              • Set CustomValue = (Custom value of (Picked unit))
              • Set Income = (Income + LoadCount[CustomValue])
          • Player - Add Income to (Picked player) Current gold
          • Game - Display to (Player group((Picked player))) for 5.00 seconds the text: (Income: + (+|cffffff00 + (String(Income))))
The thing is, TransportUG will be empty by default so you will need to add your Transport Units to TransportUG manually like I do below. TransportUG[1] is Player 1's TransportUG. TransportUG[2] would be Player 2's TransportUG.
  • Load Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Unit Group - Add Orc Burrow 0012 <gen> to TransportUG[1]
      • Unit Group - Add Orc Burrow 0002 <gen> to TransportUG[1]
      • Unit Group - Add Orc Burrow 0010 <gen> to TransportUG[1]
Note that this is just an example. Maybe the player can build their own Transport units with a Worker or train them from a Barracks. If that was the case, then you would have to make a trigger to add those newly built Transport units into the player's TransportUG. Something along the lines of "A unit finishes training/construction -> Add trained/constructed unit to TransportUG[put the player's number here]".
Note: I removed the Stand Down ability from the Orc Burrows in this example. If you want to use that ability then I can easily add it back/make it work with the system.
 

Attachments

  • Load Income.w3x
    23.2 KB · Views: 18
Last edited:
Status
Not open for further replies.
Top