How To? Can't Attack a Unit With Specific Buff

Goober4473

TH.net Regular
Reaction score
7
I'd like to make a unit that does little to no damage, but applies a high damage poison. The problem is, this makes successive attacks useless, as the poison shouldn't stack. Thus, I'd like it if the unit would ignore any enemy already poisoned.

The easiest way to do that would be to make the unit unable to attack a poisoned target, so that the unit AI would just target a new unit if one is available. Anyone know how to do this?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
well, you would have to trigger it.

beware, pseudo code:
Events
Unit is attacked
Conditions
Level of <MyMegaImbaCoolPoisonAbility> for Attacking Unit Not Equal 0
Actions
set TempGroup = Units in SomeConstantAttackRange range matching (Matching unit is alive and Matching Unit belongs to an enemy of Attacking Unit and Matching Unit got the buff <MyMegaImbaCoolPoisonBuff> Equal to False)
order Attacking unit to attack Random Unit from TempGroup
custom script: call DestroyGroup (udg_TempGroup)

again, this is not ingame code but should merely show you how to do it.
 

Goober4473

TH.net Regular
Reaction score
7
Here's what I've got so far.

This trigger makes sure that if the unit is ordered to attack a poisoned target, it will attack a nearby target instead:
Trigger:
  • Avoid Poisoned Targets Order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Unit-type of (Ordered unit)) Equal to Green Dragon Sneak (green dragon [level 6])
      • (Issued order) Equal to (Order(attack))
      • ((Target unit of issued order) has buff Deadly Poison ) Equal to True
    • Actions
      • Set TempUnitGroup = (Units within 300.00 of (Position of (Target unit of issued order)) matching (((Matching unit) has buff Deadly Poison ) Equal to False))
      • Set TempUnitGroup2 = (Units within 300.00 of (Position of (Target unit of issued order)) matching (((Owner of (Matching unit)) is an ally of (Owner of (Ordered unit))) Equal to True))
      • Unit Group - Remove all units of TempUnitGroup2 from TempUnitGroup
      • Custom script: call DestroyGroup(udg_TempUnitGroup2)
      • Set TempUnitGroup2 = (Units within 300.00 of (Position of (Target unit of issued order)) matching ((Owner of (Matching unit)) Equal to (Owner of (Ordered unit))))
      • Unit Group - Remove all units of TempUnitGroup2 from TempUnitGroup
      • Custom script: call DestroyGroup(udg_TempUnitGroup2)
      • Unit Group - Pick every unit in (Random 1 units from TempUnitGroup) and do (Actions)
        • Loop - Actions
          • Unit - Order (Ordered unit) to Attack (Picked unit)
      • Custom script: call DestroyGroup(udg_TempUnitGroup)


This trigger causes the unit to choose a different target after each attack:
Trigger:
  • Avoid Poisoned Targets Attacking
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Green Dragon Sneak (green dragon [level 6])
    • Actions
      • Set TempUnitGroup = (Units within 600.00 of (Position of (Attacking unit)) matching (((Matching unit) has buff Deadly Poison ) Equal to False))
      • Set TempUnitGroup2 = (Units within 600.00 of (Position of (Attacking unit)) matching (((Owner of (Matching unit)) is an ally of (Owner of (Attacking unit))) Equal to True))
      • Unit Group - Remove all units of TempUnitGroup2 from TempUnitGroup
      • Set TempUnitGroup2 = (Units within 600.00 of (Position of (Target unit of issued order)) matching ((Owner of (Matching unit)) Equal to (Owner of (Attacking unit))))
      • Unit Group - Remove all units of TempUnitGroup2 from TempUnitGroup
      • Unit Group - Pick every unit in (Random 1 units from TempUnitGroup) and do (Actions)
        • Loop - Actions
          • Unit - Order (Attacking unit) to Attack (Picked unit)
      • Custom script: call DestroyGroup(udg_TempUnitGroup)
      • Custom script: call DestroyGroup(udg_TempUnitGroup2)


This seems to work pretty well, but half the time, when I order the unit to attack a specific target, when none are poisoned yet, the unit attacks a random one instead. The second trigger is working fine.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
delete the first trigger, its useless. when a unit is issued to attack an enemy it will attack that enemy and therefor trigger the second trigger.
the unit is by the way only issued to attack an enemy when the player selects it an either right-clicks the enemy directly or clicks the attack button and thence an enemy. doesnt work for auto aquired targets.

and the second trigger is leaking by the way a unit group, though i would throw the second unit group variable and just use one instead:
Trigger:
  • Avoid Poisoned Targets Attacking
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Green Dragon Sneak (green dragon [level 6])
    • Actions
      • Set TempPoint = (Position of (Attacking unit))
      • Set TempUnitGroup = (Units within 600.00 of TempPoint matching (((Matching unit) has buff Deadly Poison ) Equal to False) and (((Matching unit) is alive ) Equal to True)) and (((Matching unit) belongs to an enemy of (Owner of (Attacking Unit)) ) Equal to true)
      • set TempUnit = (Random unit of (TempUnitGroup))
      • Unit - Order (Attacking unit) to Attack TempUnit
      • Custom script: call DestroyGroup(udg_TempUnitGroup)
      • Custom script: call RemoveLocation (udg_TempPoint)

this should be alot better.
 

Ashlebede

New Member
Reaction score
43
I thought the right-click order was smart, and that even if you want to attack someone with right-clicking, the returned order shalt be [ljass]"smart"[/ljass]...
 

meOme

New Member
Reaction score
31
I would just use the ability Phoenix Fire. It automatically attacks nearby enemies, gives them a DoT, and isn't cast on enemies that already have the buff. Sounds perfect for what you want. And you don't need a single annoying trigger.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I thought the right-click order was smart, and that even if you want to attack someone with right-clicking, the returned order shalt be [ljass]"smart"[/ljass]...

thats true but i think right clicking enemys directly is still the order "attack". though it doesnt matter cause you have to filter both out anyways.

@meOme: depends on what he wants to do. if the tower might have critical strike / bash /items /etc this solution would be better, though if none of these examples nor similar are true he might best use phoenix fire as you said.
 

Goober4473

TH.net Regular
Reaction score
7
delete the first trigger, its useless. when a unit is issued to attack an enemy it will attack that enemy and therefor trigger the second trigger.

If you order the unit to attack a specific unit, that is already poisoned, it would waste one attack hitting that target before switching to a new one.

Apparently if you use a smart order, it converts it into whatever other order, as this trigger goes off whether I right-click or order an attack.

I would have used Phoenix Fire if I knew it existed, but this is now working pretty well. Only problem is it sometimes doesn't attack the target you tell it to initially. This way I can also easily use upgrades that increase base attack damage and the duration of the poison separately.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
no, the "unit is attacked" event does fire when a unit is trying to attack an oponent. not when hitting him.
it would be pretty fine if the users dont spam order the unit to attack, but thence your wouldnt work either.

and your trigger isnt really working fine since its leaking heavily.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
still the first trigger is pretty useless, it will only fire if the player manually orders the unit to attack a specific target with the buff. no auto-aquired targets, no smart orders (attack ground).
i would say its rather annoying then in any way helpful, though i dont exactly know what this unit is supposed to be, a td unit i guess.
 

Goober4473

TH.net Regular
Reaction score
7
I just did a test without the first trigger, and it doesn't quite look right. If I order a few of the unit to attack a target, they all attack it. With the first trigger, they may attack it, but more often they'll pick different targets. The chosen target is random, so they may all hit the same one, but that's fine, as it's just a preference of attack, not a strict rule.

The unit is for a melee-style game.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top