Worker with auto attack

Level 9
Joined
Sep 11, 2013
Messages
230
Hi!
How can i make an unit with classification "worker" and still make him able to auto attack when an enemy is near his view.
I want that unit to be worker as classification only because i need the idle icon (F8).
The problem is that, if the unit is worker, do not auto attack anymore..
Thanks in advance!
 
Last edited:

Uncle

Warcraft Moderator
Level 48
Joined
Aug 10, 2018
Messages
4,653
You'd have to trigger it as far as I know.

A complicated solution:

Add all of the Workers to a Unit Group, then use a Periodic Interval trigger to periodically Pick through the Workers and check for units near them. Then check if each (Picked unit) is an Enemy and is in Vision, so that your Worker doesn't run off into the fog of war to attack an enemy out of sight. You probably want to use a Distance check to get the closest target amongst these enemies. You can also take into consideration Armor types for targeting priority, since Fortified units are lower priority. You'll probably also need a system in place to prevent the Worker from switching targets if it's already attacking something, this could be done with a Damage Engine/Damage Events and clever use of Timers. For example, if the Worker hasn't attacked in 5 seconds then mark it as "Idle" and Add it to the Unit Group, otherwise, Remove it from the Unit Group or mark it as "Attacking". You could use a Hashtable/Unit Indexer to "mark" the units and track the Timers.
 
Last edited:
Level 34
Joined
Feb 27, 2007
Messages
4,579
Not a good solution but you could give the worker units a custom Phoenix Fire ability to automatically damage nearby units for an appropriate amount of damage at an appropriate interval. That's what the items in maps like Battleships or Battle Tanks use. They wouldn't auto-acquire targets or chase them unless ordered, but they would at least automatically damage things nearby.

You'd have to disable/remove the ability while the worker was being ordered to do something so that it wouldn't be able to attack and mine simultaneously for example. It also wouldn't count as an auto attack for anything in the map/on those workers that should interact with auto attacks.
 
Level 27
Joined
Feb 18, 2014
Messages
3,544
I want that unit to be worker as classification only because i need the idle icon (F8).
In that case use the custom ui features to create the icon button.
 
Top