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

How to create an AI that seeks out and attacks like the one in Fortress Survival

Status
Not open for further replies.
If your map already has Player Start Location set, then you can do this:
  • Trigger
  • Events
    • Unit - A unit finishes training a unit
  • Conditions
  • Actions
    • For each (IntegerA) from 1 to 10, do (Actions)
      • Loop - Actions
        • Set Points[(IntegerA)] = ((Player(IntegerA))'s Start Location)
        • Unit - Order (Trained unit) to Attack - Move to (Points[(Random Integer number between 1 and 10)])
        • Custom script: call RemoveLocation (udg_Points[bj_forLoopAIndex])
P.S. This is not the solution, this is how to get it started.

You can also make regions, that checks if the Owner of Picked unit is Equal to Neutral Hostile/Passive and, if not, then order your units to go on that region.
In the World Editor, create a region on every Player's Start Location. Then, do this:
  • Tr
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set Regions[1] = (Region 000 <gen>)
    • Set Regions[2] = (Region 001 <gen>)
    • ...
    • Set Regions[10] = (Region 010 <gen>)
  • Trig
  • Events
    • Unit - A unit finishes training a unit
  • Conditions
  • Actions
    • For each (IntegerA) from 1 to 10, do (Actions)
      • Loop - Actions
        • Set Temp_Group = (Units in Region[(IntegerA)])
        • Unit Group - Pick every unit in (Temp_Group) and do (Actions)
          • Loop - Actions
            • If (All conditions are true) then do (Actions) else do (Actions)
              • If - Conditions
                • Or - Conditions
                  • (Owner of (Picked unit)) Not Equal to Neutral Passive
                  • (Owner of (Picked unit)) Not Equal to Neutral Hostile
              • Then - Actions
                • Set Point1 = (Center of (Regions[(IntegerA)])
                • Unit - Order (Trained unit) to Attack - Move to (Point1)
                • Custom script: call RemoveLocation (udg_Point1)
              • Else - Actions
        • Custom script: call DestroyGroup (udg_Temp_Group)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
You can set all (enemy) buildings into a unit group, and then order them to attack-move to a position of random unit from the unit group.

Or you can order them to attack closest unit or building, this is the trigger that selects closest unit:

  • Closest Unit
    • Events
    • Conditions
    • Actions
      • Set Temp_Unit_1 = The unit you want to order to do something
      • Set Temp_Loc_1 = (Position of Temp_Unit_1)
      • Set Temp_Real_1 = 9999999.00
      • Set Temp_Group_1 = (Units in (Playable map area) matching (Temp_Unit_1 Not equal to (Matching unit))) // select all units you want to compare the distance to
      • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_2 = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Loc_1 and Temp_Loc_2) Less than Temp_Real_1
            • Then - Actions
              • Set Temp_Unit_2 = (Picked unit)
              • Set Temp_Real_1 = (Distance between Temp_Loc_1 and Temp_Loc_2)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Temp_Loc_2)
      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • Custom script: call DestroyGroup(udg_Temp_Group_1)
      • // The closest unit to Temp_Unit_From the unit group will be saved to Temp_Unit_2
You can also periodically pick all zombies and check their current order. If it equals to empty string, order them to do something.
 
Status
Not open for further replies.
Top