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

How to Make a Trigger that recognizes when a base is Dead?

Status
Not open for further replies.
Level 2
Joined
Jun 14, 2020
Messages
8
I'm trying to make a custom campaign, but I realized that I don't know a way to make triggers that recognize when a base dies and do actions. Essentially, I want to know how to make a trigger that completes a quest when all the non-farm structures in a base are destroyed (one that accounts for the AI player rebuilding).

What sort of events/conditions would i use to get this affect? I've seen this in most custom campaigns I've played, but don't get how to do it.
 
Level 29
Joined
Feb 18, 2014
Messages
3,583
At map initialization, pick all buildings owned by the AI (excluding farms) and add them to a unit group variable, then periodically check when all the units in the group are dead.

You also need a trigger that adds a building to the group after it finishes construction.
 
Are there more bases owned by the same player?

I'd have a
event: generic unit "When a unit dies"
condition: dying unit is owned by that player and dying unit is a structure
action: make a unit group of all structures of owner player (maybe inside a region? if so, ensure that the size is appropriate), that is alive and not a farm, if number of units in unit group is 0, then you should do... Finish quest etc?

I'd say that should work and is fairly easy to make.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,703
It's the same thing.
A periodic trigger running regardless of the circumstances is going to run even when it's not necessary.

Making it Event based is pretty much always better.

If it's a pain in the ass to make it Event based I could understand using a periodic trigger, but in most cases it's fairly easy to make it Event based.

Event based also adds in much needed precision as you're no longer waiting for the timer to run. It'll happen EXACTLY when you want it to happen.

The triggers could look something like this:

To add any pre-placed Farms to the Unit Group
  • Events:
  • Map Initialization
  • Conditions:
  • Actions:
  • Set Variable FarmGroup = Units owned by Player X of type Farm
To check when a Farm dies and whether or not you should complete the Quest
  • Events:
  • A unit dies
  • Conditions:
  • Triggering unit is in FarmGroup equal to True
  • Actions:
  • Remove triggering unit from FarmGroup
  • If number of units in FarmGroup = 0 then complete Quest
To add the rebuilt Farms to the Unit Group
  • Events:
  • A unit begins construction
  • Conditions:
  • Unit-type of constructing structure equal to Farm
  • Actions:
  • Add constructing structure to FarmGroup
You could also use Integers instead of Unit Groups to keep track of the Farms, increasing/decreasing whenever necessary.

Map Initialization -> Set Variable FarmCount = 10 (Let's say you have 10 prebuilt farms)

A Farm dies -> Set Variable FarmCount = FarmCount - 1, then check if FarmCount equal to 0 and complete the Quest

A Farm begins construction -> Set Variable FarmCount = FarmCount + 1
 
Last edited:
Level 2
Joined
Jun 14, 2020
Messages
8
At map initialization, pick all buildings owned by the AI (excluding farms) and add them to a unit group variable, then periodically check when all the units in the group are dead.

You also need a trigger that adds a building to the group after it finishes construction.

Thanks for the help, this seems to work. However there is a strange delay (like 30 seconds) between when the last unit in the unit group dies and when the trigger activates. I suppose it's not a huge deal but any idea on how to fix that?
 
Level 24
Joined
Jun 26, 2020
Messages
1,854
Thanks for the help, this seems to work. However there is a strange delay (like 30 seconds) between when the last unit in the unit group dies and when the trigger activates. I suppose it's not a huge deal but any idea on how to fix that?

The problem is the function "Units in group" includes dead units (it takes 30 seconds to eliminate the corpse) you should add "Matching Condition" and the condition is "Matching Unit is alive".
 
Level 29
Joined
Feb 18, 2014
Messages
3,583
A periodic trigger running regardless of the circumstances is going to run even when it's not necessary.

Making it Event based is pretty much always better.

If it's a pain in the ass to make it Event based I could understand using a periodic trigger, but in most cases it's fairly easy to make it Event based.

Event based also adds in much needed precision as you're no longer waiting for the timer to run. It'll happen EXACTLY when you want it to happen
I still don't see any difference between a 0.01 timer or event based. Besides, periodic timers don't leak if that's your concern.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,703
Leaks aren't a concern, it's the fact that you're leaving room for error during these gaps in time.

Not only that, a timer that runs 100 times per second is pretty inefficient when compared to using Events which may not even go off once.

Using the Farms as an example:
With a 0.01 second timer you'd be asking this question 100 times per second: Is Farm 1 dead? Is Farm 2 dead? Is Farm 3 dead? etc...

With Event based, you'd be asking this question only when an Event goes off. Now which one do you think happens more often? Surely 100 Farms aren't dying per second.

And what if the players decide to never even bother destroying the farms? With a periodic timer you'd be asking a useless question 100 times per second for the rest of the game.

They are not the same thing.
 
Status
Not open for further replies.
Top