Jump to content
dlegion

[SOLVED] make AI sniper shoots at 2000m

Recommended Posts

hello guys...i'm sorry to ask an apparently ridicolous question (because it is), but ARMA3 make every effort to make obvious things...impossible!

to cut it short, i just wish to place a sniper and make him able to see and hit targets at ranges up to 1500m (with a 0.50 lynx rifle).
it wasn't working, so i documented myself, and finally i made this script to try solve the problem:
 

Spoiler

// null = [this] execVM "SNIPE.sqf";        // in unit init to run script

hint "sniper script started";
_sniper2 = (_this select 0);
_sniper2 disableAI "PATH";
_sniper2 setUnitPos "DOWN";
_sniper2 setSkill ["spotDistance", 1];
_sniper2 setSkill ["spotTime",1];
//_sniper2 dowatch (this getrelpos [150,0]);

while {true} do {
   _Dtargets = [];
   {if ((_x distance2D _sniper2) < 2000 && (side _x == west) && (alive _x)) then {_sniper2 reveal _x;_Dtargets pushBack _x}} forEach allunits;

   _Tcount = count _Dtargets;
   hint "sniper choose new target";
   if (_Tcount > 0) then {_Target = (selectRandom _Dtargets);_sniper2 dotarget _Target;_sniper2 doFire _Target;};
   _sniper2 setVehicleAmmo 1;

   uiSleep 20;
};

 

...and it actually works....when its 12:00 in a sunny DAY !
at night or in rain it simply dont shoot!

i'm getting mad about this thing that should already work in default ARMA3 without scripts!
hope you can help me, thanks!

  • Like 1

Share this post


Link to post
Share on other sites

Have you tried reveal target command?

 

also uiSleep should be sleep 

 

  • Like 1

Share this post


Link to post
Share on other sites

No reveal needed, a simple doTarget is enough.

At pitch black night the sniper will fire the lynx at 1km+.

It all depends on the scope, put a nightstalker on, should do the trick.

 

 

Cheers

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
28 minutes ago, gc8 said:

Have you tried reveal target command?

Well...as you can see in my script i have both, but the idea of put nightstalker optic is simply genious !

Will try asap !

Thankss 

Share this post


Link to post
Share on other sites

and again you were fast, correct, and with a solution at hand.
Grumpy, can i offer a couple of beers to you on paypal ?
really , really thanks man!

Share this post


Link to post
Share on other sites

I figured the answer would be "give them an AK with iron sights" but I guess you've got it sorted :thumb_down:

  • Haha 1

Share this post


Link to post
Share on other sites

Just a point. Don't forget the reveal /knowsAbout command has a range from 0 to 4. Default is 1 (as you did). You can reveal up to 4 if you need it.

In I'm right, the doTarget will not overpass the possible value according to the weather/night conditions.

On the other hand some night scope does the trick, as GOM said (probably like NVGs)

See @Lou Montana table.

Share this post


Link to post
Share on other sites
42 minutes ago, pierremgi said:

Just a point. Don't forget the reveal /knowsAbout command has a range from 0 to 4. Default is 1 (as you did). You can reveal up to 4 if you need it.

In I'm right, the doTarget will not overpass the possible value according to the weather/night conditions.

On the other hand some night scope does the trick, as GOM said (probably like NVGs)

See @Lou Montana table.

Well doTarget makes the unit look straight at the targeted unit.

If nothing is blocking the sight and an appropriate scope is mounted, the sniper will see he's looking at an enemy, reveal value almost immediately jumps to 4 at 1100m using the vanilla opfor sniper unit.

 

 

Cheers

Share this post


Link to post
Share on other sites

....so i assume there's no way to simply force "reveal 4" on a unit ?
because right now the limit is still around 1000m ...and a nightstalker seems to not work in day for AI, so i need to swap it with LRPS optic, and even at this point, its not very reliable...seems that lynx-LRPS equipped sniper now can't shoot at me ...

dont know...maybe its some sort of locality issue....sometimes they shoot sometimes they dont....maybe its ACE3 the problem...damned ARMA3

Share this post


Link to post
Share on other sites
55 minutes ago, dlegion said:

....so i assume there's no way to simply force "reveal 4" on a unit ?
because right now the limit is still 1100m ...

 

Well you can auto reveal everything in front of a unit:

 

GOM_fnc_autoReveal = {
	params ["_unit","_distance","_fov"];

	//we don't want to use a units direction, but rather the direction he's looking at, big difference
	eyeDirection _unit params ["_dirX","_dirY"];
	_eyedir = _dirX atan2 _dirY;
	if (_eyedir < 0) then {_eyedir = 360 + _eyedir};

	_distance = _distance ^2;
	_enemySides = side _unit call BIS_fnc_enemySides;

	_enemies = allUnits select {
		side _x in _enemySides AND {_x distancesqr _unit < _distance} AND {
		acos ([sin _eyedir, cos _eyedir, 0] vectorCos [sin (_unit getDir _x), cos (_unit getDir _x), 0]) <= _fov/2}
	};

	_enemies apply {_unit reveal [_x,4]};
	_enemies

};
[sniper,viewDistance,120] call GOM_fnc_autoReveal;

This will reveal every enemy in front of a unit, at a certain field of view (i.e. 120°) and within specified distance.

The return holds all revealed units.

 

_revealedEnemies = [sniper,viewDistance,120] call GOM_fnc_autoReveal;

 

Cheers

 

Cheers

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

thanks GOM!
...but the script i posted in the first post doesnt do much or less the same?
 

// null = [this] execVM "SNIPE.sqf";        // in unit init to run script

hint "sniper script started";
_sniper2 = (_this select 0);
_sniper2 disableAI "PATH";
_sniper2 setUnitPos "DOWN";
_sniper2 setSkill ["spotDistance", 1];
_sniper2 setSkill ["spotTime",1];
//_sniper2 dowatch (this getrelpos [150,0]);

while {true} do {
   _Dtargets = [];
   {if ((_x distance2D _sniper2) < 2000 && (side _x == west) && (alive _x)) then {_sniper2 reveal _x;_Dtargets pushBack _x}} forEach allunits;

   _Tcount = count _Dtargets;
   hint "sniper choose new target";
   if (_Tcount > 0) then {_Target = (selectRandom _Dtargets);_sniper2 dotarget _Target;_sniper2 doFire _Target;};
   _sniper2 setVehicleAmmo 1;

   uiSleep 20;
};

thanks man ! i'm getting mad on this one!

Share this post


Link to post
Share on other sites

hm...doing more tests seems the "unrealiable" part is linked to the weather.
at 12:00 of a sunny day it works perfectly, while in a cloudy day or at dawn and dusk it start to be unrealiable....
any idea if this somehow can be "skipped" ?
thanks!

Share this post


Link to post
Share on other sites

replace doFire by doSuppressiveFire . There is no more weather limitations. The accuracy is not worse.

  • Like 3

Share this post


Link to post
Share on other sites

yeah!         doSuppressiveFire     works better, but its still very, very, very unrealiable!
i came up with this :
 

// null = [this] execVM "SNIPE.sqf";        // in unit init to run script

_Tside = west;               // manually define ENEMY side to shoot at
_S1 = (_this select 0);

_S1 disableAI "PATH";

_S1 setUnitPos "DOWN";

_S1 disableAI "AIMINGERROR";
_S1 disableAI "FSM";
_S1 setSkill 1;

while {true} do {

   _Dtargets = [];
   {if ((_x distance2D _S1) < 2000 && (side _x == _Tside) && (alive _x)) then {_S1 reveal [_x,4];_Dtargets pushBack _x}} forEach allunits;

   _Tcount = count _Dtargets;
      if (_Tcount > 0) then {_Target = (selectRandom _Dtargets);_S1 reveal [_Target,4];_S1 dotarget _Target;_S1 doSuppressiveFire _Target;uiSleep 3;_S1 forceWeaponFire [(currentWeapon _S1), "Single"];};
   _S1 setVehicleAmmo 1;

   uiSleep 7;
};

with this code it is forced to shoot...while aiming a targer, so it kinda works....but there are 2 problems : its still very inaccurate at long ranges (1000m-1500m range) and the baddest problem...it is forced to try shoot even if there is no line of sight (imagine throught mountains, LOL).
any idea how solve this problem once for all ?
thanks!

  • Like 1

Share this post


Link to post
Share on other sites

i think i reached an acceptable point, with this code an AI sniper can reliably hit a man at 2000m even at night during a rainstorm in 30 seconds of shooting, but as suggested it MUST have M302 LRR and LRPS optic (with nightstalker or other rifles performance degrade a lot):

 

// null = [this] execVM "SNIPE.sqf";        // in unit init to run script. for best result, use a sniper with M320 LRR .408 rifle and LRPS optic 
//(yes, even at night and in a rainstorm...it should hit 1 man in 1 minute of shooting at 2000m, vanilla arma3)

/*
    Author: HallyG

    Parameter(s):
    0: [OBJECT] - Object who is 'looking'
    1: [OBJECT] - Object to look for
    2: [NUMBER] - Looker's FOV (OPTIONAL) DEFAULT (70)

    Returns:  [BOOLEAN]
*/

Dlos = {

params [["_looker",objNull,[objNull]],["_target",objNull,[objNull]],["_FOV",70,[0]]];
if ([position _looker, getdir _looker, _FOV, position _target] call BIS_fnc_inAngleSector) then {
    if (count (lineIntersectsSurfaces [(AGLtoASL (_looker modelToWorldVisual (_looker selectionPosition "pilot"))), getPosASL _target, _target, _looker, true, 1,"GEOM","NONE"]) > 0) exitWith {false};
    true
} else {
    false
   };
};

_Tside = west;               // manually define ENEMY side to shoot at
_S1 = (_this select 0);

_S1 disableAI "PATH";

_S1 setUnitPos "DOWN";

_S1 disableAI "AIMINGERROR";
//_S1 disableAI "FSM";
_S1 setSkill 1;

while {true} do {

   _Dtargets = [];
   {if ((_x distance2D _S1) < 2000 && (side _x == _Tside) && (alive _x)) then {_S1 reveal [_x,4];_Dtargets pushBack _x}} forEach allunits;

   _Tcount = count _Dtargets;
   if (_Tcount > 0) then {_Target = (selectRandom _Dtargets);_S1 doTarget _Target;_S1 doSuppressiveFire _Target;uiSleep 0;if ([_S1, _Target] call Dlos) then {_S1 forceWeaponFire [(currentWeapon _S1), "Single"];};};
   _S1 setVehicleAmmo 1;

   uiSleep 5;
};

thanks guys for your help, happy shooting!

  • Like 6

Share this post


Link to post
Share on other sites
On 7/6/2018 at 9:03 PM, dlegion said:

i think i reached an acceptable point, with this code an AI sniper can reliably hit a man at 2000m even at night during a rainstorm in 30 seconds of shooting, but as suggested it MUST have M302 LRR and LRPS optic (with nightstalker or other rifles performance degrade a lot):

 


// null = [this] execVM "SNIPE.sqf";        // in unit init to run script. for best result, use a sniper with M320 LRR .408 rifle and LRPS optic 
//(yes, even at night and in a rainstorm...it should hit 1 man in 1 minute of shooting at 2000m, vanilla arma3)

/*
    Author: HallyG

    Parameter(s):
    0: [OBJECT] - Object who is 'looking'
    1: [OBJECT] - Object to look for
    2: [NUMBER] - Looker's FOV (OPTIONAL) DEFAULT (70)

    Returns:  [BOOLEAN]
*/

Dlos = {

params [["_looker",objNull,[objNull]],["_target",objNull,[objNull]],["_FOV",70,[0]]];
if ([position _looker, getdir _looker, _FOV, position _target] call BIS_fnc_inAngleSector) then {
    if (count (lineIntersectsSurfaces [(AGLtoASL (_looker modelToWorldVisual (_looker selectionPosition "pilot"))), getPosASL _target, _target, _looker, true, 1,"GEOM","NONE"]) > 0) exitWith {false};
    true
} else {
    false
   };
};

_Tside = west;               // manually define ENEMY side to shoot at
_S1 = (_this select 0);

_S1 disableAI "PATH";

_S1 setUnitPos "DOWN";

_S1 disableAI "AIMINGERROR";
//_S1 disableAI "FSM";
_S1 setSkill 1;

while {true} do {

   _Dtargets = [];
   {if ((_x distance2D _S1) < 2000 && (side _x == _Tside) && (alive _x)) then {_S1 reveal [_x,4];_Dtargets pushBack _x}} forEach allunits;

   _Tcount = count _Dtargets;
   if (_Tcount > 0) then {_Target = (selectRandom _Dtargets);_S1 doTarget _Target;_S1 doSuppressiveFire _Target;uiSleep 0;if ([_S1, _Target] call Dlos) then {_S1 forceWeaponFire [(currentWeapon _S1), "Single"];};};
   _S1 setVehicleAmmo 1;

   uiSleep 5;
};

thanks guys for your help, happy shooting!

 

Hello, where would I put this in an arma 3 exile dedicated server?  Thanks

Share this post


Link to post
Share on other sites
3 hours ago, Dirk Verite said:

where would I put this in an arma 3 exile dedicated server?

Its a script for a mission, you need a mission to put it into.

Open notepad, copy all the code into it, save notepad file as SNIPE.sqf

 

Then put this code in the unit's init box      

null = [this] execVM "SNIPE.sqf";

 

  • Like 1

Share this post


Link to post
Share on other sites
21 hours ago, Gunter Severloh said:

Its a script for a mission, you need a mission to put it into.

Open notepad, copy all the code into it, save notepad file as SNIPE.sqf

 

Then put this code in the unit's init box      


null = [this] execVM "SNIPE.sqf";

 

This might sound like a noob question, but would it be the playerinit, serverinit, or just the init one.  Thanks so much for the answer, I can't wait to try this.

Share this post


Link to post
Share on other sites
3 hours ago, Dirk Verite said:

but would it be

 

This script is written in such a way that it must be called by the sniper unit, not a mission event script. Open the mission in the editor, find the sniper unit , and paste the execVM line into its init field (hence "unit's init box"). If the sniper is dynamically spawned, then you need to edit the script that spawns them, which is slightly more complicated.

  • Like 1

Share this post


Link to post
Share on other sites
12 hours ago, Harzach said:

 

This script is written in such a way that it must be called by the sniper unit, not a mission event script. Open the mission in the editor, find the sniper unit , and paste the execVM line into its init field (hence "unit's init box"). If the sniper is dynamically spawned, then you need to edit the script that spawns them, which is slightly more complicated.

Ok, I get what you are saying, I will try to do that.  I will post here after if it works.  Thanks again

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

×