How to get units to return fire?

Lizzard

New Member
Reaction score
2
I wrote something similar to this earlier but not really the same thing as it had more to do with machine performance, so I thought i would start fresh.

I'm working on a siege map and what I want to do is that when a player (except player11) attacks player12, the attacked unit shall attack the attacking unit (which always is a hero), I came up with some code to cover it but i'm having big trouble with it :(, which i will explain later:
Code:
HeroAttackPriority
    Events
        Unit - A unit owned by Player 12 (Brown) Is attacked
    Conditions
        ((Owner of (Attacking unit)) is an ally of Player 1 (Red)) Equal to True
        (Owner of (Attacking unit)) Not equal to Player 11 (Dark Green)
    Actions
        Unit Group - Pick every unit in (Units within 512.00 of (Position of (Attacked unit)) matching ((Owner of (Matching unit)) Equal to Player 12 (Brown))) and do (Actions)
            Loop - Actions
                Unit - Order (Picked unit) to Attack (Attacking unit)
But what I didn't think of is that every time a unit owned by ex player1 attacks player12 that unit will attack them: meaning that if p1 hits p12, then it works perfectly and p12 attacks p1. But the second time when p1 attacks the same unit again, it may happen (and definitely will) that p12 already has started to attack p1 again, but the attack order is canceled and replaced with another attack order issued by this trigger, meaning that the continued attacks of p1 will interrupt p12's original attack orders already targeting p1. This means that the p12 unit will not be able to get an normal attack flow but will sort of be lagging by first starting to attack then starting to attack again, hitting, attacking, attacking hitting and so on :banghead:

I'm having a hard time explaining this... :rolleyes:

What I want instead is that the trigger will only be run if p12 is NOT attacking p1 but I haven't found any good way of dealing with it. Before I tried this trigger out I tried changing priority of heroes to 20 but that didn't work either, even if I specifically ordered an attack order on a unit, the unit continued it's previous attack order and target...

Ideas or any code is welcome. Thx.
 

Arkan

Nobody rides for free
Reaction score
92
Aren't priority values the other way around (1 being first priority)? Maybe I got it wrong, never bothered with it really.

If that doesn't work, you could have a countdown timer fire in your actions, say 3 seconds, and the trigger will only fire if the countdown timer is 0.00 sec.
 

snowtiger

New Member
Reaction score
1
AI
Events
Unit - A unit owned by Player 12 (Brown) Is attacked
Conditions
((Attacking unit) belongs to an ally of Player 1 (Red)) Equal to True
(Owner of (Attacking unit)) Not equal to Player 11 (Dark Green)
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Current order of (Picked unit)) Equal to (Order(<Empty String>))
Then - Actions
-------- order unit to attack --------
Else - Actions
 

Darkchaoself

What is this i dont even
Reaction score
106
That wont work, if the unit already attacking someone else, they wont attack the new attacking unit.
 

MoonSlinger

I Love using Cheap Tricks... only Results matters
Reaction score
74
I have 2 suggestions, might help

First way, you can make use of custom value for each unit.
Whenever a unit is ordered to attack (Player 1) set its custom value to "1"
Code:
Unit Group - Pick every unit in < Your group >
.. If Condition: (Custom value of (Picked unit)) Not equal to 1
.. Then
.. .. Unit - Order (Picked unit) to Attack (Attacking unit)
.. .. Unit - Set the custom value of (Picked unit) to 1


Second way would be to play with alliance. You can try the following:
(Player 12) neutral to (Player 1) and (Player 11)
(Player 11) hostile to (Player 1)

When a unit of (Player 12) is attacked by (Player 1), change ownership
Unit - Change ownership of (Attacked unit) to Player 11 (Dark Green) and Retain color

Note: you can replace (Player 11) with (Neutral Hostile) if you need that player slot. Just make sure the alliance is set properly
 

Lizzard

New Member
Reaction score
2
snowtiger: Will this really work:
Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Current order of (Picked unit)) Equal to (Order(<Empty String>))
Then - Actions
-------- order unit to attack --------
Else - Actions
Doesn't a unit that is currently attacking the attacking unit have an order? Meaning that the statement will always be true until the unit stands still, or does it have a stop order then to?.

darkchaoself: Are you replying to me? If so: Yes I know, that's why i have to make a trigger so that they will.
 

snowtiger

New Member
Reaction score
1
snowtiger: Will this really work:
Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Current order of (Picked unit)) Equal to (Order(<Empty String>))
Then - Actions
-------- order unit to attack --------
Else - Actions
Doesn't a unit that is currently attacking the attacking unit have an order? Meaning that the statement will always be true until the unit stands still, or does it have a stop order then to?.

It will be true when the unit is doing nothing. Wasn't that the meaning? I mean, else if there are 2 ranged units and they both attack the same unit, it would be running to one of them, but then before reaching it, it would return to the other hero and so on.
 

Lizzard

New Member
Reaction score
2
It will be true when the unit is doing nothing. Wasn't that the meaning? I mean, else if there are 2 ranged units and they both attack the same unit, it would be running to one of them, but then before reaching it, it would return to the other hero and so on.

Well if the unit is doing nothing and a hero approaches, it will attack the hero without any trigger. I want the unit to attack the hero also if it is attacking another unit and then is attacked by the hero. That is not normal behavior of a unit as far as i have seen.

And as darkchaoself said: "That wont work, if the unit already attacking someone else, they wont attack the new attacking unit."

But you made a good point with that if you have two heroes fighting the same unit it will mess up. I will have to work a way around that.

MoonSlinger: Thx, for the tips, I'll try them out.
 

snowtiger

New Member
Reaction score
1
Maybe create a unit group "AttackingPlayer"

And something in the lines of this?
AI
Events
Unit - A unit owned by Player 12 (Brown) Is attacked
Conditions
((Attacking unit) belongs to an ally of Player 1 (Red)) Equal to True
(Owner of (Attacking unit)) Not equal to Player 11 (Dark Green)
((Attacked unit) is in AttackingPlayer) Equal to False
Actions
Unit Group - Add (Attacked unit) to AttackingPlayer
Unit - Order (Attacked unit) to Attack (Attacking unit)


Now you only need to check if the unit stops attacking him... I don't directly find a code for that tough
 

Lizzard

New Member
Reaction score
2
Ok. Finally came up with this code :rolleyes: :
Code:
HeroAttackPriority
    Events
        Unit - A unit owned by Player 12 (Brown) Is attacked
    Conditions
        ((Owner of (Attacking unit)) is an ally of Player 1 (Red)) Equal to True
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Owner of (Attacking unit)) Not equal to Player 11 (Dark Green)
                (Custom value of (Attacked unit)) Equal to 0
            Then - Actions
                Unit Group - Pick every unit in (Units within 512.00 of (Position of (Attacked unit)) matching (((Owner of (Matching unit)) Equal to Player 12 (Brown)) and ((Custom value of (Matching unit)) Equal to 0))) and do (Actions)
                    Loop - Actions
                        Unit - Set the custom value of (Picked unit) to 1
                        Unit - Order (Picked unit) to Attack (Attacking unit)
            Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Custom value of (Attacked unit)) Greater than 0
                        (Owner of (Attacking unit)) Equal to Player 11 (Dark Green)
                    Then - Actions
                        Unit - Set the custom value of (Attacked unit) to 0
                        Wait 2.00 game-time seconds
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Custom value of (Attacked unit)) Equal to 0
                            Then - Actions
                                Unit - Order (Attacked unit) to Attack-Move To (Random point in Base)
                            Else - Actions
                    Else - Actions
What it simply does is that if one of p12's units is attacked the unit's custom value will be 1 and it will be ordered to attack the attacker (p1-p10). But if p11 is the attacker and the custom value is already 1, then the custom value will be set to 0 and a wait is applied, and if p1-p10 has not attacked the same unit after that (custom value is still 0), then the unit will be ordered to it's original order (attack-move). The last thing is because if you have ordered a unit to attack a unit, it seems that it will follow out that order no matter where the target goes (at least if it can see the target) and whatever attacks it. Which isn't maybe such a good idea if you retreat inside the base but after you is an army which all have the target for you.

What do you think about that? Any comments appreciated!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top