This seems like it should be simple so hopefully I'm missing something obvious. I want to keep track of all units in a standard game by player. I'd like to store each unit created in an array and remove them as they are killed/destroyed. I have setup a Trigger with the Event "Any unit created...". However, I cannot seem to get at the owner (player) of the unit or the owner of the unit that created the unit. Any help?
What I'm ultimately trying to do is destroy all a player's units at a certain point, so if there's an easier way than tracking them as I suggested above, please let me know.
Actions
Unit Group - Pick each unit in (Any units in (Entire map) owned by player 1 matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
Actions
Unit - Kill (Picked unit)
^_^
If you actually wanted to track them all throughout the game, you will want a Data Table to store all the units. Although you could use a String Variable Array. If you only wanted to kill them at a certain point, then thats your trigger. Just add an Event you want like "timer runs out" and your good to go.
add triggering unit to unit group (PlayersUnits[owner of (triggering unit)]
Trigger RemoveUnit
Any unit dies
condition
type of (triggering unit) != missile
actions
remove triggering unit from unit group( PlayersUnits[owner of (triggering unit)
that should work for you
in some cases a unit may not actually be "created" or "die"
you also want to make sure that the unit is set to create events ... on the unit properties
Rollback Post to RevisionRollBack
Skype
KageNinpo = SN
My Libraries
DialogLeaderboard & TeamSort
My Projects
SPACEWAR Tribute
Infinite TD
Thanks for the tips! I would like to track things in an array as SoulCarveRR is suggesting, but I'm a bit concerned about the last two comments regarding "created" and "die" events. This is just going to be watching a normal SC2 melee match...do I still need to worry about that or can I rely on the Trigger logic you provided?
For now I'm going to implement Astral's suggestion as that doesn't seem to have the same caveats...please correct me if I'm wrong.
Units like archon, broodlords ect which morph may not be picked up by the generic Any Unit created event, if they are picked up it would be after the morph finished.
So if you wanted to remove all the players units at some point you would still have a handful of morphed units hanging around and possibly a few trigger errors from attempting to remove units that don't exist but that have never died and therefor never been removed from the variable. Also any pre-placed units would not be added to the variable and therefor not be removed.
omg that is exactly what was happening in a scripted scene I had with a broodlord...the broodlings were really screwing up my vision sharing changes. So I ditched the broodlords :(
So how does one deal with this issue? How do I access the broodlings from a broodlord as they are created (before they are done morphing), for example?
You can try using the event: Unit - Unit enters region, and set the region to playable map
That event will catch morphs too.
Just dont use too many triggers with that event, ideally limit yourself to one trigger with that event.
This seems like it should be simple so hopefully I'm missing something obvious. I want to keep track of all units in a standard game by player. I'd like to store each unit created in an array and remove them as they are killed/destroyed. I have setup a Trigger with the Event "Any unit created...". However, I cannot seem to get at the owner (player) of the unit or the owner of the unit that created the unit. Any help?
What I'm ultimately trying to do is destroy all a player's units at a certain point, so if there's an easier way than tracking them as I suggested above, please let me know.
Global Variables
Triggers
that should work for you
in some cases a unit may not actually be "created" or "die"
you also want to make sure that the unit is set to create events ... on the unit properties
Thanks for the tips! I would like to track things in an array as SoulCarveRR is suggesting, but I'm a bit concerned about the last two comments regarding "created" and "die" events. This is just going to be watching a normal SC2 melee match...do I still need to worry about that or can I rely on the Trigger logic you provided?
For now I'm going to implement Astral's suggestion as that doesn't seem to have the same caveats...please correct me if I'm wrong.
@AstralCV: Go
omg that is exactly what was happening in a scripted scene I had with a broodlord...the broodlings were really screwing up my vision sharing changes. So I ditched the broodlords :(
So how does one deal with this issue? How do I access the broodlings from a broodlord as they are created (before they are done morphing), for example?
You could pick all units owned by player in the entire map and then kill those picked units.
@jcraigk: Go
You can try using the event: Unit - Unit enters region, and set the region to playable map That event will catch morphs too. Just dont use too many triggers with that event, ideally limit yourself to one trigger with that event.
@malkavianVision: Go
That sounds like a reasonable solution...I'll probably end up using that.