Hey guys, Thanks for any help you are able to give me!
So basically i made a trigger for a map that when 1 unit enters the region around the xel'naga tower in the middle of the map, they gain control of all other xel'nagas on the map. When they leave the middle the vision goes away. However if someone enters the middle, and someone else enters the middle after them, they steal the vision away from the 1st person. How do i set it up so that the 1st person in the middle keeps the vision for as long as they have the majority units in the region. Thanks again!!
Untested: Do a Unit Count within a region around the point where the Xel'Naga tower is (circle with radius is probably what you want). Then loop through all players and set Shared Alliance Aspect (visibility) of player 0 to each player based on unit count.
Create a variable which denotes which player currently owns the tower. Let's call it TowerOwner for this example. Set it to some unused player initially.
Then make a trigger something like this:
Event: Any unit enters region MiddleTower
Condition: Number of units in unit group (Units in region matching condition(Any unit type, MiddleTower, Owner of Triggering unit, ...)) > Number of units in unit group (Units in region matching condition(Any unit type, MiddleTower, TowerOwner, ...))
As far as I know, the Trigger Police are incorrect when they say "don't use nested For loops". Blizzard fixed those a while ago, so no need to continue to fear the For loop.
I was new to Triggers about 4 months ago and now I'm getting pretty comfortable. How did I get there? (1) Research existing threads on this site (2) Hack around in the editor (make lots of little maps to test ideas) (3) Don't give up. I spent about 100 hours in the Trigger editor before I felt like I "knew what I was doing". SC2 modding is for folks who enjoy "poking around" as opposed to having a well documented API.
I feel like I've given you enough info in my post to get you started on your research...have fun!
Sometimes nested For loops are simply the tool required for the job. I agree you shouldn't try to do nested loops when it's not called for, but many times in my professional programming career it has most certainly been the best option and I do it all the time. There seems to be some irrational fear of nested For loops among users of this site...It used to be an issue in Galaxy but Blizzard fixed this months ago.
I think nested loops are fine as long as you make sure they won't iterate too much. Stuff like a search or filling a table should be fine.
However, for this particular case, you don't need loops at all. Make something like this:
Units in zone: integer array, 0=player 1, 1=player 2... or leave 0 empty.
Each time an unit enters the zone, add +1 to the integer array in the position of the owning player ("player number - 1" if you use the 0, and "player number" if you don't use it) and then, check the ownership of the tower.
If you want to save some space, you could leave 0 empty, and use it to denote the last highest player. That way, if an unit enters the region, and it's already owned by the las highest player, you don't check tower ownership.
Something like this (rough scripting):
Unit enters region
add +1 to array(player number of owner of entering unit)
if array(0) != player number of owner of entering unit {
if array(array(0)) < array(player number of owner of entering unit) {
array(0) = player number of owner of entering unit
change ownership of tower to player number array(0)
}
}
You could check the ownership of the tower every time an unit enters a region, but I think this could be more efficient, since you don't need to search the array and compare one by one (you don't need a loop) :P.
Don't forget to initialize the array correctly. Array(0) could be 1, and the others 0.
Not only does the above trigger not work, it's also wastefully overcomplicated.
1 trigger, 1 event, 1 variable, 1 condition. That is all that is needed.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hey guys, Thanks for any help you are able to give me!
So basically i made a trigger for a map that when 1 unit enters the region around the xel'naga tower in the middle of the map, they gain control of all other xel'nagas on the map. When they leave the middle the vision goes away. However if someone enters the middle, and someone else enters the middle after them, they steal the vision away from the 1st person. How do i set it up so that the 1st person in the middle keeps the vision for as long as they have the majority units in the region. Thanks again!!
-Tazac
@TazacSC: Go
Untested: Do a Unit Count within a region around the point where the Xel'Naga tower is (circle with radius is probably what you want). Then loop through all players and set Shared Alliance Aspect (visibility) of player 0 to each player based on unit count.
I would tell you to do a nested For loop but I think I would get scolded by the trigger police. I'm sure there's another way that's just as easy.
@jcraigk: Go
Im sorry i'm new to triggers. How would i go about doing that though?
Don't need nested for loops.
Create a variable which denotes which player currently owns the tower. Let's call it TowerOwner for this example. Set it to some unused player initially.
Then make a trigger something like this:
Event: Any unit enters region MiddleTower
Condition: Number of units in unit group (Units in region matching condition(Any unit type, MiddleTower, Owner of Triggering unit, ...)) > Number of units in unit group (Units in region matching condition(Any unit type, MiddleTower, TowerOwner, ...))
Then do your give vision stuff in the actions.
@BasharTeg: Go
As far as I know, the Trigger Police are incorrect when they say "don't use nested For loops". Blizzard fixed those a while ago, so no need to continue to fear the For loop.
@TazacSC: Go
I was new to Triggers about 4 months ago and now I'm getting pretty comfortable. How did I get there? (1) Research existing threads on this site (2) Hack around in the editor (make lots of little maps to test ideas) (3) Don't give up. I spent about 100 hours in the Trigger editor before I felt like I "knew what I was doing". SC2 modding is for folks who enjoy "poking around" as opposed to having a well documented API.
I feel like I've given you enough info in my post to get you started on your research...have fun!
Nested loops should be avoided in general due to their time complexity. O(n²) is not very good efficiency.
@Nashadun: Go
Sometimes nested For loops are simply the tool required for the job. I agree you shouldn't try to do nested loops when it's not called for, but many times in my professional programming career it has most certainly been the best option and I do it all the time. There seems to be some irrational fear of nested For loops among users of this site...It used to be an issue in Galaxy but Blizzard fixed this months ago.
Of course nested for loops have their uses, but it's often as a last resort, if you can't/don't have time to come up with a good algorithm.
I think nested loops are fine as long as you make sure they won't iterate too much. Stuff like a search or filling a table should be fine.
However, for this particular case, you don't need loops at all. Make something like this:
Each time an unit enters the zone, add +1 to the integer array in the position of the owning player ("player number - 1" if you use the 0, and "player number" if you don't use it) and then, check the ownership of the tower.
If you want to save some space, you could leave 0 empty, and use it to denote the last highest player. That way, if an unit enters the region, and it's already owned by the las highest player, you don't check tower ownership.
Something like this (rough scripting):
You could check the ownership of the tower every time an unit enters a region, but I think this could be more efficient, since you don't need to search the array and compare one by one (you don't need a loop) :P.
Don't forget to initialize the array correctly. Array(0) could be 1, and the others 0.
Not only does the above trigger not work, it's also wastefully overcomplicated. 1 trigger, 1 event, 1 variable, 1 condition. That is all that is needed.