Jump to content
Sign in to follow this  
garnett21a

How to "AI sharing target info". need help

Recommended Posts

It has been a while since I bring this on. and finally I finished it with a small "neat" script.

Usage:

1. recieve info from the whole side: nil = [] execVM "Intelsys.sqf";

2. recieve info from selected units (could be one or multiple): nil = [unit1, unit2, ......] execVM "Intelsys.sqf";

my current updated script which works quite well:

if (!isServer) exitWith {};

private [ "_condition", "_targetlist", "_mklist", "_updatelist", "_cntC", "_target", "_mkname", "_i"];




// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =   
//									Phase 0: Settings 
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  

switch true do
{
case (count _this == 1): 
{
	_condition = ( alive (_this select 0) );
};

case (count _this > 1): 
{ 
	_condition = ( {alive _x} count _this > 0 ); 
};

case (count _this == 0): 
{
	_condition = ( {side _x == side player} count allunits > 1 ); 
};
};

if ( !(_condition) ) exitWith 
{ 
[West,"HQ"] sideChat "Lost contact with intel update source. System offline";
};

_targetlist = [];
_mklist = [];

[West,"HQ"] sideChat "Initiating Cross Intel System... To be advised: All data is expected to delay for approximately 4 seconds"; 

sleep 0.1;

while { _condition } do
{

_cntC = count _targetlist;
_updatelist = [];

uisleep 3;

switch true do
{
	case (count _this == 1): 
	{
		{ 
			if ((group (_this select 0) knowsAbout _x) > 1 and alive _x) then {_updatelist = _updatelist + [_x];}; 
		}foreach (allunits + vehicles);
	};

	case (count _this > 1): 
	{ 
		for "_i" from 0 to (count _this - 1) do
		{
			{ 
				if ( (group (_this select _i) knowsAbout _x) > 1 and alive _x and !(_x in _updatelist) ) then {_updatelist = _updatelist + [_x];}; 
			}foreach (allunits + vehicles);
		};		 
	};

	case (count _this == 0): 
	{
		{ 
			if ((side player knowsAbout _x) > 1 and alive _x) then {_updatelist = _updatelist + [_x];}; 
		}foreach (allunits + vehicles);
	};
};

sleep 0.1;
//hint format ["list of targets: %1", _updatelist];
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =   
//					Phase 1: Remove invalid elements
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  	

_targetlist = _targetlist - (_targetlist - _updatelist);

if ((_cntC - count _targetlist) >= 1) then
{
	for "_x" from (count _targetlist) to (_cntC - 1) do
	{
		_mkname = "mk" + str (_x);
		deleteMarkerLocal _mkname;
	};	
};

sleep 0.1;
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =   
//					Phase 2: Add new elements
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =	

_cntC = _updatelist - _targetlist;

if ((count _updatelist - count _targetlist) >= 1) then
{
	for "_x" from (count _targetlist) to (count _updatelist - 1) do
	{
		_target = _cntC select (_x - count _targetlist) ;
		_mkname = "mk" + str(_x);

		createMarker [_mkname, getPos _target ];
		_mkname setMarkerShapeLocal "Icon";
		_mkname setMarkerTypeLocal "Destroy";	
	};
};

sleep 0.3; 	
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =   
//					Phase 3: Update marker and array
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =	

_targetlist = _targetlist + (_updatelist - _targetlist);


for "_x" from 0 to (count _targetlist - 1) do
{
	_target = _targetlist select _x;
	_mkname = "mk" + str(_x);
	switch true do 
		{
			case ( _target isKindOf "Man" ): {_mkname setMarkerTypeLocal "DOT";};
			case ( _target isKindOf "Car" ): {_mkname setMarkerTypeLocal "Car";};
			case ( _target isKindOf "Motorcycle" ): {_mkname setMarkerTypeLocal "Car";};
			case ( _target isKindOf "Tank" ): {_mkname setMarkerTypeLocal "Tank";};
			case ( _target isKindOf "Air" ): {_mkname setMarkerTypeLocal "Air";}; 
			case ( _target isKindOf "Ship" ): {_mkname setMarkerTypeLocal "Boat";}; 
			case ( _target isKindOf "StaticWeapon" ): {_mkname setMarkerTypeLocal "Man";};
		};
	_mkname setMarkerPosLocal getPos _target;
	_mkname setMarkerDirLocal getDir _target;
	_mkname setMarkerAlphaLocal (1 - getDammage _target);
};

};

if ( true ) exitWith 
{ 
{deleteMarkerLocal _x} forEach _mklist;
[West,"HQ"] sideChat "Lost contact with intel update source. System offline";
};

Edited by garnett21a
script now functional with side or multiple units as spotter

Share this post


Link to post
Share on other sites

Updated and finally works.

Just wondering what code to use for this to be functional in MP.

Any tips?

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  

×