Jump to content
pdp

AI sniper killing an enemy VIP (and him only)

Recommended Posts

Hi I'm new to mission editing, but I wish to learn. I want to set a sniper to stay hidden and quiet, until comes in his view the designated VIP to kill together in a group of enemies, *kill him only*, then runs away unharmed.

Other enemies must survive.

I did try a lot of failed attempts using enable/disableAI, etc. but I have to give up: the sniper always attack other enemies before and after the VIP kill. Thank you.

Share this post


Link to post
Share on other sites
10 hours ago, pdp said:

Hi I'm new to mission editing, but I wish to learn. I want to set a sniper to stay hidden and quiet, until comes in his view the designated VIP to kill together in a group of enemies, *kill him only*, then runs away unharmed.

Other enemies must survive.

I did try a lot of failed attempts using enable/disableAI, etc. but I have to give up: the sniper always attack other enemies before and after the VIP kill. Thank you.

 

Took a quick glance at @Gunter Severlohs glorious collection, couldn't spot something similar so I made something from scratch.

 

This can be quirky and depends on quite a few factors to work reliably.

Usually make sure that the sniper can actually fire at the target and has a clear line of sight as well as an appropriate firearm, which apparently isn't an issue in your situation, just worth mentioning.

This snippet will make the sniper target and shoot at the VIP, if successful the sniper will move 1500m facing away from the VIPs current position and ignore further engagements if possible:

 

//put this into init.sqf or where you seem fit
GOM_fnc_sniperKillTarget = {

	params ["_sniper","_target",["_debug",true]];

	if (_debug) then {

		systemchat format ["%1 attempting to shoot %2.",typeof _sniper, typeof _target];

	};

	while {alive _sniper AND alive _target} do {

		sleep 3;
		_sniper reveal [_target,4];
		_sniper doFire _target;

	};


	if (!alive _sniper AND _debug) exitWith {systemchat "The sniper got killed!"};


	{group _sniper forgetTarget _x} forEach (_sniper targets [true,0]);//remove all targets from snipers memory
	_sniper disableAI "AUTOCOMBAT";
	_sniper setBehaviour "AWARE";
	_sniper setCombatMode "GREEN";//allows firing for defense only, adjust or remove this
	_sniper setUnitPos "UP";

	_awayPos = _sniper getRelPos [1500,_target getRelDir _sniper]; //move 1500 away from target
	if (!alive _target AND _debug) then {systemchat format ["The target got eliminated! Moving to grid %1!",mapGridPosition _awayPos]};
	_sniper doMove _awayPos;
	true


};

//to spawn the function from a trigger or where you seem fit, turn off debug if not needed:
_debug = true;
_shoot = [mysniper,myVIP,_debug] spawn GOM_fnc_sniperKillTarget;

If the target is moving, and the further the target is away from the sniper, the harder it is for AI to kill only the designated target.

Best space out the units and make them stand still when starting the snippet for best results, also make sure to set the snipers skill to 1, since the most recent AI "refactoring" the precision of editor placed units with default settings has gone down a lot.

 

Cheers

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Incredible... :wow_o: thank you for your precious work. I'm going to report your snippet to G. Severloh.

Share this post


Link to post
Share on other sites

That's a good bit of code, but if you want such a specific outcome that works every time, it might be easier to just fake it. 

 

ie. Make the sniper fire his weapon in the air and then setDamage 1 on the target. 

  • Haha 1

Share this post


Link to post
Share on other sites
31 minutes ago, dreadpirate said:

That's a good bit of code, but if you want such a specific outcome that works every time, it might be easier to just fake it. 

 

ie. Make the sniper fire his weapon in the air and then setDamage 1 on the target. 

:rofl: I'm stil laughing. nice trick :rthumb:

Share this post


Link to post
Share on other sites
1 hour ago, dreadpirate said:

That's a good bit of code, but if you want such a specific outcome that works every time, it might be easier to just fake it. 

 

ie. Make the sniper fire his weapon in the air and then setDamage 1 on the target. 

 

Good suggestion, at least if you want to completely ignore line of sight and all the other jazz.

Now if you want to fake it this could be a proper solution to calculate the delay between shot fired and projectile hitting the target:

 

_muzzleVelocity    = getnumber (configfile >> "CfgMagazines" >> currentmagazine _sniper >> "initSpeed");
_delay = (_sniper distance _target) / _muzzleVelocity; //at 800m and 300m/s muzzle velocity this will result in a delay of ~2.66s
sleep _delay;
_target setdamage 1;

 

Cheers

  • Like 3

Share this post


Link to post
Share on other sites

I've spent hours trying to wrangle the AI to do what I want to no avail, so I always look for a short cut or a cheat. 

 

If the players in your mission don't notice, it's a win. 

  • Haha 1

Share this post


Link to post
Share on other sites

sorry to bother you again, in the same scenario (stealth mission)  I need that if a shot is fired by everyone  (opfor or blufor), it activates a waypoint that makes jump in a guard patrol. I've found some examples, this is one:

alarmID= PLAYER addEventHandler ["Fired",{alarm = true; publicVariable "alarm";}];

 

but it applies only when the player (me) shots. How can I modify "PLAYER" with: "every single blufor or opfor soldier present in the scenario that opens fire"?  Of course I tried "BLUFOR" (or "OPFOR") but it didn't work.

 

Please forgive me for the trivial question, I just started to play with the editor.

Thank you.

Share this post


Link to post
Share on other sites

Just add this to the init.sqf, should work fine.

If you spawn units mid mission just apply it to spawned units.

 

{

		_alarmID = _x addEventHandler ["Fired",{

		params ["_shooter"];
		alarm = true;
		publicVariable "alarm";

		//remove the eventhandler from every unit to prevent publicvariable spam
		{

			_alarmID = _x getVariable ["TAG_fnc_alarmID",-1];
			_shooter removeEventHandler ["Fired",_alarmID];

		} forEach allUnits;

	}];

	_x setVariable ["TAG_fnc_alarmID",_alarmID];
} forEach allUnits;

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank You very much. Your help is very appreciated.

 

3 hours ago, Grumpy Old Man said:

If you spawn units mid mission just apply it to spawned units.

 

In this case, where have I to paste Your code? Into in the groupleader's Object:line? Or into every soldier's Object:line?

 

(later...)

So I:

- pasted Your code into init sqf, and put it into mission folder;

- created an enemy patrol named "Mygroup";

- added a "wait" waypoint then a "S&D" waypoint to Mygroup;

- created a Switch type "pass waypoint", activated by everyone and put "Fired" in Condition;

- connected "Wait" WP to that switch

 

but when my fellow sniper shots, Mygroup stays blocked in wait WP and do not search for us...

 

what is wrong? Thank you.

 

Share this post


Link to post
Share on other sites
5 hours ago, pdp said:

Thank You very much. Your help is very appreciated.

 

 

In this case, where have I to paste Your code? Into in the groupleader's Object:line? Or into every soldier's Object:line?

 

(later...)

So I:

- pasted Your code into init sqf, and put it into mission folder;

- created an enemy patrol named "Mygroup";

- added a "wait" waypoint then a "S&D" waypoint to Mygroup;

- created a Switch type "pass waypoint", activated by everyone and put "Fired" in Condition;

- connected "Wait" WP to that switch

 

but when my fellow sniper shots, Mygroup stays blocked in wait WP and do not search for us...

 

what is wrong? Thank you.

 

 

Do you want your patrol to search for the sniper or anyone that fired a shot?

In the latter case you would do fine just giving the patrol group a "GUARD" waypoint, they'll engage any enemy in their vicinity that their side knows about.

There would be no need for fired eventhandlers etc.

 

Cheers

Share this post


Link to post
Share on other sites

Thank you for the time spent answering to my questions.

 

Search for the sniper (that runs away). The player (me) stays hidden, hoping not to be seen, and continue his mission. He knows that - if he or the sniper shots for whaterver reason - their life is in serious danger.

 

In conclusion, the plot is:

- the sniper stays quiet also if 2 bodyguards are present;

- when VIP comes, the sniper kills the VIP (primary objective);

- the bodyguards start searching the sniper;

- a patrol, alarmed by the shot(s), runs out from the house to search the sniper;

- the sniper runs away, attracting bodyguards and patrol behind him far from the house; if not, the player must kill everyone, but this may attract other patrol(s) (random event);

- now the house is (perhaps!) unguarded, the player can sneak in and continue his missions (second objective).

Share this post


Link to post
Share on other sites

Made a small mission to showcase a scenario like this.

All happens inside the init.sqf:

 


GOM_fnc_sniperKillTarget = {

	params ["_sniper","_target","_awayMarker",["_debug",true]];

	if (_debug) then {

		systemchat format ["%1 attempting to shoot %2.",typeof _sniper, typeof _target];

	};

	while {alive _sniper AND alive _target} do {

		sleep 3;
		_sniper reveal [_target,4];
		_sniper doFire _target;

	};


	if (!alive _sniper AND _debug) exitWith {systemchat "The sniper got killed!"};


	{group _sniper forgetTarget _x} forEach (_sniper targets [true,0]);//remove all targets from snipers memory
	_sniper disableAI "AUTOCOMBAT";
	_sniper setBehaviour "AWARE";
	_sniper setCombatMode "GREEN";//prevents him from firing, adjust or remove this
	_sniper setUnitPos "UP";

	_awayPos = getMarkerPos _awayMarker; //move 1500 away from target
	if (!alive _target AND _debug) then {systemchat format ["The target got eliminated! Moving to %1!",mapGridPosition _awayPos]};
	_sniper doMove _awayPos;
	true


};

GOM_fnc_groupChaseUnit = {

	params ["_group","_unit"];

	while {count units _group > 1 AND alive _unit} do {

		{_x dofollow leader _group} forEach units _group;
		_movePos = getPosATL _unit;

		//make them more mobile/agile when chasing another unit
		{_x disableAI "AUTOCOMBAT";_x setBehaviour "AWARE"} forEach units _group;

		_group move _movePos;

		waituntil {sleep 10;!alive _unit OR _unit distance _movePos > 30};

	};


};


//to spawn the funciton:
_shoot = [mySniper,myVIP,"SniperEscape"] spawn GOM_fnc_sniperKillTarget;

//spawn control function to handle all events:
_main = [] spawn {

	_debug = true;//set to false to disable debug messages
	waitUntil {!alive myVIP};
	
	sleep random [0.5,0.5,1.5];

	if (_debug) then {systemchat "VIP has been killed!";playSound "Click";};

	_hunt1 = [myVIPGroup,mySniper] spawn GOM_fnc_groupChaseUnit;
	_hunt1 = [myPatrolGroup,mySniper] spawn GOM_fnc_groupChaseUnit;



};

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

wow... this is an huge work. I'm speechless. :wow_o:. A (virtual) beer for you. I have *a lot* to study now. Thank you again.

  • 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

×