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

[Trigger] Constructing Structure vs Triggering Unit

Status
Not open for further replies.
Level 37
Joined
Jul 22, 2015
Messages
3,485
I made my own income system for my project that gives the player income based on the amount of structures they have. After some tinkering, I found that while a structure is being built or being upgraded, the player will still get credit for that structure, which I do not want. My way around is to use custom values: if structure is built or finishing an upgrade, set custom value = 1; if they are being built or beginning an upgrade, set custom value = 0. I then added an extra condition that only adds income if the custom value of the unit is 1.

  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • Set IS_PickedUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (IS_PickedUnit is alive) Equal to True
          • (Custom value of IS_PickedUnit) Equal to 1
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of IS_PickedUnit) Equal to IS_LumberUnit[IS_CurrentIndex]
              • (Unit-type of IS_PickedUnit) Equal to IS_GoldUnit[IS_CurrentIndex]
        • Then - Actions
          • -------- income stuff --------
        • Else - Actions
  • Income Add Unit
    • Events
      • Unit - A unit Finishes construction
      • Unit - A unit Finishes an upgrade
      • Unit - A unit Cancels an upgrade
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to IS_LumberUnit[IS_CurrentIndex]
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 1
  • Income Remove Unit
    • Events
      • Unit - A unit Begins an upgrade
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to IS_LumberUnit[IS_CurrentIndex]
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 0

My question is: For Income Remove Unit, why does the condition not take "triggering unit" as a valid comparison for the trigger like Income Add Unit? The trigger will only run if I set it to Constructing structure, yet I set the custom value of the "triggering unit", which happens just fine.
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
  • Unit - A unit Finishes construction
Using this event, triggering unit = the unit that made the structure
  • Unit - A unit Finishes an upgrade
  • Unit - A unit Cancels an upgrade
In these events, triggering unit = structure that has the upgrade

In short, triggering unit refers to the 'A unit' in the event.
Example:
- 'A unit dies', triggering unit = dying unit.
- 'A unit is summoned', triggering unit = summoned unit not summoning unit.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
  • Unit - A unit Finishes construction
Using this event, triggering unit = the unit that made the structure
  • Unit - A unit Finishes an upgrade
  • Unit - A unit Cancels an upgrade
In these events, triggering unit = structure that has the upgrade

In short, triggering unit refers to the 'A unit' in the event.
Example:
- 'A unit dies', triggering unit = dying unit.
- 'A unit is summoned', triggering unit = summoned unit not summoning unit.

To sum it up, Triggering Unit is the unit that ran the event for trigger.

Thanks :)

KILLCIDE, just keep in mind that if you are using UnitIndexer you'd want to switch that to Set BuildingArray[(Custom value of StructureUnit)] = 0/1/etc. instead of directly setting the custom value.

Yes I know :( right now I'm not using a Unit Indexer, so its no problem. I'm thinking of just adding these units to a group whenever they finish an upgrade/construction or cancel an upgrade, removing them whenever they begin an upgrade, and then just checking if the unit type of the unit is in said group.

EDIT:
  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • Set IS_PickedUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (IS_PickedUnit is in IS_Group) Equal to True
        • Then - Actions
          • -------- income stuff --------
  • Income Add Unit
    • Events
      • Unit - A unit Finishes construction
      • Unit - A unit Cancels an upgrade
      • Unit - A unit Finishes an upgrade
    • Conditions
    • Actions
      • Set tempUnit = (Triggering unit)
      • For each (Integer tempInt) from 1 to IS_MaxIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Unit-type of tempUnit) Equal to IS_GoldUnit[tempInt]
                  • (Unit-type of tempUnit) Equal to IS_LumberUnit[tempInt]
            • Then - Actions
              • Unit Group - Add tempUnit to IS_Group
            • Else - Actions
  • Income Remove Unit
    • Events
      • Unit - A unit Dies
      • Unit - A unit Begins an upgrade
    • Conditions
      • ((Triggering unit) is in IS_Group) Equal to True
    • Actions
      • Set tempUnit = (Triggering unit)
      • Unit Group - Remove tempUnit from IS_Group

I have to loop through the unit-types because of this :)
  • Set IS_GoldUnit[1] = Level 1 Mine Shaft [1]
  • Set IS_GoldUnit[2] = Level 2 Mine Shaft [2]
  • Set IS_GoldUnit[3] = Level 3 Mine Shaft [4]
  • Set IS_GoldUnit[4] = Level 4 Mine Shaft [8]
  • Set IS_GoldUnit[5] = Level 5 Mine Shaft [16]
  • Set IS_GoldUnit[6] = Level 6 Mine Shaft [32]
  • Set IS_LumberUnit[1] = Lumber Mill - Level 1 [1]
  • Set IS_LumberUnit[2] = Lumber Mill - Level 2 [2]
  • Set IS_LumberUnit[3] = Lumber Mill - Level 3 [4]
  • Set IS_LumberUnit[4] = Lumber Mill - Level 4 [8]
  • Set IS_LumberUnit[5] = Lumber Mill - Level 5 [16]
  • Set IS_LumberUnit[6] = Lumber Mill - Level 6 [32]
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
Unit - A unit Finishes construction
Using this event, triggering unit = the unit that made the structure
It is impossible to get the unit which built a structure if I recall. Since more than 1 unit can finish a structure this is logical. In fact it is impossible to tell who started or finished a structure (you need a possibly inaccurate system to do that).

The general approach to get that functionality is to track unit construction orders and then when the building foundation is created assume the closest builder ordered to build the particular building at that location is responsible for making the building. Additional tests such as builder ownership also help with accuracy. Inaccuracy will occur if multiple workers are ordered to build the exact same building at the exact same place for the same player, which is acceptable since one usually does not care for such an error.
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
It is impossible to get the unit which built a structure if I recall. Since more than 1 unit can finish a structure this is logical. In fact it is impossible to tell who started or finished a structure (you need a possibly inaccurate system to do that).

The general approach to get that functionality is to track unit construction orders and then when the building foundation is created assume the closest builder ordered to build the particular building at that location is responsible for making the building. Additional tests such as builder ownership also help with accuracy. Inaccuracy will occur if multiple workers are ordered to build the exact same building at the exact same place for the same player, which is acceptable since one usually does not care for such an error.

Hmm, you're right. Constructing Unit is the same as Triggering Unit. Though I wonder why Blizzard didn't made an Event Response for the Worker that begin the construction. So killcide, ignore the part where I said things about constructing unit because the unit in the 'A unit begins construction' refers to the structure not the worker that's why triggering unit is the structure not the worker.
 
Status
Not open for further replies.
Top