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

Detect Unit Type in a Region

Status
Not open for further replies.
Level 11
Joined
Nov 25, 2014
Messages
526
In a region containing units of type A, they are able to morph into type B. I want a trigger to fire, showing game text of "VICTORY" when all of the units of type A has successfully morphed into type B in a specific region.

How the trigger goes?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You can count the number of units of a unit type within a region.
You can count how many of type A are left and if 0 -> Victory
 
You can use a For Unit Group action to count the number of units. That would not leak easily.

Approach 1

Approach 2


This might be handy for you:
Transformation Detector

You create a trigger that filters out when a unit of type A transforms into type B, and count the number of units of type A in the Unit Group. If it is 0, you win!

This utilizes a timer, so here it goes:

You periodically check if the number of units of type A in the unit group is equal to 0. If it is, you disable the trigger and win!
 
Level 3
Joined
Apr 6, 2015
Messages
44
Many ways to do this, but I don't know how you want to do it, but I'll give you MUI ways to do because I perfer MUI

Have them all trigger right away into the same unit all at once

First
Create a TempGroup
Create a TempRegion

Your own Trigger
-Blah
-Blah
-Your fire Trigger is done, then add this to the end
-Set TempRegion = Region 001
-Set TempGroup = All units of unit-type A within TempRegion
-Pick Every Unit in TempGroup
-Repleace Picked Unit with Unit B
-Destroy TempRegion & TempGroup (To prevent Leaks, you use scipts like [call DestroyGroup(udg_TempGroup)]).
-Then Display Text to Player 1 (or all): VICTORY (As they all were replaced so theres none left of Unit Type A, no need for a trigger)


Have them all transform at different times or something that you can control

Here
Create a Hasttable
Create a TempGroup
Create a TempRegion


Trigger 1
-When A Unit enters a region
-Region = Region 001
-Unit-Type= Unit A
-Save 10 as Time for Entering Unit in RandomHashtableName
-Add unit to RandomUnitGroupName

See later for Version 2 -You can also set it as RandomUnitGroupName[1]



Trigger 2
-When A Unit leaves a region
-Region = Region 001
-Unit-Type= Unit A

-Clear all child hastables from Leaving Unit in RandomHashtableName
-Remove Leaving Unit from RandomUnitGroupName


Trigger 3 [Version 1]
-Every 1 second
-Pick every unit in RandomUnitGroupName Version 2 Will be -Pick every unit in RandomUnitGroupName[2]

-Set RandomRealVariableName as Load Hashtable Time of key Picked Unit in RandomHashtableName
-If RandomRealVariableName is greater than 0 then
-Save RandomRealVariableName - 1 as Time for Picked Unit in RandomHashtableName
-Else
-Replace Picked unit with Unit B
-Set TempRegion = Region 001
-Set TempGroup = All units of unit-type A within TempRegion
-Pick Every Unit in TempGroup
-if Number of Units in TempGroup is greater than 0 then
-Do Nothing
-Else
-Display Text to Player 1 (or all): VICTORY
-Destroy TempRegion & TempGroup


This is the Version 2 part from before
YOUR OWN TRIGGER AND WHAT YOU WANT TO FIRE WITH THAT TRIGGER, Just add this to the end of it
-When Illidan kisses Furion
-Blah Stronghold is upgraded to level 2 Blah Blah
-Blah Blah add 500 EXP to Furion blah blah
-Done with what ever triggers you have here
-Pick every Unit in RandomUnitGroupName[1]
-Add unit to RandomUnitGroupName[2]
-
Remove Unit from RandomUnitGroupName[1]

And that should make Trigger 3 work just fine for when you want to activate it
 
Status
Not open for further replies.
Top