Jump to content

Sign in to follow this  
Nephris1

AI reacting on flare

Recommended Posts

Hi friends,

today i played around with some behaviourd of AI at night.

1. AI reacts on enemy at night (0:00h) at a distance of max 30m

2. AI dont notice enemies at 40m, even if i triggered a flare.

I changed the skill from 1% to 100%, what made no differences.

The enemy (me) was just walking on the radius to test at.

As soon as i do a shot (even from 200m) the AI react directly, with precise shots.

So i know AI doesnt react on any "viewabout" but "knowsabout" command.

Nevertheless i hoped the knowsabout value would increase at night if a flare lighten a territory with an enemy is walking by.

Do u have any ideas how to make AI to react on enemies if they are lighten up with a flare?

Edited by Nephris1

Share this post


Link to post
Share on other sites

Yeah, wouldn't we all :)

Either ES onFlare or EH fired.

Here is what I used as fired eventhandler:

private ["_ammo","_types","_dummy","_color","_r","_g","_b","_delay","_pos","_radius","_i","_groupsenemy","_groupsfriendly","_unitsEnemy","_unitsFriendly"];
_shooter = _this select 0;
_ammo = _this select 4;
_groupsenemy = [];
_groupsfriendly = [];
_unitsenemy = [];
_unitsfriendly = [];
_types = ["F_40mm_White","F_40mm_Yellow","F_40mm_Green","F_40mm_Red"];
if !(_ammo in _types) exitWith {};
_delay = time + 1;
waitUntil {!isNull nearestObject [player, _ammo] || time > _delay}; //BIS, PLEASE give us object reference from "fired" eventhandler.
if (time > _delay) exitWith {}; //Failsafing. Exiting prevents error messages.
_dummy = nearestObject [_shooter, _ammo];
_color = getArray (configFile >> "CfgAmmo" >> typeOf _dummy >> "lightColor");
_r = _color select 0;
_g = _color select 1;
_b = _color select 2;
sleep 1.4; //Not sure how to look up the correct value, or even find it, but this is close enough for current ignition delay.

//Make an array of units in the vicinity of the flare
_pos = [getPos _dummy select 0, getPos _dummy select 1, 0];
_radius = 133 * (_r + _g + _b); //Gives 200m for a white flare since base vanilla value is 0.5
for "_i" from 0 to (count allGroups) - 1 do {
if(side (allGroups select _i) != playerside) then {
	if (leader (allGroups select _i) distance _pos < _radius) then {
		_groupsenemy set [count _groupsenemy, allGroups select _i];
		sleep 0.012;
	};
} else {
	if (leader (allGroups select _i) distance _pos < _radius) then {
		_groupsfriendly set [count _groupsfriendly, allGroups select _i];
		sleep 0.012;
	};
};
};
for "_i" from 0 to (count _groupsenemy) do {
{_unitsEnemy set [count _unitsenemy, _x]} forEach units leader (_groupsenemy select _i);
sleep 0.012;
};
for "_i" from 0 to (count _groupsfriendly) do {
{_unitsFriendly set [count _unitsfriendly, _x]} forEach units leader (_groupsfriendly select _i);
sleep 0.012;
};
sleep 5; //Artificial delay to make units "study the surroundings" a little more. Already way too powerful.
for "_i" from 0 to (count _groupsfriendly) - 1 do {
{(leader (_groupsfriendly select _i)) reveal _x} forEach _unitsEnemy;
sleep 0.012;
};
for "_i" from 0 to (count _groupsenemy) - 1 do {
{(leader (_groupsenemy select _i)) reveal _x} forEach _unitsFriendly;
sleep 0.012;
};
_groupsenemy = nil;
_groupsfriendly = nil;
_unitsenemy = nil;
_unitsfriendly = nil;

Note the number of for next and forEach loops - not good, even if the for next loops have some builtin delays. My _radius value is set quite small, since I at the time couldn't figure out a way to cause a correct behaviour (not hard btw), but more importantly, couldn't find a way to check for validity of reveal. I.e. you might base

{_unitsEnemy set [count _unitsenemy, _x]} forEach units leader (_groupsenemy select _i);

on the stance and speed of _x. The correct reaction procedure is to lay down and stay still, and anyone doing that would have a greater chance of not get added to the array. Also there is the lacking canSee command which would have been helpful here - if _x is hidden from view by building etc, then he is not added the array.

So this is way from perfect (or even usable in terms of realism), but at least it manages to get the action going instead of being stupidly blind.

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

Hi Carl,

thx for your effort posting your script.

I tried to get it working.

My EH executes but i cant notice a difference on AI behaviour.

Perhabs i am missing something.

I created a testmission ,if u r interested to have a look, i would appreciate that.

As this feature is imho a very interesting one, the more for earlier battle campaigns before NVGoggles.

Nevertheless it is a bit annoying that AI reacts on fire at night as well as on daylight.

Share this post


Link to post
Share on other sites
  Cyborg112 said:
Would this work for the streetlamps too?

for one streetlamp

trigger then activation

([0,0,0] nearestObject IDname) switchLight "OFF"

for lots of streetlamp

{_x switchLight "OFF"} forEach ((getPos centre) nearObjects ["StreetLamp",200]);

200 is the radius

Share this post


Link to post
Share on other sites

I mean if you stand in the light of the streetlamp at night the AI doesn't recognize you even if they watch at you.

Share this post


Link to post
Share on other sites

Not at this state of the script.

As no unit will be added to the array....and the script wont be executed by a streetlamp if u use a EH.

So the answer is no, relating to that script as it is.

Share this post


Link to post
Share on other sites

I had a look at the mission.

Put a ; at the end of your added hint in the start.

And attach it as sqf (execVM) instead of sqs (exec).

And, always use -showScriptErrors in your Arma shortcut. :)

Doing that, it worked for me. Takes a while for the loops to finish, then everyone opens fire on everyone :D

I'll throw together a quick mission where AI are also given flares, and will use them on suspicion, and where this "madness reveal" takes place :)

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

Did i mention it works like it does ?!

Cheerz m8!

---------- Post added at 09:11 PM ---------- Previous post was at 08:10 PM ----------

I would like to refer to one of your scripts, that make an AI shoot flare into the sky by knowsabout, as i do not want to make AI shoot flares by executing triggers e.g.

Well this is your script (i changed it to vanilla class)

hint "jo";
private ["_unit","_check","_leader","_flarechance","_mags","_one_flare","_one_flare_muzzle"];
_unit = _this select 0;
_check = false;
_flarechance = 0.6;
_enemylist = [];
while {alive _unit} do{
   if (flarefired) then {sleep 10.123 + (random 10)};
   _leader = leader _unit;
   {
       if(_leader knowsAbout _x >= 0.7) then
       {
           _check = true;
           sleep 1.123;
       };
   } forEach list tEastAriAllEnemies;

   if (_check && !flarefired && (random 1 < _flarechance) && !(call fn_isDay)) then {
       _one_flare = "";
       _mags = magazines _unit;
       {
           scopeName "xxxx1";
           if (_x in d_flarelist) then {
               _one_flare = _x;
               breakOut "xxxx1";
           };
       } forEach _mags;
       sleep 3.345;
       if (!flarefired && alive _unit) then {
           if (_one_flare != "") then {
               flarefired = true;
               sleep 1.234;
               _one_flare_muzzle = "GP25Muzzle";
               _unit selectWeapon _one_flare_muzzle;
               _unit doWatch [getPos _unit select 0, getPos _unit select 1, 200];
               sleep 1.234;
               _unit fire [_one_flare_muzzle, _one_flare_muzzle, _one_flare];
               sleep 31.234;
               if (random 1 < 0.7) then {_unit addMagazine (d_flarelist select (floor random count d_flarelist));};
           };
       }
       else {
           flarefired = false;
       };
       sleep 30;
   };
   sleep 1 + (random 1);
   flarefired = false;
};

I created a trigger 5000x5000 called it tEastAriAllEnemies, triggered by bluefor.In activation: nil=[] execVM "enemydetect.sqf"

I hoped to make one of the grenadiers shooting flares as soon as they know enough about any bluefor unit, but nothing happened,

So i expect sth wrong here.

Can u give me hand once again plz?

Share this post


Link to post
Share on other sites
  Quote
nil=[] execVM "enemydetect.sqf"

Ouch! Never use nil, call it xxx, dummy, nothing, handle, but never nil :) This is a fairly old script of mine, so if I do it myself somewhere, I didn't know at the time.

Is d_flarelist defined and flarefired set, i.e. in init.sqf?

Do you have the function fn_isDay defined?

And of course the units needs to have the script started and been given some flares.

Here is some updated scripts, including an updated isDay function, should work better with any island at different latitudes:

  Reveal hidden contents

Share this post


Link to post
Share on other sites
  CarlGustaffa said:
Ouch! Never use nil, call it xxx, dummy, nothing, handle, but never nil :)

You can ever use 0 (zero). Sounds bad, but 0=something works in arma.

Share this post


Link to post
Share on other sites

Couldnt bother with ArmA2 these days, as we played and lost Championsleague today, nevertheless i ll try to get it work tomorrow!

Share this post


Link to post
Share on other sites

I havn't tried this at night butyou can try the {_x reveal (unit x should be revealed to)} foreach units groupx.

If that doesn't work you can use the target command and loop a script with the action useweapon command.

Mabey you can use this in combination withthe ishidden command to check if friendly units are hidden before revealing their position to enemies.

Edited by Rejenorst

Share this post


Link to post
Share on other sites

Are any of the hide commands still valid in Arma2? I thought they were all obsolete now, but I haven't checked.

getHideFrom: No particular note.

setHideBehind: Command is not functional in Arma2.

Share this post


Link to post
Share on other sites

Hi Carl,

tested your scripts and working as it does, cheerz.

Share this post


Link to post
Share on other sites

Yeah, it will "appear" to work. But when you start using it in an actual mission, you will begin calling me stupid - at least I do :D

Share this post


Link to post
Share on other sites

Well atm i didnt reach the point i was supposed to do so ....

Nevertheless, i got another prob atm.#

As this scripts are worth using by night only, some units should shoot by random a flare, otherwise the "flare-drama" wont get running.

I treid to implement a triggered flare, but of course this didnt work, due to the EH.

If i make a unit shoting flares like each 600 sec ,just for controll view or whatever , how should i implement this one in your composition?

Edith sais:

I played, or better gambled around and i think i got a way that satisfie me.

Means i got one initially flare shooting unit, that makes the stone rolling.

I thought i must have to give that initially shooting unit the EH fired

_unit addEventHandler ["fired", {_this execVM "EH-flares.sqf"}];

But it seems to work without.....???

Edited by Nephris1

Share this post


Link to post
Share on other sites

For more and easier "flare drama", just lower the knowsAbout check to say 0.05. That will make them fire flares on just about any unknown contact.

For the 600 thingy, you could just separate the part of the script that does the actual firing into a separate script of function, and just call that separately without any "do I need to fire a flare check" going.

Share this post


Link to post
Share on other sites

How to set up this to work with Ambient Combat Manager?

Is that possible?

Share this post


Link to post
Share on other sites

It seems to work OK with ACM.

I tryed this

in init file:

isDay_check = true;

[] execVM "script\fncIsDay.sqf";

Then in fncIsDay.sqf I have this

while {isDay_check} do {

Your code

sleep 60;

}

Now when I have played with this, I can see AI shoot up flares like hell.

(3-5 flares in the air at the same time.)

Are they going to do that, my thought was that the AI shoot one flare, then wait 10-15 second, then shoot next one.

Good script to make AI shoot flares =)

It is really fun playing with this.

Edited by Kiptanoi

Share this post


Link to post
Share on other sites

So, are you beginning to call me stupid yet? Told ya you would :D I'm aware of the amount that goes up, and have tried to implement a system against it. Each unit is now given a variable if he can shoot a flare or not. And when someone shoots a flare, this variable is updated for nearby friendly units preventing him from launching. Also the random delay was increased.

Just for the hell of it, I now let you choose if the enemy AI will be using "rocket flares". Think of it as "old style flares" (we used them when I serviced), but it's not quite up to M127A1 standards (it's still the vanilla flare being used, but with different effects).

7u4l0DRnPFQ

And to keep in mind if you think "flares are blinding". Well... They are :)

9c4R_U_70fI

All code within the spoiler tag.

  Reveal hidden contents

All I really need to address now is the stupid "information sharing" reveal thingy, which is waaay too good now. I know ACE is handling vanilla flares differently, so I could probably pick up some things there. Also, (I've read that) mando missiles have some sort of "can see unit" check, this might also be worth looking into.

Btw, you might want to disable the "residue dropper" for vanilla flares and use it only for rocket flares (I've seen youtube videos with this happening), as it doesn't look too good at the moment.

Have fun, I know I'm loving this :)

Edit1: Hopefully fixed FlareShooting.sqf (had some bracing errors due to last minute changes).

Edit2: Fixed _lat lookup in fn_SunElev (should now work correctly also with Thirsk Winter).

Edited by CarlGustaffa
Shown in edit note.

Share this post


Link to post
Share on other sites

Thx a lot m8!

I am trying to implement it into Dac, which shouldnt be too hard, as it can be "easily" implemented via event.

Give ya a shout or mission example if interested.

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  

×