• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Prevent unit from target allies

Status
Not open for further replies.
Level 6
Joined
Jan 2, 2015
Messages
171
i am making semi auto unit. I want the unit to cast the spell when he is attacked on enemy unit. but the problem is..if there is ally near him..he will target it because i set the trigger to pick any unit within 300 around him..so any unit include ally and enemy will be picked. how do i prevent this? is it possible to pick enemy unit behind him so it looks like semi boss fight?

  • Ai
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacked unit)) Equal to Archimonde
    • Actions
      • Set Demon = (Attacked unit)
      • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)))
      • Set Chance = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance Less than or equal to 15
        • Then - Actions
          • Unit Group - Pick every unit in (Random 1 units from Temp_Group) and do (Actions)
            • Loop - Actions
              • Unit - Order Demon to Undead Crypt Lord - Impale (Position of (Picked unit))
        • Else - Actions
 
Level 5
Joined
Jan 17, 2014
Messages
131
Simple. You just need a matching condition.
Example:
  • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)) matching (((Matching unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to True))
P.S. Since you are using a random unit from the group you should make that matching condition an "And" condition. The first condition to exclude ally units (like in the example above), and the second condition to exclude dead units from the group (when picking up units, dead units are being picked as well).

Final result:
  • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)) matching ((((Matching unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to True) and (((Matching unit) is alive) Equal to True)))
 
Last edited:
Level 6
Joined
Jan 2, 2015
Messages
171
Simple. You just need a matching condition.
Example:
  • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)) matching (((Matching unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to True))
P.S. Since you are using a random unit from the group you should make that matching condition an "And" condition. The first condition to exclude ally units (like in the example above), and the second condition to exclude dead units from the group (when picking up units, dead units are being picked as well).

Final result:
  • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)) matching ((((Matching unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to True) and (((Matching unit) is alive) Equal to True)))

what if i want it to not targetting flying unit. just ground unit?
 
Level 5
Joined
Jan 17, 2014
Messages
131
what if i want it to not targetting flying unit. just ground unit?

Then you add another "And" condition (Boolean Comparison > Unit - Unit Classification Check).

  • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)) matching ((((Matching unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to True) and ((((Matching unit) is A flying unit) Equal to False) and (((Matching unit) is alive) Equal to True))))
Edit: Attached a test map.
 

Attachments

  • Test Map for ninehell.w3x
    13 KB · Views: 53
Last edited:
Level 6
Joined
Jan 2, 2015
Messages
171
Then you add another "And" condition (Boolean Comparison > Unit - Unit Classification Check).

  • Set Temp_Group = (Units within 300.00 of (Position of (Attacked unit)) matching ((((Matching unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to True) and ((((Matching unit) is A flying unit) Equal to False) and (((Matching unit) is alive) Equal to True))))
Edit: Attached a test map.

if i make 3 spell with chance to cast it. will it work? i dont want the 3 spell to be cast at the same time.. it will make the unit stuck
 
Level 5
Joined
Jan 17, 2014
Messages
131
if i make 3 spell with chance to cast it. will it work? i dont want the 3 spell to be cast at the same time.. it will make the unit stuck

Depends on how you want them to be. Do you want it to have 15% chance to cast 1 of the 3 spells, or each spell to have it's own chance to be cast? You also have to consider the spells cooldowns in order not to cast a spell that is on cooldown (which will do nothing).
 
Level 6
Joined
Jan 2, 2015
Messages
171
Depends on how you want them to be. Do you want it to have 15% chance to cast 1 of the 3 spells, or each spell to have it's own chance to be cast? You also have to consider the spells cooldowns in order not to cast a spell that is on cooldown (which will do nothing).

i want each spell has its own chance to be cast but what will happen if two spell with different chance triggered? do i have to worry about it?
 
Level 5
Joined
Jan 17, 2014
Messages
131
i want each spell has its own chance to be cast but what will happen if two spell with different chance triggered? do i have to worry about it?

Well, it needs to be tested (it will probably cast 1 of the triggered spells). When more than 1 spells are triggered, what do you want to happen, cast 1 of the triggered spells, or cast every one that's triggered?
 
Last edited:
Level 6
Joined
Jan 2, 2015
Messages
171
Well, it needs to be tested (it will probably cast 1 of the triggered spells). When more than 1 spells are triggered, what do you want to happen, cast 1 of the triggered spells, or cast every one that's triggered?

if more than 1 spells are triggered..i want it to cast one of the triggered spells to prevent it to cast 2 spell at the same time because it will make the unit stuck.
 
Level 5
Joined
Jan 17, 2014
Messages
131
Tricky, but I don't think it's impossible. Still, if I were you, I'd make it to have that 15% chance to cast 1 of the 3 spells at random. And if the chosen spell is on cool down, then cast one of the other 2.
 
Level 5
Joined
Jan 17, 2014
Messages
131
good suggestion..how to do that?

Well, you know how you run a random value between 1 and 100, exactly like that, but you run it after it is 15 or less and this time you run a number between 1 and 3 and then an If/Then/Else: if value is 1 then cast spell 1, if value 2 - spell 2 and 3 - 3. As for spell cool downs, it will be a little more complicated there.
 
Level 6
Joined
Jan 2, 2015
Messages
171
Well, you know how you run a random value between 1 and 100, exactly like that, but you run it after it is 15 or less and this time you run a number between 1 and 3 and then an If/Then/Else: if value is 1 then cast spell 1, if value 2 - spell 2 and 3 - 3. As for spell cool downs, it will be a little more complicated there.

  • Trigger 1
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Molten Giant
    • Actions
      • Set Chance = (Random integer number between 1 and 100)
      • Set AbilityValue = (Random integer number between 1 and 3)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance Less than or equal to 5
        • Then - Actions
          • Set Temp_Location = (Position of (Triggering unit))
          • Set Temp_Group = (Units within 300.00 of Temp_Location matching (((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Matching unit) is A flying unit) Equal to False)) and ((((Matching unit) is alive) Equal to True) and (((Matching uni
          • Unit Group - Pick every unit in (Random 1 units from Temp_Group) and do (Actions)
            • Loop - Actions
              • Custom script: call RemoveLocation(udg_Temp_Location)
              • Set Temp_Location = (Position of (Picked unit))
              • Unit - Order (Triggering unit) to Undead Crypt Lord - Impale Temp_Location
          • Custom script: call DestroyGroup(udg_Temp_Group)
          • Custom script: call RemoveLocation(udg_Temp_Location)
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AbilityValue Equal to 1
        • Then - Actions
          • Set Temp_Location = (Position of (Triggering unit))
          • Set Temp_Group = (Units within 300.00 of Temp_Location matching (((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Matching unit) is A flying unit) Equal to False)) and ((((Matching unit) is alive) Equal to True) and (((Matching uni
          • Unit Group - Pick every unit in (Random 1 units from Temp_Group) and do (Actions)
            • Loop - Actions
              • Custom script: call RemoveLocation(udg_Temp_Location)
              • Set Temp_Location = (Position of (Picked unit))
              • Unit - Order (Triggering unit) to Undead Crypt Lord - Impale Temp_Location
          • Custom script: call DestroyGroup(udg_Temp_Group)
          • Custom script: call RemoveLocation(udg_Temp_Location)
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AbilityValue Equal to 2
        • Then - Actions
          • Set Temp_Location = (Position of (Triggering unit))
          • Set Temp_Group = (Units within 300.00 of Temp_Location matching (((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Matching unit) is A flying unit) Equal to False)) and ((((Matching unit) is alive) Equal to True) and (((Matching uni
          • Unit Group - Pick every unit in (Random 1 units from Temp_Group) and do (Actions)
            • Loop - Actions
              • Custom script: call RemoveLocation(udg_Temp_Location)
              • Set Temp_Location = (Position of (Picked unit))
              • Unit - Order (Triggering unit) to Human Mountain King - Storm Bolt (Matching unit)
          • Custom script: call DestroyGroup(udg_Temp_Group)
          • Custom script: call RemoveLocation(udg_Temp_Location)
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AbilityValue Equal to 3
        • Then - Actions
          • Set Temp_Location = (Position of (Triggering unit))
          • Set Temp_Group = (Units within 300.00 of Temp_Location matching (((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Matching unit) is A flying unit) Equal to False)) and ((((Matching unit) is alive) Equal to True) and (((Matching uni
          • Unit Group - Pick every unit in (Random 1 units from Temp_Group) and do (Actions)
            • Loop - Actions
              • Custom script: call RemoveLocation(udg_Temp_Location)
              • Set Temp_Location = (Position of (Picked unit))
              • Unit - Order (Triggering unit) to Orc Tauren Chieftain - War Stomp
          • Custom script: call DestroyGroup(udg_Temp_Group)
          • Custom script: call RemoveLocation(udg_Temp_Location)
        • Else - Actions
          • Do nothing
is it like this?
 
Status
Not open for further replies.
Top