Jump to content
Sign in to follow this  
afp

ArmA 2 Awarness Script

Recommended Posts

Awarness Script v1.00

I kept wondering for a while why some missions are really intense and after an hour of playing you look like after an hour of football while some others are really boring. Some of the missions creators are aware of this but most of the people don't figure out this is a real issue.

I belive the main problem is that the GROUPS DO NOT SHARE CRITICAL INFORMATION. If a squad of 10 people start shooting in real life in an enemy city full of patrols, the next minute every enemy soldier will be alerted of it. Well, this does not happen in ArmA, as we can see in the movie bellow:

awarness.jpg

Even if the right soldier started shooting at me, the left one doesn't care even if he has a Sentry waypoint on him... It is just unnatural that after some gunfights to advance in the city or battlefield and find calm patrols moving slowly.

Most of the AI improvement scripts I have checked (DAC, Kronsky, Group Link) fix this but also add some overhead, especially with lot of enemies. I tried to find a lighter solution and to rely mostly on the game engine which is good enough and send everybody on you of they know about you. So what I did was to share information among groups in a "not processor intensive" manner and let the engine do the job.

It performed better than I expected since the engine takes a good decision of where to move the AI the if AI knows about two enemies or if AI decides to flank one. Here is the result:

It took 4 seconds for the second soldier to be alerted by my presence. My suggestion is to put some "intervention" groups in "guard" mode and add them to Awarness group or switch some patrols with a trigger to guard mode as described here.

Or you can put a helicopters group in guard mode on the other side of the map and add them to Awarness groups so as soon as you are seen they come after you. Cool, eh? The script makes the enemies more aggresive also the mission more intense.

I really expect suggestion / help for improving the script as this is my first script, heavily inspired by Kronsky UPS (many thanks). I just hope the idea here also will be inserted into the game engine to create a more realistic AI. Still some checkings have to be performed and maybe some code in case of respawn.

Full code bellow:



// Awarness Script v1.00 afp, December 2009
//
//
// Usage: 
// 1. add this script to your mission folder and call it at the beggining of "init.sqf" file, like that:
//      null = [] execVM "Awarness.sqf";
//
// 2. Add next row to the init field of the enemy groups leaders:
//      if (isNil ("afpEnemyGroups")) then {afpEnemyGroups=[]}; afpEnemyGroups = afpEnemyGroups + [group this];
//
// 3. Add next row to the init field of playable soldiers:
//      if (isNil ("afpPlayers")) then {afpPlayers=[]}; afpPlayers = afpPlayers + [this]; 



if (isNil("afpEnemyGroups")) then { afpEnemyGroups = []; };
if (isNil("afpPlayers")) then {	afpPlayers = []; };
if (!isServer) exitWith {};
sleep 4;
_playerIndex = 0;

// check for groups awarness
while {true} do 
{
// don't need to update too often
sleep 4; 

// first perform a fast check on groups to remove empty groups
// not sure about this (deleting an item while in array), maybe create another array is better
{
	if (isNull _x || count units _x <= 0) then
	{
		afpEnemyGroups = afpEnemyGroups - [_x];
	}; 
} foreach afpEnemyGroups;
sleep 0.01;

// select a new player every cycle
_player = afpPlayers select _playerIndex;
_playerIndex = _playerIndex + 1;
if (_playerIndex >= count afpPlayers) then { _playerIndex = 0};

// share information among enemy groups
_count = count afpEnemyGroups - 1;
_index = 0;
_ready = false;
while {(_index < _count && !_ready)} do
{	
	sleep 0.001;
	if ((afpEnemyGroups select _index) knowsAbout _player > 1) then 
	{
		{_x reveal _player } foreach afpEnemyGroups;
		_ready = true;
	};
	_index = _index + 1;
};
};

// every 4 seconds a player is updated - 15 players / minute which is a decent speed
// for most multiplayer games; for 50 players servers is fast enough because an enemy 
// group seeking for a player will self update knowsAbout for other players too

Download code and demo mission here

Edited by afp

Share this post


Link to post
Share on other sites
It is just unnatural that after some gunfights to advance in the city or battlefield and find calm patrols moving slowly.

This remembers me of what I've liked to do in ofp/resi:

  1. setup n patorls at/around a base/city, with "calm patrols" waypoints
  2. setup 2 triggers, each big enough to include all this patrols:

    1. player-side detected by enemy-patrols
    2. player-side not present

Maybe I used to have only the first trigger and use it's "deactivated" script instead of the second trigger, I don't remember. Anyway, all that is needed now are two scripts: one to engange/alarm all the patrols and one to disengage/set them back to calm patrols, once the intruder is gone/eliminated.

The nice thing about trigger's is, that you can retrieve all units inside the trigger, so we can pass thisList to the script, filter out all patrols (we can filter on group, unit-type or even completely customized with some set-/getVariable switches; for example we may cheat a little and have some special speznaz-soldiers sitting somewhere.. we filter them out and pass the intrudors/players current position to them once, creating a search-and-destroy wp for them, etc..). btw. overwriting current waypoints per script is very effective ;)

Such trigger's aren't very expensive, but rather effective! One trigger can manage as many groups/patrols as you like.

An additional idea would be to "count out" the battlefield/trigger-area. If too many patrols have died, we, resp. they, call in reinforcements. There, another very simple triggered event, that can result in big surprises! Just remember to slightly randomize the circumstances and results of such events. Send them early sometimes, too late other times... maybe you can even factor in some results the player may have already accomplished (you know: if C is done prior to engaging B, then it will be easier, etc..)

^^ for this latter approach I probably wouldn't rely on a trigger, but register all the patrols in a global array to run a script (fsm or while-loop with big delay) that checks on them. This should cost even less performance.

Hm, maybe I'll have to setup an example mission... I need to watch this myself again, but I'm pretty sure that such simple approaches (working with triggers) always did an impressive job. (but maybe my memories are a little bit decorated, hehe)

Anyway, I certainly agree that such "master-AI" scripts to model intelligent responses are really needed to make a mission believable. To make this happen, the mission designer should leave the player's perspective every now and then, and look at the mission from the bot's perspective: what are they doing? and what are they going to do, once the player arrives? etc..

Share this post


Link to post
Share on other sites

I made some "nomove" advanced observers with binoculars linked with about 6 or 7 guard mod intervention groups through awarness script. It performs pretty well, once you got spotted you can hardly get close on target without full engage. I only let some on hold to defend the objective as last line.

I think triggers are just expensive as any script loop, maybe they are implemented as loops, what's inside is important and time consuming. I very much agree the feeling is given by the way you made the mission and as a personal taste, by the smoothness of the gameplay.

Here is the script for binocular observer, just call it in init field like null=[this] execVM "name.sqf" etc. It just enlarge the binocular field of view by moving the observer left-right. Ussually I put a static machine gunner in the same group, so as soon as he observe someone, the mg open fire on a very long distance.

// "observer.sqf" - afp, December 2009
//
// make current unit an observer - stay still and look around
// the observer can be a spotter with binocular, sniper, M2 car, tank, static etc.
// usage: null = [this, false] execVM "observer.sqf" in init field
// first parameter is unit, second is true if you want to cover a wider area

if (!isServer) exitWith{};

_observer = _this select 0;
_observer allowFleeing 0;
doStop _observer;

_square = if (_this select 1) then {630} else {480};
_position = getPos _observer;
_alfa = getDir _observer;
_xBase = (_position select 0) + (sin (_alfa) * 500) - (_square / 2);
_yBase = (_position select 1) + (cos (_alfa) * 500) - (_square / 2);
if (_xBase < 0) then {_xBase = 0;};
if (_yBase < 0) then {_yBase = 0;};

while {alive _observer} do
{	
_newX = _xBase + random (_square);
_newY = _yBase + random (_square);
_newPosition = [_newX, _newY, _position select 2];
_observer doWatch _newPosition;
sleep (2.5 + random(1.8));
};

Edited by afp

Share this post


Link to post
Share on other sites

@ afp,

I'm taking my first steps into making a SP mission and I want to make enemy units smarter when I ran into your script.

You said that this script is highly recommended to be used in co-op missions.

Would it make sense to use it in SP missions too? Should it be used in SP mission?

Thanks much. -Splicer.

Share this post


Link to post
Share on other sites

Splicer, it can be used in SP too, you need to consider all your team as players. For performance reasons you may not want to add two full armies from the beggining, rather start with some small squad (1-4) on your side.

I'm also trying to design missions, its fun to make AI react smart. Later you can try more advanced scripts but I think it should be a balance between resources added and mission performance.

Share this post


Link to post
Share on other sites
Splicer, it can be used in SP too, you need to consider all your team as players. For performance reasons you may not want to add two full armies from the beggining, rather start with some small squad (1-4) on your side.

I'm also trying to design missions, its fun to make AI react smart. Later you can try more advanced scripts but I think it should be a balance between resources added and mission performance.

Hi afp,

Thanks for the info.

BTW, I've been looking into Monsada's USPMON and he uses a parameter to determine/calculate how close units have to be to each other to share information.

Do you have something like this in place too? I see you are using the knowsAbout parameter and, although I know about it only what the wiki says (returns a numerical value between 0 and 4), it is not clear to me how the knowsAbout command works and how you are actually using it here.

Thanks afp. Best, Splicer.

Share this post


Link to post
Share on other sites

Hi Splicer, the script doesn't have a maximum distance to share information. That's because I tried to keep the things simple and avoid computing too many distances - the engine already does it while deciding what to do an AI knowing about multiple enemies.

For example a group in guard mode won't attack if the enemy is too far.

Second reason would be that in real multiple people are conected to radio, so they all know about an enemy.

Anyway, I studied more and more AI behaviour and I try to find time to improve the script and come with additional ones. I am very much convinced that some improved AI system can be done, lighter than existing ones, based on game engine more than on a separate decision tree.

Share this post


Link to post
Share on other sites

Second reason would be that in real multiple people are conected to radio, so they all know about an enemy.

Hi afp,

Fair enough. I like your approach. :notworthy:

Like you, I also want to introduce more realism in the mission I'm putting together and sharing enemy spotting intel is key. HOWEVER, for the mission I'm putting together I have 2 questions for you:

1) Who has a radio on a team? The team leader or everybody in the team?

2) I want units to report back to HQ of enemy spotting to activate other triggers (i.e., have HQ send reinforcements via air drop). Have you considered such scenario in your awareness approach?

Thanks afp. Best, Splicer.

Share this post


Link to post
Share on other sites

Well the test I performed show that knowledge about an enemy is shared inside a group no matter the distance, so we can assume that everybody has a radio.

Yes, in my missions I also trigger other things when enemy is detected. For example I put the soldiers in a truck and bring them on the battlefield.

Its easy, just set a variable to true inside the script and add it to a trigger condition, for example "enemyDetected=true" and "?enemyDetected" inside trigger condition. Or you can check it inside the HQ script and perform the right procedure.

Right now I build a mission on 3 levels, observers, patrols and reaction groups. Both patrols and observers signal to reaction groups trying not to get involved. These reaction groups are generated from a camp so they respawn several times after they are dead to save resources. This way I have around 150 virtual enemies at the cost of about 30. They come in waves, pretty funny. I have played DAC missions like this too and its really intense.

Edited by afp

Share this post


Link to post
Share on other sites

One major problem I have noticed with such scripts when experimenting with them myself, is that "reveal" just doesn't give the AI enough information to act properly. It sets knowsAbout value to 1 which just doesn't seem to be enough in most cases. To get proper reactions you actually have to give them waypoints on top of the detected enemy's position, which requires a lot more complicated scripting, both on the performance level, and more importantly, on the logical level (when should the waypoint be created? Where should it move? etc.) - it leaves a lot of the decisions of how the AI should act to the mission maker, instead of letting the game AI handle those things themselves, and gets very complicated very fast.

Share this post


Link to post
Share on other sites

Yes indeed, that's why I didn't add waypoints or move commands. For short distances, with proper default waypoints (guard) they react as expected. Decision is ussually to engage the closest enemy, which is ok. When to add waypoints is let at mission maker decision.

Another thing is that keeping updating others with "reveal" makes "knowsAbout" rise to 3 or 4 after a while if other group engage the enemy and has its knowsAbout 4.

I don't want to make a whole system to replace default AI decisions which will affect performance in the end. I'm trying to find ways to adapt default AI to more needs.

My gameplay experience with or without such systems shows that a very complicated thing is not really needed, in the end if they come over you in the old Duke Nukem/Doom stile or they try to flank you is the most enjoyable experience. Watching them moving around is pretty much unrealistic.

Share this post


Link to post
Share on other sites

afp - try playing around with guard waypoints and guarded by triggers maybe you'll

find something there.

Place 3 guarded by triggers (no syncronisation needed) and place let's say 5 groups

on guard mode.

3 groups will go to the 3 triggers (can't remember how to determine which is going

where but you'll find that out easy me thinks) and 2 groups will stay at their starting

position.

Setdammage one group to death or do it the rambo way and use a pkm on a jeep :)

and you'll see one of the 2 reserve groups enter the scene - they might go directly

to the now empty guarded by trigger or a group of another guarded by trigger does

and the reserve takes their place instead.

Such a guarded by trigger on top of the players helmet could make one get really nervous.

Ah and btw - i saw in your first post something about the sentry wayoint.

Waypoint SENTRY does nothing else than let a unit wait to pass it until it detects

an enemy unit.

So in case of them not noticing that you are there - it wouldn't have helped at all - it

doesn't make them get knowledge of someone else it's more like you say "sit" to a dog

and the dog has to get up once you release him (in that case once he knowsabout an enemy unit).

~S~ CD

Share this post


Link to post
Share on other sites

Thanks Chriss, "guarded by" has a lot of potential indeed. I think it internally deals pretty much similar with "knowsAbout" and "reveal"...

"Guarded by OPFOR - Any OpFor squad with a Guard waypoint type will move to this trigger's location and await for ANY enemy contact on the ENTIRE island, then move there to engage the spotted enemy. Reference wiki for Guard waypoint type for more information on using this."

Very good details here too:

http://community.bistudio.com/wiki/Waypoint:Guard

Share this post


Link to post
Share on other sites

afp

may you upload demo mission somewhere

Share this post


Link to post
Share on other sites
afp

may you upload demo mission somewhere

I have updated the download link in the first post but the full script is also inside the post.

Share this post


Link to post
Share on other sites

If I use the script on the first post will I have every unit on the map zeroing in on my location instantly? There is mention there is no distance check so will I have to be extra careful on the waypoints and use GUARD waypoints carefully?

If there is a compound on the other side of the map I won't want them walking 10km across the map to get me. What are the limitations? Thx.

Share this post


Link to post
Share on other sites

Not sure about this script, but it seems like you want things that are easily available with UPSMON, where AI will share information up to pre-defined distance and will stay in their zone if you use the appropriate parameter.

Share this post


Link to post
Share on other sites

I have studied most of the available AI scripts, most of them add too much overhead for something that is not really needed. If you try to play an UPSMON mission with 10-15 players it lags too much. Other scripts like GroupLink or DAC just send AI over you in kamikaze waves, even if some of them have some internal optimisations.

I still think the default AI behaviour with a bit of help and awarness is a very good ballance of realism and speed.

Indeed, there are no distances involved, but ussually groups sharing information are around one objective, they cannot see players on the other side of the map. Designing a mission this way requires a bit more attention, while being a bit more "low-level".

Sharing information while players are in objective area makes AI react faster instead of standing still and being sniped from distance.

Share this post


Link to post
Share on other sites

@ afp

Thanks for the script and the other informations about the GUARD waypoints.

I have made a little example (OA needed) for you, can you please look at it and tell me what i could do better ?

I mean, the AI still is acting pretty stupid althought the GUARD Group with your script acts much better.

Example Mission:

DOWNLOAD

Just stay at you current position, take a look at the map for some more informations about groups and then shot at the patrol group (dont move !).

Now wait what will happen (maybe skip time fast forward).

Share this post


Link to post
Share on other sites

Yes, the mission is just a proof of concept that once detected, all groups will start to hunt the player. You can also check the UPS script, its more complex but easy to use for simple missions.

One thing that can be improved is to try to make AI to observe the player before the players see AI. This way you avoid to kill lot of AIs before they react.

There are several ways to do this:

1. place observers - remove all weapons, add binocular only, add some sniper or long range static machinegunnner in the same group and use observer script:

private ["_observer"];

_observer = _this select 0;

_observer setUnitPos "UP";

doStop _observer;

_observer allowFleeing 0;

removeAllWeapons _observer;

_observer addWeapon "binocular";

_observer selectWeapon "binocular";

sleep 0.5;

null = [_this select 0, _this select 1] execVM "observer.sqf";

Several good placed observers may see the players from long range. You can add them to the awarness groups too.

2. Add some vehicles having long range weapons. These will observe players from far longer distance. You can also make them patrol around the objective or look around with the observer script.

3. You can even add a patrol helicopter around the objective and share the awarness to some intervention groups.

There are many other ways too, I think a difficult mission is a nice mission, observing AI from long distance then start to masacre them its just too easy.

Also you can create some custom scripts, for example if some observer detected the player, he may inform others about it, something like this:

while (true)

{

sleep 3;

if (Observer1 knowsAbout Player && Player distance objective1 < 500) then

{

liderGroup1 reveal Player;

};

};

EDIT: you need to name all the players and use that names, for example p1, p2 etc.

Edited by afp

Share this post


Link to post
Share on other sites

I haven't noticed any lag with UPSMON, and neither did anyone else. If you have a lot of moving AI there will be lag regardless of what scripts you use. Scripts, as for themselves, cannot really lower FPS as the engine doesn't allow them to.

Share this post


Link to post
Share on other sites

Can you simply place a "spotter" OPFOR and "sync" him to a larger patrol (on guard setting).... Will he alert them of what he sees??? (without the need for any script or even trigger)??

Share this post


Link to post
Share on other sites

I would dearly love to see a patrol - for once - spot a dead body and actually react sensibly to it and not merely walk past.

guard1: "I say Harold, Frank is lying dead on the ground."

guard2: "You are right - that is Frank lying dead on the ground."

guard1: "How was your golf game on the weekend?"

:confused:

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  

×