🏆 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!
Is there a workaround of this so I don't have to pick a random unit? I rather want it to be any unit of a specific type owned by player 1 red within range, not a random one. Do I have to use a variable?
((Triggering unit) is in (Units within 100.00 of (Position of (Random unit from (Units owned by Player 1 (Red) matching (((Unit-type of (Matching unit)) Equal to Village) or ((Unit-type of (Matching unit)) Equal to City))))))) Equal to True
and when you use the "PlayerNumberOf(Player)" function instead of a fix number (1, 2, 3, ...) , then you can dynamically use it in triggers.
For example, we want to have a trigger that when a player presses "ESC" button, then we kill his unit:
KillTrigger
Events
Player - Player 1 (Red) skips a cinematic sequence
Player - Player 2 (Blue) skips a cinematic sequence
Player - Player 3 (Teal) skips a cinematic sequence
Player - Player 4 (Purple) skips a cinematic sequence
Conditions
Actions
Unit - Kill Unit[(Player number of (Triggering player))]
.. PlayerNumberOf(Player) will automatically hold value "1" for Player1, "2" for Player2, and so on. Depending on which player triggered the event to run.
I don't think I quite get it, seems like I've tried everything, can't get it right!
See below, I've played around with setting variables but it doesn't matter what I do, I can never set:
((Triggering unit) is in (Units within 100.00 of PointTest[1])) Equal to True
To:
((Triggering unit) is in (Units within 100.00 of "UNIT TYPE OWNED BY PLAYER")) Equal to True
The goal is to check if there is a specific unit within range, if it is, it should complete the upgrade, if not the upgrade is cancelled (Haven't found a way to cancel an upgrade, just using method to replace the unit that is being upgraded)
RedUpgradesToSpiritway
Events
Unit - A unit Begins an upgrade
Conditions
(Unit-type of (Triggering unit)) Equal to Spiritway (road)
Actions
Set Unit[1] = (Random unit from (Units owned by (Owner of (Triggering unit)) of type Spiritway (road)))
Set BuildingType[1] = (Unit-type of Unit[1])
Set PointTest[1] = (Position of Unit[1])
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Triggering unit) is in (Units within 100.00 of PointTest[1])) Equal to True
Then - Actions
Set Unit[1] = (Random unit from (Units owned by (Owner of (Triggering unit)) of type Spiritway (road)))
Set PointTest[1] = (Position of Unit[1])
Set Unit[2] = (Random unit from (Units owned by (Owner of (Triggering unit)) of type Village))
Set Unit[3] = (Random unit from (Units owned by (Owner of (Triggering unit)) of type City))
Set BuildingType[1] = (Unit-type of Unit[1])
Set BuildingType[3] = (Unit-type of Unit[3])
Set BuildingType[1] = Spiritway (road)
Set SpiritwayForPlayer = (Units owned by (Owner of (Triggering unit)) of type BuildingType[1])
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Clay[1] Greater than or equal to 1
Tree[1] Greater than or equal to 1
Then - Actions
Set Clay[1] = (Clay[1] - 1)
Set Tree[1] = (Tree[1] - 1)
Floating Text - Create floating text that reads -1 |c00c67000Clay|r at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Wait 0.33 seconds
Floating Text - Create floating text that reads -1 |c0000bf16Tree|r at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Game - Display to (All players) the text: ((PC[1] + (Name of (Owner of (Triggering unit)))) + |r built a Spiritway!)
Else - Actions
Unit - Replace (Triggering unit) with a Ground for spiritways using The new unit's default life and mana
Unit - Change ownership of (Last replaced unit) to Neutral Passive and Change color
Floating Text - Create floating text that reads |c00ff0000Not enoug... at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Else - Actions
Unit - Replace (Triggering unit) with a Ground for spiritways using The new unit's default life and mana
Unit - Change ownership of (Last replaced unit) to Neutral Passive and Change color
Floating Text - Create floating text that reads |c00ff0000You need a nearby Village!|r at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Edit: Maybe if I create a region at triggering unit with the aprox size of the "within 100" and verify that there is a specific unit-type in that region? I'll test this.
Edit: Ok so I can't seem to get this to work either... You need (1) "village" in the region to be able to upgrade a "ground for spiritway" to a "spiritway". This is what I have at the moment:
Game setup
Events
Map initialization
Conditions
Actions
Set BuildingType[1] = Spiritway (road) (Unit-type)
Set BuildingType[2] = Village (Unit-type)
Set BuildingType[3] = City (Unit-type)
Set BuildingType[4] = Ground for spiritways (Unit-type) <- unit that upgrades to spiritway
Set BuildingType[5] = Ground for villages/citys (Unit-type) <- unit that upgrades to village
Set RegionTest[1] = WithinRange <gen> (Region)
RedUpgradesToSpiritway
Events
Unit - A unit Begins an upgrade
Conditions
(Unit-type of (Triggering unit)) Equal to BuildingType[1]
Actions
Region - Center RegionTest[1] on (Position of (Triggering unit))
Unit Group - Pick every unit in (Units in RegionTest[1] matching ((Unit-type of (Picked unit)) Equal to BuildingType[2])) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Picked unit) is in (Units of type Village)) Equal to True
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Clay[1] Greater than or equal to 1
Tree[1] Greater than or equal to 1
Then - Actions
Set Clay[1] = (Clay[1] - 1)
Set Tree[1] = (Tree[1] - 1)
Floating Text - Create floating text that reads -1 |c00c67000Clay|r at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Wait 0.33 seconds
Floating Text - Create floating text that reads -1 |c0000bf16Tree|r at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Game - Display to (All players) the text: ((PC[1] + (Name of (Owner of (Triggering unit)))) + |r built a Spiritway!)
Else - Actions
Unit - Replace (Triggering unit) with a Ground for spiritways using The new unit's default life and mana
Unit - Change ownership of (Last replaced unit) to Neutral Passive and Change color
Floating Text - Create floating text that reads |c00ff0000Not enoug... at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Else - Actions
Unit - Replace (Triggering unit) with a Ground for spiritways using The new unit's default life and mana
Unit - Change ownership of (Last replaced unit) to Neutral Passive and Change color
Floating Text - Create floating text that reads |c00ff0000You need ... at (Position of (Triggering unit)) with Z offset 0.00, using font size 7.50, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
Edit: Hmm!! Maybe I can just make an aura on villages and check if spiritway is under the effects of that aura? Trying!
It's more just a condition check, than a variable assignment. Maybe an example helps.
First variables need some value. Here we create a unit at map load for player 1, and assign the variable.
Init
Events
Map initialization
Conditions
Actions
Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
Set unit[1] = (Last created unit)
Now we can use the variable, and make distance check if needed like in your case. In the example the distance check runs, when Player 1 presses "ESC" button.
Distance Check
Events
Player - Player 1 (Red) skips a cinematic sequence
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Distance between (Position of unit[(Player number of (Triggering player))]) and (Position of Scout Tower 0000 <gen>)) Less than 300.00
Then - Actions
Game - Display to (All players) the text: in range
Else - Actions
Game - Display to (All players) the text: not in range
^It checks if the unit of triggered player is in range "300" of an other pre-set unit.
Can be, but I've seen also many times people use "Random Unit of Type < x > By Player" to refer to one specific unit from player, because they didn't know how to use unit variables, but they know the player has only 1 unit of this type.
If you want actions to apply to every unit in a group then use the pick every unit in group action and inside the loop block apply the actions to the picked unit.
If you want to apply actions to just 1 unit (do not care which) of a unit group then you can use the FirstOfGroup function on the unit group to get such a unit. Performance wise this is a lot more efficient than a random unit of a unit group due to more simple native logic.
JASS:
native FirstOfGroup takes group whichGroup returns unit
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.