• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Need help with IA archers defending area

Status
Not open for further replies.
Level 13
Joined
Oct 28, 2019
Messages
523
In this the IA enemy archers advance:
  • ArchersAdvance
    • Events
      • Unit - A unit enters ArchersAttack <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
    • Actions
      • Game - Display to (All players) the text: Advance
      • Unit Group - Order VillageArchersLeft to Attack-Move To (Center of VillageArchersADVleft <gen>)
      • Unit Group - Order VillageArchersRight to Attack-Move To (Center of VillageArchersADVright <gen>)
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on ArchersBackDefensivePosition <gen>
In this they return to normal position
  • ArchersBackDefensivePosition
    • Events
      • Unit - A unit leaves ArchersAttack <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
      • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Warrior))) Less than or equal to 1
      • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Dwarf))) Less than or equal to 1
      • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Archer))) Less than or equal to 1
    • Actions
      • Game - Display to (All players) the text: Back
      • Unit Group - Order VillageArchersLeft to Move To (Center of ArchersLeft <gen>)
      • Unit Group - Order VillageArchersRight to Move To (Center of ArchersRight <gen>)
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on ArchersAdvance <gen>
If a player human (1) enter the area the enemies archers advance in position, the problem is when they back to normal stance. No one human player unit must have in the area, unless dwarf landmines, Im not gettin how this can be done
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
First I would "fix" your Regions so that they work properly:
  • Region Fixer
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: local rect r
      • -------- --------
      • -------- Set this to the number of Regions you want to fix: --------
      • Set VariableSet RegionFixer_Count = 2
      • -------- --------
      • -------- Assign each Region you want to fix: --------
      • Set VariableSet RegionFixer_Region[1] = Archer Trigger Region <gen>
      • Set VariableSet RegionFixer_Region[2] = Archer Starting Region <gen>
      • -------- --------
      • -------- Once our variables are setup, loop through all of the Regions and adjust them so that they have the correct size: --------
      • For each (Integer A) from 1 to RegionFixer_Count, do (Actions)
        • Loop - Actions
          • Custom script: set r = udg_RegionFixer_Region[bj_forLoopAIndex]
          • Custom script: call SetRect(r, GetRectMinX(r) - 32., GetRectMinY(r) - 32., GetRectMaxX(r) + 32., GetRectMaxY(r) + 32.)
          • Custom script: set r = null
Regions have issues related to their coordinates which can make the Enters/Leaves Events run before the Unit is actually in/out of the Region. This makes Conditions like "Is unit in Region" fail in cases where you'd expect it to work.

Then you can use an Integer variable and Unit Group variable to determine how many units are in your region. Here are the triggers.

First, add 1 to our Integer and check if it's equal to 1 when we enter the region. If it is 1 then the archers should advance forward:
  • Enter Region
    • Events
      • Unit - A unit enters Archer Trigger Region <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to User
      • (Unit-type of (Triggering unit)) Not equal to Goblin Land Mine
    • Actions
      • Set VariableSet Units_In_Region = (Units_In_Region + 1)
      • Unit Group - Add (Triggering unit) to Enter_Group
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Units_In_Region Equal to 1
        • Then - Actions
          • Unit Group - Pick every unit in Archer_Group and do (Actions)
            • Loop - Actions
              • Unit - Order (Picked unit) to Attack-Move To (Center of Archer Advance Region <gen>)
          • Trigger - Turn on Unit Dies In Region <gen>
        • Else - Actions
Next, subtract 1 from our Integer and check if it's equal to 0 when we leave the region. If it is 0 then there are zero units in the region:
  • Exit Region
    • Events
      • Unit - A unit leaves Archer Trigger Region <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to User
      • (Unit-type of (Triggering unit)) Not equal to Goblin Land Mine
    • Actions
      • Set VariableSet Units_In_Region = (Units_In_Region - 1)
      • Unit Group - Remove (Triggering unit) from Enter_Group.
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Units_In_Region Equal to 0
        • Then - Actions
          • Unit Group - Pick every unit in Archer_Group and do (Actions)
            • Loop - Actions
              • Unit - Order (Picked unit) to Move To (Center of Archer Starting Region <gen>)
          • Trigger - Turn off Unit Dies In Region <gen>
        • Else - Actions
Also, a unit dying doesn't make it "leave" a region so we need to account for this:
  • Unit Dies In Region
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in Enter_Group.) Equal to True
    • Actions
      • Trigger - Run Exit Region <gen> (ignoring conditions)
This will ensure that the archers only advance when there's a unit in the region owned by a User that ISN'T a goblin land mine (change it to dwarf land mine in your case). I assume when you said Human player you meant a User.

Note that these triggers leak a Point whenever we order the units to move/attack-move to the (Center) of a region.
You're also leaking A LOT of Unit Groups by doing this:
  • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Warrior)))
 

Attachments

  • Archer Advance Demo 1.w3m
    19.9 KB · Views: 3
Last edited:
Level 13
Joined
Oct 28, 2019
Messages
523
I´ve fixed this way and is working.

  • ArchersBackDefensivePosition
    • Events
      • Unit - A unit leaves ArchersAttack <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
      • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Warrior))) Less than or equal to 1
      • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Dwarf))) Less than or equal to 1
      • (Number of units in (Units in ArchersAttack <gen> matching ((Unit-type of (Matching unit)) Equal to Archer))) Less than or equal to 1
    • Actions
      • Game - Display to (All players) the text: Back
      • Unit Group - Order VillageArchersLeft to Move To (Center of ArchersLeft <gen>)
      • Unit Group - Order VillageArchersRight to Move To (Center of ArchersRight <gen>)
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on ArchersAdvance <gen>
 
Status
Not open for further replies.
Top