Jump to content
Jester504

How to make AI JTAC lase enemy infantry

Recommended Posts

I've had good success with AI lasing enemy vehicles. I am now trying to get them to lase groups of enemy infantry for GBUs. I'm just getting into scripting and trying to brainstorm ways to do this. Any ideas? Would be awesome to do it without scripting but I imagine it's not possible. I'm also open to finding a way to spawn just the laser targets without relying on AI JTACs if that's easier/more controllable. The scenario I have in mind is a MP coop with players flying CAS for a large AI battle.

 

Thanks!

Share this post


Link to post
Share on other sites

As far as I know Recon JTAC units will automatically lase valid targets if they got line of sight and are not under fire.

As zeus you can see the Recon JTAC pull out his laser designator and lase nearby hostile vehicles.

A lasertarget will also be created, so it's working just fine by just placing a JTAC unit.

 

If you want a JTAC to lase infantry you'd need to do quite some workarounds to make him not switch to his weapons.

Spawning a laser target on the infantry unit would be indeed a simpler solution:

laserTarget = "LaserTargetW" createVehicle getposatl this;
laserTarget attachTo [this, [0, 0, 0]];

 

Cheers

Share this post


Link to post
Share on other sites

Thanks for the tip! I can follow basically what your code is doing, but I'm not sure where it fits into a mission. Would it go in a group's init field or should it be called from a file? How do I decide between those two, generally?

 

Let's say I wanted to have multiple squads and only have certain squads get lased (e.g. the squad nearest any friendly unit, one at a time). Could I have a script that gets a list of all opfor groups within e.g. 2km of a blufor unit, then spawns a laser target at the closest one, one at a time?

Share this post


Link to post
Share on other sites
9 hours ago, Jester504 said:

Thanks for the tip! I can follow basically what your code is doing, but I'm not sure where it fits into a mission. Would it go in a group's init field or should it be called from a file? How do I decide between those two, generally?

 

Let's say I wanted to have multiple squads and only have certain squads get lased (e.g. the squad nearest any friendly unit, one at a time). Could I have a script that gets a list of all opfor groups within e.g. 2km of a blufor unit, then spawns a laser target at the closest one, one at a time?

Grumpys code has to go in the init line of the infantry units which the JTACs should be able to lase.

It will create a laser target on that unit and the JTAC will lase it.

But I think you need to delete these laser targets after the unit is dead or the JTACs will lase dead bodies as well.

Share this post


Link to post
Share on other sites

Alternative to grumpys solution you could paste one of the following codes in your

initServer.sqf

 

// this sets a laser target to all units except players and deletes it if the specific unit dies 
{
 _x setVariable ["laserTarget", ("LaserTargetW" createVehicle getPosATL _x), false];
 _x spawn
 {
  _l_target = _this getVariable "laserTarget"; 

  _l_target attachTo [_this, [0, 0, 0]];

  waitUntil {sleep (5 + random 5); !alive _this};
 
  detach _l_target;
  
  deleteVehicle _l_target;  
 };
} count (allUnits - allPlayers);

 

// this sets a laser target to all team leaders side east except players and deletes it if the leader dies 
{
 _x setVariable ["laserTarget", ("LaserTargetW" createVehicle getPosATL _x), false];
 _x spawn
 {
  _l_target = _this getVariable "laserTarget"; 

  _l_target attachTo [_this, [0, 0, 0]];

  waitUntil {sleep (5 + random 5); !alive _this};
 
  detach _l_target;
  
  deleteVehicle _l_target;  
 };
 
 (_x == leader _x) && (side _x == east)
} count (allUnits - allPlayers);

 

Share this post


Link to post
Share on other sites
On 4/7/2017 at 1:58 AM, sarogahtyp said:

Alternative to grumpys solution you could paste one of the following codes in your

initServer.sqf

 

Thanks sarogahtyp! I tried your second example. I put this in initServer.sqf:

 

Quote

[] execVM "lasertargets.sqf";

 

And copy/pasted your second example into lasertargets.sqf.

 

It worked pretty well, overall! A BluFor drone saw and bombed the created laser targets automatically, the targets moved as the units moved, and any dead unit's laser target was removed. There was one problem, however.

 

I see you're trying to limit the creation of a laser target to only group leaders on side east with:

 

Quote

(_x == leader _x) && (side _x == east)

 

But upon running in MP (from the editor) my test mission places lasertargets on all east units, group leader or not. I'm slowly learning Arma scripting syntax and formatting and everything but I don't yet know enough to know why it works that way. Could you help me?

 

Thanks again!

Share this post


Link to post
Share on other sites

If anyone wants to give me hints, here's what I think my script needs to do overall, broken down as much as I can:

 

1. Find all east infantry

2. Limit to group leaders with more than two units in their group

3. Limit to group leaders within 2km of west infantry

4. Limit to the one group leader that is closest to west infantry

5. Create laser target on that group leader

6. Wait until he is dead

7. Delete laser target

8. Repeat from 1

Share this post


Link to post
Share on other sites

Oh the joy of having such simple requests!

 

//put this into init.sqf or from wherever you init your functions
GOM_fnc_spawnLaserOnInfantry = {

	params ["_JTAC"];
	_debug = true;
	_JTAC setCombatMode "BLUE";
	_JTAC setVariable ["GOM_fnc_LaserOn",true];

	_JTAC addEventHandler ["Hit",{
		params ["_JTAC"];
		_JTAC setCombatMode "RED";
		_JTAC removeEventhandler ["Hit",_thisEventHandler];
		_JTAC setVariable ["GOM_fnc_LaserOn",false];

	}];

	while {alive _JTAC} do {


		waituntil {sleep 1; (_JTAC getVariable ["GOM_fnc_LaserOn",false])};
		_enemies = [_JTAC,2000] call BIS_fnc_enemyTargets;

		if (count _enemies > 0) then {

			_enemies = _enemies select {typeOf _x isKindOf "CAManBase" AND _x isEqualTo leader group _x AND count units group _x > 2};

			if (_debug) then {systemchat format ["%1 spotted %2 enemy leaders!",name _JTAC, count _enemies]};
			sleep 1;
		{


		if (alive _x) then {
		_target =_x;
		_dispName = getText (configfile >> "CfgVehicles" >> typeOf _x >> "displayName");
		_laser = "LaserTargetW" createVehicle getPosATL _target;
		_laser attachTo [_target,[0,0,0]];
		if (_debug) then {systemchat format ["%1 lasing %2 of %3!",name _JTAC,_dispName,groupID group _target]};
		waituntil {if (alive _x) then {sleep 3};!alive _x OR !alive _JTAC};
		if (!alive _JTAC) exitWith {deleteVehicle _laser};
		deleteVehicle _laser;
		if (_debug) then {systemchat format ["%1, %2 is dead!",name _JTAC,groupID group _target]};
		sleep 1;
		if !(GOM_fnc_LaserOn) exitWith {
		deleteVehicle _laser;
		if (_debug) then {systemchat format ["%1, no more lasing!",name _JTAC]};
		sleep 1;
		};
		};
		} forEach _enemies;


		} else {

		if (_debug) then {systemchat format ["%1, no enemies.",name _JTAC]};
		sleep 1;

		};

	sleep 3;
	};

};


//call the function:
_JTAC = YOURJTACUNIT;
_lase = [_JTAC] spawn GOM_fnc_spawnLaserOnInfantry;

Works side independent, so if JTAC unit is east he will lase west infantry, etc.

If you want to stop the lasing simply use:

_JTAC setVariable ["GOM_fnc_LaserOn",false];

 

This snippet makes JTAC unit lase nearby enemy infantry with a group size of more than 2 units.

JTAC unit itself won't fire on enemies unless being hit.

JTAC unit will stop lasing when being hit.

 

Cheers

Edited by Grumpy Old Man
optimized and updated snippet to work with multiple jtacs on multiple sides simultaneously
  • Like 1

Share this post


Link to post
Share on other sites

WOW, I'm going to try this out ASAP and try and understand how the code is working.

 

Thank you SO MUCH :D

Share this post


Link to post
Share on other sites

Updated the script snippet and edited the post above.

Should now work for multiple JTAC units on the same side for multiple sides

 

Cheers

  • 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

×