Help with Defence

Progesterone

New Member
Reaction score
0
Dear all,
how do I make the computer units defend an important structure or area ? ie, every time enemy units are near the important structure/area, the AI will send all nearby units to defend it.
Thanks !
 

FhelZone

Have a drink of a nice cold mellowberry juice!
Reaction score
103
You may try to use a trigger but the default AI would also do... The default melee AI would always defend the town hall type units...
As for the trigger make a trigger like..

Unit is attacked

Life of attacked unit is less than 50% or something

set TempGroup = Units of type not equal to structure //you may add any other conditions
Pick all units in TempGroup
set TempPoint = position of attacked unit
order picked units to move to temp point
call RemoveLocation( udg_TempPoint)
call DestroyGroup( udg_TempGroup )
 

Aedes

Member
Reaction score
8
you can use UNIT IS ATTACKED or UNIT IS IN RANGE event. then order the units around to attack.
 

Moridin

Snow Leopard
Reaction score
144
If you want them to defend a certain zone, like an area around a certain structure, then you could do two things:

1) If you have the structures pre-placed (meaning you don't have any more built/placed during the game) then you can make regions around those structures and use a trigger like this:

Trigger:
  • Defend Region Trigger
    • Events
      • Unit - A unit enters Region Defend <gen>
      • ...add all your regions here
    • Conditions
      • (Triggering unit belongs to enemy of (<Your computer player>)) Equal to True -> Boolean comparison.
    • Actions
      • Unit Group - Pick all units in Defend_Group and do (multiple actions)
        • Loop - Actions
          • Unit - Order unit to Attack-Move to (Position of (Triggering unit))


You have to make sure that the units you want to defend are in Defend_Group, which is a unit group variable.

2) Otherwise, if you DO have more and more of these "important" structures popping up, you can do this one of two things:

a) Detect when an enemy unit comes within a certain range of a structure.
b) Detect when an enemy unit ATTACKS an important structure.

For a) You can use a periodic trigger (The event being a periodic time event, like every 1 second) and then check if any enemy unit is within a certain range of any of the important structures. You can use the Real Condition:

Math - Distance between two points

For b) You simply use the event:

Unit - A unit is attacked

...along with the condition

(Unit-type of (Triggering unit)) Equal to <Your important structure> -> This is a Unit-type condition

If you have many different structure types that are important, simply put an "Or - multiple conditions" and list the different unit-types under it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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