• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Any way to prevent workers from being targeted while repairing?

Level 39
Joined
Feb 27, 2007
Messages
5,031
Since that target acquisition is usually passive, you would probably have to use the event specific unit acquires a target which would be annoying.

You could use a damage detection system to prevent attacks made against workers while repairing. Whenever such an attack is prevented or a unit is ordered to attack a worker that is repairing, order the attacker to either Stop or Attack something else directly.

Could make the workers invulnerable while repairing, but that has other gameplay implications for abuse.

The other solution I see is that maybe giving the worker units the Suicidal tag would cause them to be ignored, as the AI usually doesn’t attack units with that tag. I frankly cannot remember if adding tags dynamically is possible, so they might have to be flagged that way all the time even when not building.
 
Level 21
Joined
Dec 3, 2020
Messages
528
Since that target acquisition is usually passive, you would probably have to use the event specific unit acquires a target which would be annoying.

You could use a damage detection system to prevent attacks made against workers while repairing. Whenever such an attack is prevented or a unit is ordered to attack a worker that is repairing, order the attacker to either Stop or Attack something else directly.

Could make the workers invulnerable while repairing, but that has other gameplay implications for abuse.

The other solution I see is that maybe giving the worker units the Suicidal tag would cause them to be ignored, as the AI usually doesn’t attack units with that tag. I frankly cannot remember if adding tags dynamically is possible, so they might have to be flagged that way all the time even when not building.
Addng the suicidal tag doesn't work, they still get targeted but thank you so much!
 
Level 19
Joined
Jan 3, 2022
Messages
320
I think there are multiple things to consider. One workaround that I know of is used in maze-like TDs where "dumb" walls are given an 1-1 attack to force enemy units to attack and tear down walls rather than following a maze.
In your case if a building doesn't have an attack to trigger aggro, I think melee units will be prioritized (over buildings).
Another thing to consider is unit priority is afaik determined by their point value: Doc - GetUnitPointValue but it's possible other conditions are taken into consideration first. See if vastly different point values matter, because if yes, try to modify each unit's value at runtime using the Field natives (repair = low value, stopped repairing = high value).

Honestly idk what else to suggest. Redirecting orders is tricky and explotable like Pyro said. I'm not even sure if rewriting AI scripts will give you the flexibility, because a lot of functions are hardcoded for convenience.
What about a temporary invulnerability on workers with a really long cooldown, triggered by triggers? Just for the purpose of cancelling the current attack-targetting once per worker.
 
Level 21
Joined
Dec 3, 2020
Messages
528
Isn't worker targeting related to difficulty? I know it's the case in SC2, can't tell about WC3, although unless it's a campaign I don't think there's a way to change that in custom games
In WC3 the AI doesn't attack your siege units if the siege units are attacking their buildings on Easy or Normal, but as far as my knowledge goes, this doesn't affect workers.
Plus the AI is set to Normal and it still attacks them.

It's not really a biggie if I cannot fix/prevent this.

I think there are multiple things to consider. One workaround that I know of is used in maze-like TDs where "dumb" walls are given an 1-1 attack to force enemy units to attack and tear down walls rather than following a maze.
In your case if a building doesn't have an attack to trigger aggro, I think melee units will be prioritized (over buildings).
Another thing to consider is unit priority is afaik determined by their point value: Doc - GetUnitPointValue but it's possible other conditions are taken into consideration first. See if vastly different point values matter, because if yes, try to modify each unit's value at runtime using the Field natives (repair = low value, stopped repairing = high value).

Honestly idk what else to suggest. Redirecting orders is tricky and explotable like Pyro said. I'm not even sure if rewriting AI scripts will give you the flexibility, because a lot of functions are hardcoded for convenience.
What about a temporary invulnerability on workers with a really long cooldown, triggered by triggers? Just for the purpose of cancelling the current attack-targetting once per worker.
Click to expand...
Thanks but the map where I need is basically a horizontal line where allied units attack enemy units to the death and giving invulnerability to the workers seems kind of broken :D . It's basically a tug of war map where workers are sent to repair the towers and units such as catapults and goblin shredders during combat.
 
Level 21
Joined
Dec 3, 2020
Messages
528
Woah this idea is so good @Chaosium!
I will check what parameters I need to change for the heal to make the workers play their repair animation normally, but giving it like a cooldown of 0.2 seconds should work, right? For constant repair animation. And then just give it a tiny heal like 1 hp per cast.
 
Level 21
Joined
Dec 3, 2020
Messages
528
Just a note, the repair speed is tied to a separate property in repair target's unit editor definition; it's not a flat HP/sec. The repair's resource cost can be easily emulated with triggers though.
Yeah! Resources won't matter since AI with infinite gold and lumber is using the workers to repair their stuff.
Yeah it'll be hard to reproduce exactly the behavior of proper repair (although I suppose you could also trigger the HP restored but that's a bit much maybe), still at least the AI would leave your peasants alone ^^
As long as it doesn't repair/heal too fast I'm fine :D.
I want around 500-600 hp to be restored more or less between 45-60 seconds interval.

I shall tinker with this soon when I can.
 
Level 21
Joined
Dec 3, 2020
Messages
528
Found a workaround!!!
So I gave Heal to the workers. Only 1 worker can repair a mechanical unit/structure but that's in fact what I really wanted to be honest so it's a nice bonus.
Still the AI focused the workers tho, so I removed the worker classification from the workers and voila, all worked well!
So it seems the AI focuses any workers that provide healing to a mechanical unit/structure.

I did try removing the worker classification initially but the AI would not repair (doesn't use the repair ability) if you do that.
You have to do both! Remove worker classification and remove Repair ability and replace it with a Heal for example.

Thanks y'all!
 
Top