• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Looking to make a trigger that only applies to buildings after they've finished constructing.

Status
Not open for further replies.
Level 2
Joined
Jan 11, 2023
Messages
3
Hello,

I haven't seen anything like this anywhere else so thought it'd worth the ask. I'm making triggers that apply when a building is clicked, and I've gotten everything to work how I want it. The only kicker is, I'd like to modify the trigger so it only takes effect if the building is not under construction. I've searched fruitlessly for such a modifier, and the closest I've seen is making a condition with Triggering unit is not constructing, but that seems to apply to a builder rather than a building. Is there anywhere I can find a modifier for buildings that are being constructed? I can share an example trigger if needed!

Thanks for any insight you might have!
 
Level 20
Joined
Aug 29, 2012
Messages
847
I did a quick test and managed to do that in two triggers (if I understood correctly)

  • Trigger 1
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 1
  • Trigger 2
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Unit - Set the custom value of (Constructed structure) to 0
This way, you can just check the custom value of the building to see if it's under construction or not :)

If you don't want to use custom value, you can create a dummy ability based on claws of attack or whatever, give it to the structure, and remove it when it's finished, then you can just check whether the building has the ability or not in your other actions. The idea is just to have something exclusive to this building that you can retrieve with a simple condition
 
Last edited:
Level 2
Joined
Jan 11, 2023
Messages
3
I did a quick test and managed to do that in two triggers (if I understood correctly)

  • Trigger 1
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • Unit - Set the custom value of (Triggering unit) to 1
  • Trigger 2
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Unit - Set the custom value of (Constructed structure) to 0
This way, you can just check the custom value of the building to see if it's under construction or not :)

If you don't want to use custom value, you can create a dummy ability based on claws of attack or whatever, give it to the structure, and remove it when it's finished, then you can just check whether the building has the ability or not in your other actions. The idea is just to have something exclusive to this building that you can retrieve with a simple condition
Thanks for the reply! I did something similar, and it doesn't seem to have worked. Essentially, I want a sound to play from this structure, but only lafter it finishes construction. I made a trigger to classify all structures as heros while they are being constructed, and then another trigger to remove that classification the moment that the construction is finished. I then made a trigger so that when a player clicks on my unit, it makes a sound, but only when it doesn't have a hero classification. Unfortunately, it seems to make the sound regardless, and it's not clear to me why.
Trigger.JPG
Trigger complete.JPG
Trigger on unit.JPG


Thanks again for your insight!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,584
Here's how you can post your triggers without needing to take a picture:

Here's the problem, the last part of your Condition in Bulbasaur Sound doesn't really make any sense:
  • and (((Triggering unit) is a Structure) Not equal to ((Triggering unit) is A Hero))
What does this mean?

You simply want to check if it is a Hero or not, which is a True or False question:
  • Conditions
    • (Unit-type of (Triggering unit) Equal to Bulbasaur)
    • ((Triggering unit) is A Hero) Equal to False
Note that all Conditions need to be True for a trigger to succeed, so using AND is unnecessary here.

Also, note that when you Add a classification to a Unit you aren't Removing any other Classifications. Your Structure will be both a Hero AND a Structure while under construction. If this Unit Classification method doesn't work for some odd reason then you can use a Unit Group instead. You would Add them to the group while they're constructing and Remove them when they finish/cancel.

Now here's another issue, your Sound will play for everyone. Here's the trick to make it play for a specific player:
  • Actions
    • Set Variable TempSound = No sound
    • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
    • Set Variable TempSound = Bulbasaur <gen>
    • Sound - Play TempSound
    • Custom script: endif

Here's the final product:
  • Events
    • Player - Player 1 (Red) selects a unit
    • etc...
  • Conditions
    • (Unit-type of (Triggering unit) Equal to Bulbasaur)
    • ((Triggering unit) is A Hero) Equal to False
  • Actions
    • Set Variable TempSound = No sound
    • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
    • Set Variable TempSound = Bulbasaur <gen>
    • Sound - Play TempSound
    • Custom script: endif
TempSound is a Sound variable that you need to create yourself. It's necessary to avoid a possible desync issue.
The Custom Script is a special Action that allows you to write code in your triggers. This code allows for more options than what the normal Trigger Editor provides. In this case the Custom Script is saying "Only run these two Actions for the Player that fired the trigger".
 
Last edited:
Level 11
Joined
May 29, 2008
Messages
132
I needed a system like this for my map (wanted to prevent casting certain spells on under construction structures). My solution was just to make a little system that keeps track of under construction structures by keeping them in a global group. Just bind to 'Unit begins construction' to add a unit to the group, then remove the unit from the group on construction finish, construction cancel, or death events!

Checking if a unit is under construction is as easy as checking group membership. Easy and it doesn't mess with classifications built into the game.
 
Level 12
Joined
Jan 10, 2023
Messages
191
I'm a bit late to suggest this, but I would go with what Chaosium said but with one change:

Make the custom value go to 1 when they are complete, that way the default is that they are 0 and you can avoid an extra trigger.

If we set them all to 1 when they begin construction or when they enter the map, we have to have a trigger to detect the creation of each structure.
If we leave them all at 0 and then set them to 1, we only need to detect when they finish construction and I'm guessing we aren't using the custom values for anything special.

If you do need to use the custom value for something else, but you don't need the custom value while it's under construction, this will work because we don't care what the custom value is as long as it isn't 0.

  • Construction Complete
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Unit - Set the custom value of (Constructed structure) to 1
  • Structure Selected
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
      • Player - Player 9 (Gray) Selects a unit
      • Player - Player 10 (Light Blue) Selects a unit
      • Player - Player 11 (Dark Green) Selects a unit
    • Conditions
      • (Custom value of (Triggering unit)) Not equal to 0
    • Actions
      • Sound - Play I Think I'm Going Bald <cos>
 
Level 39
Joined
Feb 27, 2007
Messages
5,034
If you do need to use the custom value for something else, but you don't need the custom value while it's under construction, this will work because we don't care what the custom value is as long as it isn't 0.
Anything that uses custom value (unit indexer, most likely) will set that value when the unit enters the map (which happens when you start building a building) and never attempt to set it again, so you would absolutely still break an indexer doing this. The better way to work around an indexer that's co-opted your CV is to use the value it gives to a unit's CV as indices in an array, which you can safely modify any time you want:
  • //When the unit first enters the map:
  • Set IsBuilding[(Custom Value of (Triggering Unit))] = 1
  • //When construction finishes:
  • Set IsBuilding[(Custom Value of (Triggering Unit))] = 0
Don't even have to clean up this array when units die.
 
Level 12
Joined
Jan 10, 2023
Messages
191
Anything that uses custom value (unit indexer, most likely) will set that value when the unit enters the map (which happens when you start building a building) and never attempt to set it again, so you would absolutely still break an indexer doing this. The better way to work around an indexer that's co-opted your CV is to use the value it gives to a unit's CV as indices in an array, which you can safely modify any time you want:
  • //When the unit first enters the map:
  • Set IsBuilding[(Custom Value of (Triggering Unit))] = 1
  • //When construction finishes:
  • Set IsBuilding[(Custom Value of (Triggering Unit))] = 0
Don't even have to clean up this array when units die.
My main point, well, now it's a question isn't it just easier and without issue to pay no heed to the structure's creation, leaving it at 0 CV, and then when structure is finished construction set it to 1 and just check if it's 1 when you want to know if it is complete, that way you don't need a trigger for 'created unit' AND a trigger for 'unit finishes construction', you could use just the 'unit finishes construction' trigger and not worry about it being created...

but i think this might be a solved issue anyway...
 
Level 39
Joined
Feb 27, 2007
Messages
5,034
The unit indexer assigns it an index and then sets the unit's CV to that value when the unit enters the map. This occurs when the building starts construction, not when it finishes (human buildings are functional buildings, they just need to be 'repaired' up to full health during construction). The structure will not have a CV = 0 if you check while it's constructing (because the indexer has already assigned it a CV), and setting the CV = 1 after construction will remove the index it was given by the indexer (indexer doesn't try to 're-assign' a new index to the unit) and generally cause the indexer not to have a great time when that unit dies.
 
Level 12
Joined
Jan 10, 2023
Messages
191
I see, I thought that the CV was completely unused unless I put it to use and I thought it was defaulted to 0. Good to know!
Sorry for the waste of time there! Normally I try to make sure that if I have something to add I should know what the heck I'm talking about... my bad..
 
Level 12
Joined
Jan 10, 2023
Messages
191
O I see, it's a common term for a common practice. I can say, I at least knew that CV was liable to be used for many purposes, but I haven't been engaged in any sort of community for the world editor (just beginning to change that now) so I'm a little in the dark when it comes to common practices.

Thanks for clearing that up for me.
 
Status
Not open for further replies.
Top