Jump to content
Sign in to follow this  
ArmAriffic

How to keep bloody AI in one area

Recommended Posts

I am trying to make a team death match type mission with AI but I keep coming up with a problem, you see the damn AI just walk through cargo containers and do whatever they like, is there a way so that if they are NOT in a trigger area they get teleported to an invisible H (called US_BASE_1)

Share this post


Link to post
Share on other sites

You could define an area and command every A.I. unit with "move" to move back into the area when they are coming close to the border of the allowed area.

My example:

When you have an allowed area that is a circle with the radius "AREA", and the center "wpc1" you could have a loop checking all the time all units in concern:

areacheck.sqf:

the loop observing all units of the type "BAF_Soldier_L_DDPM":

if !(isServer) then { exit };

~1.0

_dist   = AREA +1;
_wpc   = [(position wpc1 select 0),(position wpc1 select 1),0];
_ptype = "BAF_Soldier_L_DDPM";

#start

_dist  = AREA + 1 + random(3);
_plist = [];

{ if ((typeof _x == _ptype) and (alive _x)) then {_plist = _plist + [_x]}} forEach allUnits;

{if (([(position _x select 0),(position _x select 1),0] distance _wpc) > _dist) then {[_x] exec "areacheck2.sqf"}} forEach _plist;

_wait = 1 + (random(2));
~_wait
goto "start";

exit;

areacheck2.sqf:

killing all players and A.I. that however leave the area:

_man = _this select 0;

if ( !(isServer) or !(alive _man) or ((_man distance wpc1) < AREA) ) then { exit };

_man allowdamage true;

_bomb = createVehicle ["R_57mm_HE", position _man, [], 0, "NONE"];
_bomb setDamage 1;

_man setdamage 1;

exit;

areacheck3.sqf:

tries to command an A.I. unit back into the allowed area (a random point within the half radius of the area):

_man = _this select 0;

if ( !(alive _man) or !(local _man) or (isPlayer _man) ) then { exit };

_x = position wpc1 select 0;
_y = position wpc1 select 1;
_dir = random 360;
_radius = AREA/2;
_finalpos = [(_x + (random _radius) * sin _dir), (_y + (random _radius) * cos _dir), 0];

_man domove (_finalpos);

exit;

Of course that is no 100% guarantee. The domove-command may not be observed when the unit is in combat and currently engaging/hunting an enemy. But I noticed a lot less amount of A.I. leaving the allowed area.

Edit: Think I mixed up something. Actually I have triggers observing the distance of every unit to the border of the allowed area. When they are closer than 5 meters to the border, they are commanded back into the central area:

activation: multiple
condition: (unit1 distance wpc1) > (AREA-5)
on activation: [unit1] exec "areacheck3.sqf"

So areacheck1 & 2 are just to kill any unit (player and ai) that makes it beyond the border.

The triggers and areacheck3.sqf are responsibly for trying to keep A.I. inside.

I also suggest to avoid "unnatural" processes like teleporting if possible. Seeing a unit disappear from its current position suddenly without "physical" or "logical" reason does not suit the world of ArmA.

Off topic: It would be great to have some editor objects being configurable like triggers or markers that can be used as invisible walls that A.I. never leaves/enters/crosses. Not being really able to restrict A.I to or exclude from certain areas can be quite annyoing.

Edited by RogueTrooper

Share this post


Link to post
Share on other sites

Could you please put that in a demo mission for me

EDIT: I got it, I was doing something wrong but now it works thanks

Edited by ArmAriffic

Share this post


Link to post
Share on other sites

and could you make me a cup of coffee while you're at it :D

Mate you'll learn a lot more if you try and get it working yourself as he's already done most of the work for you. If you get stuck then of course ask for some help....

Just my opinion of course, feel free to tell me to piss off ;)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×