Jump to content
Ramsen II

No Aware Mode script - Need help.

Recommended Posts

I need help with the below script.

 

Problem: I read a post as far back as 2007 where units that enter combat mode and then get stuck in 'Aware' mode for the rest of mission (apart from combat / stealth of course). This issue is still present on A3. Once 'All Clear' is declared and my group goes back to safe mode, it actualy remains in AWARE mode, guns raised, looking for enemys.... i hate this when not leading a group and ai leads my group. Aware never ends.

 

I tried expriements with three simple radio triggers setting my group to 'COMBAT' 'SAFE' or 'CARELESS'

 

Selecting combat, safe, combat, safe still made the group stay in aware while safe mode was active, so switching on / off did not work.

 

However, forcing mode to CARELESS allowed my units to start walking normally, patrol style, guns down etc.

 

Objective: I am trying to create a script that creates the illusion of safe mode, but is actually CARELESS untill either:

 

a) enemys are in eye sight

b) knowsabout value is above zero (unreliable but a back up check)

c) my ai led group is surpressed by enemy gunfire

d) a bullet is detected close to the player.

e) enemy count is also above zero within _radius. But without giving away to the player ai led group.

 

The below script actually works o.k to a degree, no major performance lag despite it checking 8 times a second (for bullets). but i need help, you will only need to browse the script to see why.

 

Quote

_enemySides = [side player] call BIS_fnc_enemySides;
_radius = 800;
_group = grp1;
_led = leader _group;

while {alive player} do

    {

    _enemies = allUnits select {_x distance player < _radius AND side _x in _enemySides};
    _count = count _enemies;
    
    if (_count == 0) then

        {

        _group setbehaviour "careless";

        }

        else

        {

        _knows = {_group knowsabout _x} foreach _enemies;
        _surp = {getsuppression _x} foreach units _group;
        _unit = _enemies select 0;
        _los = if ({lineIntersects [eyepos _x, eyepos _unit, _x, _unit]} foreach units _group) then {false} else {true};

        if (_knows > 0 || _surp > 0 || {!isnull (nearestObject [_x, "Bulletbase"])} foreach units _group) then

            {

            if (_los) then

                {

                _group setbehaviour "aware";    

                sleep 6;

                };

            }

            else

            {

            _group setbehaviour "careless";

            };

        };

    sleep 0.1;

    };

 

 

 

bascially i need: All members of my group to check eyepos with all enemy units.

 

   _enemies = allUnits select {_x distance player < _radius AND side _x in _enemySides};

then testing count = count UNITS _enemies;

 

flags up an array error, but  _enemies = allunits (of the side east) so why this error? or should i say HOW do i select each unit of this unit and check its eyepos with all units in my group.

 

Also I want the script run less times a second but of course to 'catch a passing bullet' check i need it running often, but any better ideas welcome.

 

cheers. guys.

 

p.s thx to several members of this forum for bits of the above script, as its very cut and paste.... some of its mine honestly! lol.

  • Like 1

Share this post


Link to post
Share on other sites

I get around the problem by tying my AI squad's awareness to whether my weapon is raised or not. If my rifle is up, they go into aware mode, if it's lowered, they're back to safe. Very easy on the CPU

 

//Squad will only run around with raised weapons if you do

private ["_squad","_mode","_unit"];
while {alive player} do
	{
	_squad = group player;
	if (count units _squad > 1) then // only bother if there are actually people in the player's squad
		{
		_unit = units _squad select 1; 
		_mode = behaviour _unit; // current behaviour of 2nd squaddie
		if !(_mode == "STEALTH") then // don't bother changing awareness if squad is already in stealth mode
			{	
			if (weaponLowered player) then // weapon down?
				{
				_squad setbehaviour "safe"; // safe
				}
				else
				{
				_squad setbehaviour "aware"; // aware
				};
			};	
		};
	sleep random 5; // squad don't instantly follow
	};

 

 

  • Like 5

Share this post


Link to post
Share on other sites

Nice one, had to be another way round, will try this. thx. ;)

Share this post


Link to post
Share on other sites

Nice idea tpw but that works only for squads led by a player.

 

I'd use the following to apply it to all AI.

(Be aware I wrote this from scratch without any testing, so it may have flaws that still need to be ironed out).

Here goes:

while { true } do {
	_dist = 1000 max (getObjectViewDistance select 0);
	{
		if (local _x) then {
			_lead = leader _x;
			if !((behaviour _lead) isEqualTo "STEALTH") then {
				if ( (count (_lead targets [true, _dist, [], 300])) > 0 ) then {
					_x setBehaviour "COMBAT";
				} else {
					if ( (count (_lead targets [true, _dist, [], 600])) > 0 ) then {
						_x setBehaviour "AWARE";
					} else {
						if ( (count (_lead targets [true, _dist, [], 900])) > 0 ) then {
							_x setBehaviour "SAFE";
						} else {
							_x setBehaviour "CARELESS";
						};
					};
				};
			};
		};
	} count allGroups;
	sleep 10;
};

 

Every 10 seconds, the script will query all groups and check if they know about any targets within viewing distance (1000m or more if the user has set a higher distance). Target age is used to let their behavior decay towards careless (in steps of 5 minutes each, so if their last known target is older than 15minutes, they go back to careless. If they know about no targets at all, they go to careless immediately).

 

Groups set to "stealth" are ignored.

 

The Script should be spawned from init, for all clients because I check only groups that are local. (this balances the load a bit and makes sure that target knowledge data is accurate)

 

 

 

I'll give it a test run later today, when I get home. Let me know how it works for you.

 

 

ps.: I think the 10s delay should be ok but if you need them to react faster to direct fire, then I suggest using "firedNear" Eventhandlers to supplement it. (can also give you an example for that if needed)

Edited by Tajin
fix
  • Like 3

Share this post


Link to post
Share on other sites

Awesome @Tajin, would definitely make enemy appear "normal" when combat subsides. Look forward to seeing how this script develops.

Share this post


Link to post
Share on other sites

@Tajin If your script was still in play, was this something you might want to know about?

 

S0fJe9Z.png

  • Thanks 1

Share this post


Link to post
Share on other sites

My bad, missed a parameter there.

* changed it *

Share this post


Link to post
Share on other sites
11 minutes ago, Tajin said:

My bad, missed a parameter there.

* edited it now *

 

Hoping not to misunderstand whether you meant you are still editing, or have edited? The code further up is now modified?

Share this post


Link to post
Share on other sites
2 hours ago, Tajin said:

It is.

 

Thank you!

edit: @Tajin I'm going to say I'm more than likely at fault here but I am getting the same error and when I use your modified code above. :eh:

When I compare, it seems to be the exact same as when it was originally posted 4 October. Perhaps I am looking at the wrong post? Sorry for the bother and thanks for your time. :grinning:

Share this post


Link to post
Share on other sites

No, you're right it apparently didn't update the post.

Try now.

Share this post


Link to post
Share on other sites

@Tajin

Out of courtesy, I thought I would let you know that the script works. I even tested with waypoints and the "safe" AI resume waypoints after losing contact. :thanx:

  • Like 1

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

×