• 🏆 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!

How to trigger income for specific units in a specific region?

Status
Not open for further replies.
Level 1
Joined
Jan 9, 2020
Messages
2
Hi there,

This is my first post and I hope it's not a silly question. I've spent many hours trying to solve this trigger system. I've tried countless variations, which work more or less. But none like I want it to.

I am trying to add a small income every 2 seconds for the player for each unit-type "wind mill" in the region "tempreg".

  • Events
    • Time - Every 2.00 seconds of game time
  • Conditions
  • Actions
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Unit Group - Pick every unit in (Units in tempreg matching (((Owner of (Picked unit)) Equal to (Picked player)) and ((Unit-type of (Picked unit)) Equal to Wind Mill))) and do (Actions)
          • Loop - Actions
            • Player - Add (1 x (Number of units in (Units in tempreg matching (((Owner of (Picked unit)) Equal to (Picked player)) and ((Unit-type of (Picked unit)) Equal to Wind Mill))))) to (Picked player) Current gold
I tried adding conditions such as "(Unit-type of (Picked unit)) Equal to Wind Mill)", simply going with Player - Add 1, and/or removing some of the conditions from the "Unit Group" or "Player", but that seemed to either disable the trigger completely or add income for all my units, not just wind mills. I am not sure if the conditions work as "if and only if" in this system and how the picking works exactly. I thought it'd be like pick a player, pick all the units in the region, make sure they belong to player and are in fact wind mills, add income.
 
Last edited:
Level 38
Joined
Feb 27, 2007
Messages
4,951
Helpful resources:
The problem is that you used "picked unit" where you should have used "matching unit". If you are writing a condition in the "units matching (somecondition)" then somecondition needs to refer to the unit as "matching unit". Once the unit is picked and it moves on to the Loop - Actions you refer to the unit as "picked unit".

Another issue is that you will be adding the total gold amount (1 x number of units) for each unit owned by the player, since the action to add the gold is under the Unit Group - Pick actions. You have two options to fix this: first, don't do the player group pick and instead just grab all matching units in the region and add 1 gold to their owner's gold. Second, don't do the unit group pick and instead just count the units then add the proper gold. I would suggest option two. You should also check that the matching units are alive so you don't get gold for dead/decaying wind mills.
  • Events
    • Time - Every 2.00 seconds of game time
  • Conditions
  • Actions
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Set TempGroup = Units in tempreg matching ((((Owner of (Matching unit)) Equal to (Picked player)) and ((Unit-type of (Matching unit)) Equal to Wind Mill))) and ((Matching unit) is alive equal to True))
        • Player - Add (1 x (Number of units in TempGroup)) to (Picked player) Current gold
        • Custom script: call DestroyGroup(udg_TempGroup)
 
Level 1
Joined
Jan 9, 2020
Messages
2
May Elune be with you! Thank you, it works! However, it seems to apply even before the structure is complete. I suppose alive isn't the same as constructed. I'm trying to fiddle with the event response constructed, but I'm not sure how it works. Sorry for all my questions, it's my first map I'm creating.

Moreover, would it be possible to have a structure like this instead:

  • Actions
    • Set TempGroup = Units in TempReg matching
      • And - All (Conditions) are true
        • Conditions
          • Owner of (Matching unit)) Equal to (Picked player)
          • Unit-type of (Matching unit)) Equal to Wind Mill
          • (Matching unit) is alive equal to True
 
Last edited:
Level 9
Joined
Jul 30, 2018
Messages
445
You can do it that way as well. I actually prefer that myself, since it looks a lot better, it’s a lot easier to read and it’s easily modified, if the need arises.

You just have to put an If-statement right after picking the units and use (If (Picked Unit) equal to ...).
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
  • Events
    • Unit - A unit finishes construction
  • Conditions
    • (Unit type of (Triggering Unit)) equal to Wind Mill
  • Actions
    • Unit Group - Add (Triggering Unit) to WINDMILL_GROUP
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Triggering Unit) is in WINDMILL_GROUP) equal to True
  • Actions
    • Unit Group - Remove (Triggering Unit) from WINDMILL_GROUP
  • Events
    • Time - Every 2.00 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in WINDMILL_GROUP and do (Actions)
      • Loop - Actions
        • Player - Add 1 to (Owner of (Picked Unit)) Current gold
 
Status
Not open for further replies.
Top