• 🏆 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!

AI withing range

Status
Not open for further replies.
Level 24
Joined
Feb 9, 2009
Messages
1,787
Why a periodic trigger that picks all units around your AI hero within a specific range under those specific conditions!

Ex.
  • Untitled Trigger 001
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set U_Group (Units within 500.00 of (Position of Orc Warlock 0001 <gen>))
      • Unit Group - Pick every unit in U_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
              • ((Picked unit) belongs to an enemy of (Owner of Orc Warlock 0001 <gen>)) Equal to True
              • (Percentage life of (Picked unit)) Less than or equal to 30.00
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Life of (Picked unit)) Less than (Life of EnBa_Target[1])
                      • EnBa_Target[1] Equal to No unit
                • Then - Actions
                  • Set EnBa_Target[1] = (Picked unit)
                • Else - Actions
            • Else - Actions
      • Unit - Order Orc Warlock 0001 <gen> to Attack EnBa_Target[1]
      • Set EnBa_Target[1] = No Unit
      • Custom script: call DestroyGroup(udg_U_Group)

ETA: Cleaning my lazy ass mistakes
 
Last edited:
Level 11
Joined
Apr 27, 2009
Messages
202
Can you explane me why are we checking life of the picked of the picked unit?

  • (Life of (Picked unit)) Less than (Life of EnBa_Target[1])
Isn't
  • (Life of (Picked unit))
same as this
  • EnBa_Target[1]
cause
  • Set EnBa_Target[1] = (Picked unit)
is the picket unit

Haven't we done the checking hero if he is alive and has 30% of the health?
  • ((Picked unit) is alive) Equal to True
  • ((Picked unit) belongs to an enemy of (Owner of Orc Warlock 0001 <gen>)) Equal to True
  • (Percentage life of (Picked unit)) Less than or equal to 30.00
 
Last edited:
Level 24
Joined
Feb 9, 2009
Messages
1,787
The idea is to get the lowest health target, the first unit encountered is set to be saved, when the next unit is selected it is compared to the saved unit, if their health is lower it becomes the saved unit for targeting.

Ex. 5 footman with %30, %0 (dead), %21, %5, & %60 health
  • The footmen with %0 & %60 are ignored as they are blocked by the conditions for being deadbeat losers who have no business bothering our super intelligent AI who has better things to do then deal with foppish twits
Now we are left with %30, %21, & %5, for this example let's assume that 21% is chosen first and saved to EnBa_Target[1]:
  • (picked unit) %30's health is compared EnBa_Target[1]
    - EnBa_Target[1]'s health is lower than %30's so we do not change EnBa_Target[1]
Lastly we are left with only EnBa_Target[1] (21%) & %5 footmen:
  • (picked unit) %5's health is compared EnBa_Target[1]
  • EnBa_Target[1]'s health is higher than %5's so we do change EnBa_Target[1] to the (picked unit) resulting in the lowest health target being selected!

When I filled out the previous example I was rather hasty, (note the "Custom script: call DestroyGroup thing idk lazy to remembr")
If you plan on using it be sure to set EnBa_Target[1] = no unit after ordering the hero, along with the proper usage of the group destruction:

*Credit to Busterkomo's Complete list of things that leak* :
  • Set Group = (Units in (Playable map area))
  • Unit Group - Pick every unit in Group and do (Actions)
  • Loop - Actions
  • Unit - Remove (Picked unit) from the game
  • Custom script: call DestroyGroup(udg_Group)
 
Last edited:
Level 11
Joined
Apr 27, 2009
Messages
202
Great i now undrestood why you done it so. Thanks man.

Can you tell me where should i put Custom script: call DestroyGroup cause i don't understand anything about it "Custom script: call DestroyGroup ..." ?

  • AI Move attack low health
    • Events
      • Time - Every 20.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in AIGroup and do (Actions)
        • Loop - Actions
          • Set PicketAi = (Picked unit)
          • Unit Group - Pick every unit in (Units within 512.00 of (Position of (Picked unit))) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is alive) Equal to True
                  • ((Picked unit) belongs to an enemy of (Owner of PicketAi)) Equal to True
                  • (Life of (Picked unit)) Less than or equal to 30.00
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Life of (Picked unit)) Less than or equal to (Percentage life of LowestHealth[1])
                          • LowestHealth[1] Equal to No unit
                    • Then - Actions
                      • Set LowestHealth[1] = (Picked unit)
                    • Else - Actions
                • Else - Actions
          • Unit - Order PicketAi to Attack LowestHealth[1]

Why "Unit - Remove (Picked unit) from the game" would that remove the unit??
 
Last edited:
Level 24
Joined
Feb 9, 2009
Messages
1,787
You're creating an Ouroboros.
AIGroup1 is looking for units within range of the position of the picked units within range of picked units within range...etc.

Change "Unit Group - Pick every unit in (Units within 512.00 of (Position of (Picked unit))) and do (Actions)"
To "Unit Group - Pick every unit in (Units within 512.00 of (Position of PicketAi)) and do (Actions)"

I"ll be able to fully flesh this out once I get home, keep experimenting and look at that link regarding leaks to brush up!


ETA: Tested, works just fine
Map init (this is to establish your ai hero)
  • Map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup=true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Matching unit) Equal to Orc Warlock 0001 <gen>)) and do (Actions)
        • Loop - Actions
          • Set My_AIHero = (Picked unit)
Periodic
  • Periodic
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Set My_AIHero_Location = (Position of My_AIHero)
      • Set My_AIHero_Group = (Units within 2000.00 of My_AIHero_Location)
      • Unit Group - Pick every unit in My_AIHero_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
              • (Percentage life of (Picked unit)) Less than or equal to 30.00
              • ((Picked unit) belongs to an enemy of (Owner of My_AIHero)) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Life of (Picked unit)) Less than (Life of My_AIHero_Target)
                      • My_AIHero_Target Equal to No unit
                • Then - Actions
                  • Set My_AIHero_Target = (Picked unit)
                • Else - Actions
            • Else - Actions
      • Unit - Order My_AIHero to Attack My_AIHero_Target
      • Special Effect - Create a special effect attached to the origin of My_AIHero_Target using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
      • Special Effect - Destroy (Last created special effect)
      • Set My_AIHero_Target = No unit
      • Custom script: call RemoveLocation(udg_My_AIHero_Location)
      • Custom script: call DestroyGroup(udg_My_AIHero_Group)
 
Last edited:
Status
Not open for further replies.
Top