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

[Trigger] Income system for Town halls and Supply Buildings

Level 3
Joined
Feb 2, 2025
Messages
11
I need help to complete my income script for my work in progress map. In essence I want the last part of it (the 10 second delay before receiving the income again) to loop until either the end of the game or the building is destroyed (similar to how ressource buildings work in Battle for Middle Earth and Command & Conquer). What should I modify to have the intended effect ?
  • Income
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • ((Triggering unit) is A town-hall-type unit) Equal to True
          • (Unit-type of (Triggering unit)) Equal to Farm
          • (Unit-type of (Triggering unit)) Equal to Burrow
          • (Unit-type of (Triggering unit)) Equal to Ziggurat
          • (Unit-type of (Triggering unit)) Equal to Spirit Tower
          • (Unit-type of (Triggering unit)) Equal to Nerubian Tower
          • (Unit-type of (Triggering unit)) Equal to Moon Well
    • Actions
      • Player - Set (Owner of (Triggering unit)).Current gold to (((Owner of (Triggering unit)) Current gold) + 25)
      • Wait 10.00 game-time seconds
      • Player - Set (Owner of (Triggering unit)).Current gold to (((Owner of (Triggering unit)) Current gold) + 25)
 
Level 31
Joined
Aug 29, 2012
Messages
1,415
You can use unit groups, add your building in a group like this

  • Unit Group - Add (Triggering unit) to IncomeBuildingsGroup
And handle the income in a separate trigger

  • Income
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Player - Add (25 x (Number of units in IncomeBuildingsGroup)) to Player 1 (Red).Current gold
If there are several players, you'll need an array to the group and add the gold to all players, but the idea is the same

And if the building is destroyed, you remove it from the group so that it doesn't count anymore
  • Clear
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Unit Group - Remove (Triggering unit) from IncomeBuildingsGroup.
 
Level 3
Joined
Feb 2, 2025
Messages
11
Okay, as i said in my previous thread, that whole trigger thing is still pretty new to me. How do I set-up such an array ?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,925
Okay, as i said in my previous thread, that whole trigger thing is still pretty new to me. How do I set-up such an array ?
When you create your Unit Group variable you'll see a little checkbox with the word Array next to it. You have to click that to enable it for this specific variable. That will give it extra functionality, allowing it to hold multiple values at a time instead of just one value like normal.
1739920982519.png

You can think of a non-Array Variable, which is their default state, as a reference to a single "thing".
Once you make the Variable an Array it becomes a list of that "thing", allowing it to contain references to a huge number of "things".

So the triggers could look something like this:
  • Add Building
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • ((Triggering unit) is A town-hall-type unit) Equal to True
          • (Unit-type of (Triggering unit)) Equal to Farm
          • (Unit-type of (Triggering unit)) Equal to Burrow
          • (Unit-type of (Triggering unit)) Equal to Ziggurat
          • (Unit-type of (Triggering unit)) Equal to Spirit Tower
          • (Unit-type of (Triggering unit)) Equal to Nerubian Tower
          • (Unit-type of (Triggering unit)) Equal to Moon Well
    • Actions
      • Set Variable PN = (Player number of (Owner of (Triggering unit))
      • Unit Group - Add (Triggering unit) to Building_Groups[PN]
  • Remove Building
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • ((Triggering unit) is A town-hall-type unit) Equal to True
          • (Unit-type of (Triggering unit)) Equal to Farm
          • (Unit-type of (Triggering unit)) Equal to Burrow
          • (Unit-type of (Triggering unit)) Equal to Ziggurat
          • (Unit-type of (Triggering unit)) Equal to Spirit Tower
          • (Unit-type of (Triggering unit)) Equal to Nerubian Tower
          • (Unit-type of (Triggering unit)) Equal to Moon Well
    • Actions
      • Set Variable PN = (Player number of (Owner of (Triggering unit))
      • Unit Group - Remove (Triggering unit) from Building_Groups[PN]
  • 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 Variable PN = (Player number of (Picked player))
          • Player - Add (25 x (Number of units in Building_Groups[PN])) to (Picked player) Current gold
These triggers will track your "living" buildings. Then every 10 seconds each Player will gain Gold equal to (25 * the number of those buildings) that they control. PN is an Integer variable, it's completely optional and serves to make the trigger easier to work with and more readable. Understand how it works -> Each Player has a (Player Number) in Warcraft 3, Red = 1, Blue = 2, Teal = 3, etc. We can leverage this number to store data in an Array that is specific to that Player.

So Red's buildings will be stored in Building_Groups[1].
Blue's buildings will be stored in Building_Groups[2].
Teal's buildings will be stored in Building_Gorups[3].

This pattern continues all the way to the Neutral Players with the last number being 28 (representing Neutral Victim I think?).
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,925
Uncle once again to the rescue ! Thanks for the help man, you're a life saviour.
No problem, and I forgot to mention:

You only need to set the Size for the following Variable Types when using Arrays:
Unit Groups, Player Groups, Timers... and one more I'm probably forgetting.

The rest can remain at their default value of 1. Also, there are ways to use these without changing the Size but that's a bit more advanced and a topic for another day. Another thing, you MUST change the Size from within the actual Variable Editor itself, there's a bug otherwise and it might fail to update properly.

To explain Size in greater detail:

The Size controls how large the [index] of an Array can be. So if your Size is 28 then you cannot write [29] as the index since 29 is larger than 28. Using my list analogy from earlier, the Size is how many items you're allowed to add to your list. The paper can only hold up to 28 items on it before you run out of space.

So for example:
  • Set Variable MyUnitGroupArray[29] = ...
  • -------- This currently won't work, 29 is > 28. Increase the Size! --------
Technically you can write [29] there but when you test your map you'll find that your Variable doesn't work.

Fortunately, most Variable Types will automatically Resize, meaning the game will increase the max [index] needed on the fly. However, an [index] can never go above 32,768, that's a hard rule that you cannot bypass. All of this is an efficiency thing for reducing memory usage.
 
Last edited:
Top