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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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