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.
 
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.
 
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
 
That wont work, if the unit already attacking someone else, they wont attack the new attacking unit.
 
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
 
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: 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.
 
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.
 
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
 
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 The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top