• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Selecting Units By Type

Status
Not open for further replies.
Level 6
Joined
Nov 1, 2015
Messages
62
Is there a way to make units being able to be selected seperately just like it is with wards but still retain their ability to build things?

I basically need to find a way to make worker type units not selectable while you control soldiers, because they often get in the way is there any way around this?
 
Level 25
Joined
May 11, 2007
Messages
4,650
Create a trigger that checks when a player selects multiple units,
if one of them is a worker and the rest isn't deselect all workers for that player.

Of course it could result in the player selecting 10 soldiers when there are 12 in his selection box if there are 2 workers too, but at least the workers would be ignored.
 
Level 6
Joined
Nov 1, 2015
Messages
62
I know about that solution, however there's two problems with that;
1. there is a tiny window where the player can still order the workers regardless
2. the player's selection is limited in a way if you had lets say 12 soldiers and 10 workers in one place mixed up, you cannot select all soldiers cleanly :|

I temporarily/partly solved this by making the workers unselectable at all by using the chaos/locust bug and making them selectable when they are doing certain actions
 
Level 7
Joined
Apr 17, 2017
Messages
316
I guess you can do this but I am not sure. When you select workers via trigger. Create a point there might even be a random point as long as it's not too far away, then add units that are not selected to unit group. Then add picked unit to your selection. The problem here is, we need to find a way to detect how many selection slots are left.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
I think you're all converging upon a solution that would be functional... but a little messy. Selection events in Wc3 are bad and slow, and anything that relies on them will be too. Unfortunately. (Really tho I hope this is magically better in Reforged.) Instead it's probably better to use a low period timer to simply check if a unit is selected. This timer has to be running at like 0.2 the whole map (like 0.05 if you don't really wanna see it on screen), but if it's lightweight (doesn't check literally every unit on the map) it can do it's job: see if any of a particular set of units is selected by a player. If a player shouldn't select that unit, just deselect it. I've found in personal testing that the test of native IsUnitSelected takes unit whichUnit, player whichPlayer returns boolean returns true well before the selection event fires.
Create a trigger that checks when a player selects multiple units,
if one of them is a worker and the rest isn't deselect all workers for that player.

Of course it could result in the player selecting 10 soldiers when there are 12 in his selection box if there are 2 workers too, but at least the workers would be ignored.
So we take that but do it with our own fast timer to disable selecting our own workers completely and we combine it with...
I thought about additional player slot - allied/shared unit control - with a player. Let's say player 2 (blue). These blue units will be selectable secondary. But this has side effects unfortunatelly.
yeah unfortunately this would mean there'd be *2 players and the map uses 13 players so thats 26 players plus neutral passive and hostile :/
Bummer, right? No. We make 'our' workers owned by an allied player and allow us to select them but not our own. When a worker is produced for a player we catch that with a 'trains unit' trigger and change ownership of that unit to some designated allied player. If you have a CPU allied player per 'team' in your game you can use that same one otherwise you could do some loop like p2 for p1, p3 for p2, p4 for p3, etc. The workers would also have to have 0 food cost and instead we create an invisibly food-costing dummy unit that's tied to the life of the worker. UI would show 0 food cost but they'd increase your food used. Could manually disable training at max food.

___________
I temporarily/partly solved this by making the workers unselectable at all by using the chaos/locust bug and making them selectable when they are doing certain actions
This is a cool solution from a different angle. I like it!
I suggest to take care upon doing this in a trigger or scrip,, it might desync the other player :)
You do have to be careful but smart usage of GetLocalPlayer() is careful usage. It's only ever used in the 'deselecting a unit' part of the trigger.
 
Status
Not open for further replies.
Top