Jump to content
willithappen

AddEditableUnit if unit is seen by unit

Recommended Posts

Hi all, back with another obscure question.

 

For the past hour i've tried several ways to do the following:

 

Needed Script

IF BLUFOR Unit spots an enemy via [Tried knowsabout and FindNearestEnemy] then add the spotted unit as a curatorEditableObject.
Then if the unit gets too far away or is no longer seen, remove them from being editable.

 

The reason I am trying to do this is I am creating a gamemode where the commanding player is in zeus and branches off to different bases held by AI to begin with. I'd like to be able to run whatever code on ALL BLUFOR units so that ANY BLUFOR units that find an enemy can do the above. This is a singleplayer mission.

 

I believe i've seen a similar question on something similar before but I am unable to locate it (Searched to page 10 for search results on "Zeus/Curator/EditableObjects/ Zeus/Curator Add).

 

The below works for half of the above.

_unit = _this select 0;
while {true} do
{
sleep 1;
_enemy = _unit findNearestEnemy _unit;
_foundunits = WEST knowsAbout _enemy;
WH_Zeus addCuratorEditableObjects [[_enemy],true];
};

I need to know how to run this on ALL BLUFOR. I tested the above on a single editor placed unit and once it locates hostiles it adds them to zeus editable.

Share this post


Link to post
Share on other sites


while{true}do{

sleep 1;

{

if((side _x) == west)then{

_lu = _x;

{

if (((side _x) == east)or(/*(side _x) == independent)*/)then{

if ((west knowsAbout _x) >= 2)then{

cmIlias addcuratoreditableobjects [[_x],true];

}else{

cmIlias removecuratoreditableobjects [[_x],true];

};

};

}foreach (_lu nearObjects 2000);

};

}foreach allunits;

};

Share this post


Link to post
Share on other sites

Doesn't seem to work t.a.6.

Don't recieve any errors, the enemy units do not show up? Have changed the knows about value down a bit so they detect easier aswell still won't work.

Any Ideas?

Share this post


Link to post
Share on other sites

Doesn't seem to work t.a.6.

Don't recieve any errors, the enemy units do not show up? Have changed the knows about value down a bit so they detect easier aswell still won't work.

Any Ideas?

You changed |cm| on your curator module name?

Found mistake, sorry, refresh, copy the code again.

Share this post


Link to post
Share on other sites

Have tried again with edited code. Same result. (I am indeed changing |CM| to name of my zeus module, even tried name of zeus gamelogic)

Share this post


Link to post
Share on other sites

 

1 bracked was missing, soorry ) , fixed, tested.

(think, should replace " knowsabout " with something else, find what will be best for you) (and can increase range `(looking for objects around the unit to add or remove from zeus)or:

while{true}do{
sleep 1;
{
if ((side _x) == east)then{
	if ((west knowsAbout _x) >= 2)then{
		|cm| addcuratoreditableobjects [[_x],true];
	}else{
		|cm| removecuratoreditableobjects [[_x],true];
	};
};
}foreach allunits;
};

 - will check if any enemy unit are known to west side)(can |-| the sleep too).

*-----

uhhhh...

Guies will be fine:

_cm = |cm|;
_n = |n (number (~100 or 50 (if see then <1, so) are fine i guies), range - how far enemy should be from place where any friendly unit think he is)|;

while{true}do{
	{if ((side _x) == west)then{
		_u = _x;
		{if ((side _x) == east)then{
			if(((_u getHideFrom _x) distance (getposatl _x))<_n)then{
				_cm addcuratoreditableobjects [[_x],true];
			}else{
				_lu = _x;
				_lst = true;
				{if((side _x) == west)then{
					if(((_x getHideFrom _lu) distance (getposatl _lu))<_n)exitwith{
						_lst = false;
					};
				};}foreach allunits;	
				if(_lst)then{
					_cm removecuratoreditableobjects [[_lu],true];
				};
			};
		};}foreach allunits;
	};}foreach allunits;
};

Not genially and not precise right, but sure is working.

(sorry for the |'answer's mistakes'|, was busy with transporting script)

Share this post


Link to post
Share on other sites

Hey mate, using the top script you sent in your post works fine, doesn't remove enemy units after they aren't known of or the unit that knew about them died.

I can't decipher how to use the second script and how many variables I need under _n.
I have tried with 100 in there but it doesn't' work nor give errors.

Can you  give me a numbered example for that section of the script?

Share this post


Link to post
Share on other sites
_cm = |cm|;
_n = 100;

while{true}do{
	{if ((side _x) == west)then{
		_u = _x;
		{if ((side _x) == east)then{
			if(((_u getHideFrom _x) distance (getposatl _x))<_n)then{
				_cm addcuratoreditableobjects [[_x],true];
			}else{
				_lu = _x;
				_lst = true;
				{if((side _x) == west)then{
					if(((_x getHideFrom _lu) distance (getposatl _lu))<_n)exitwith{
						_lst = false;
					};
				};}foreach allunits;	
				if(_lst)then{
					_cm removecuratoreditableobjects [[_lu],true];
				};
			};
		};}foreach allunits;
	};}foreach allunits;
}; 

it's working, just not when unit see enemy, after loosing line of sight, problem is in:

((_x getHideFrom _lu) distance (getposatl _lu))<_n

, need to replace with something to determine when to add|remove unit.

(knows about value do not going down, ever)

Did it, i guies ) , ) know, hope the last one ) (and think actualy):

_cm = |cm|;
_n = 70;

while{true}do{
	{if ((side _x) == west)then{
		_u = _x;
		{if ((side _x) == east)then{
			if(((assignedTarget _u) == _x)or(((_u getHideFrom _x) distance (getposatl _x))<_n))then{
				_cm addcuratoreditableobjects [[_x],true];
			}else{
				_lu = _x;
				_lst = true;
				{if((side _x) == west)then{
					if(((assignedTarget _x) == _lu)or(((_x getHideFrom _lu) distance (getposatl _lu))<_n))exitwith{
						_lst = false;
					};
				};}foreach allunits;
				if(_lst)then{
					_cm removecuratoreditableobjects [[_lu],true];
				};
			};
		};}foreach allunits;
	};}foreach allunits;
};

Share this post


Link to post
Share on other sites

Surely you dont want to do this for all units. You dont need a curator editable object if its the other side of the map to where the curator currently is?

How about targetsQuery? and only query nearby west units for their targets? targetsQuery can be quite CPU intensive so would need playing with.

Untested but im thinking something along the lines of...

while { true } do {
	
	//Get curator position
	_pos = getPosATL _curator;
	//Save check time
	_lastcheck = time;
	
	//For each nearby west unit
	{
		//Query it for its targets of side east
		_targets = _x targetsQuery [ objNull, east, "", [], 0 ];
		
		//For each target
		{
			_x params[
				"_accuracy",
				"_target"
			];
			
			//if its a match and not in curator editable object
			if ( _accuracy isEqualTo 1 && { !( _target in curatorEditableObjects _curator ) } ) then {
				//Add it and any crew if its a vehicle
				_curator addCuratorEditableObjects [ [ _target ], true ];
			};
		}forEach _targets;
	}forEach ( _curator nearEntities [ "B_Soldier_base_F", 500 ] );
	
	//Clean up curator editable objects
	{
		//If is dead OR is 500+ meters away OR is no longer know by WEST
		if ( !alive _x || { _x distanceSqr _curator > 500^2 || { west knowsAbout _x < 2 } } ) then {
			//Remove it and its crew if its a vehicle
			_curator removeCuratorEditableObjects [ [ _x ], false ];
			//Flag for removal
			_curatorObjects set [ _forEachIndex, -1 ];
		};
	}forEach _curatorObjects;
	
	hint str _curatorObjects;
	
	//Clean up array
	_curatorObjects = _curatorObjects - [ -1 ];
	
	//Wait until curator has moved 100 meters OR it has been a minute since last check
	waitUntil { getPosATL _curator distanceSqr _pos > 100^2 || time - _lastcheck > 60 };
};
So your only querying nearby west units for their known targets. If these known targets become either unknown or a certain distance from the curator then remove them! ?

Share this post


Link to post
Share on other sites

Almost perfect:

_cm = cmIlias;
_n = 50;

while{true}do{
	{if ((side _x) == west)then{
		_u = _x;
		{if ((side _x) == east)then{
			_lst = true;
			if((_x getvariable "pstcae")select 0)then{_lst = (_x getvariable "pstcae") select 1};
			if((if((typename _lst)!="bool")then{((assignedTarget _u)==_x)}else{(_lst)})and(((assignedTarget _u) == _x)or(((_u getHideFrom _x) distance (getposatl _x))<(if(!((vehicle _x)iskindof "man"))then{_n}else{_n*2}))))then{
				_cm addcuratoreditableobjects [[_x],true];
				[_x,_cm] spawn {for"_cn"from 0 to 20 do{sleep 1;};_this select 1 removecuratoreditableobjects [[_this select 0],true];_this select 0 setvariable ["pstcae",[true,0],false];};
				_x setvariable ["pstcae",[true,false],false];
			}else{
				_lu = _x;
				_lst = true;
				{if((side _x) == west)then{
					if(((assignedTarget _x) == _lu)or(((_x getHideFrom _lu) distance (getposatl _lu))<(if(!((vehicle _x)iskindof "man"))then{_n}else{_n*2})))exitwith{
						_lst = false;
					};
				};}foreach allunits;
				if(_lst)then{
					_cm removecuratoreditableobjects [[_lu],true];
					_lu setvariable ["pstcae",[true,true],false];
				};
			};
		};}foreach allunits;
	};}foreach allunits;
};

A bit slower then should be ) .

(unit will be added if seen or known by friendly unit, will be removed if unseen by friendly units 20 seconds (readded if seen), or are further than (if vehicle then 100, if man then 50)m. from point it was known).

Share this post


Link to post
Share on other sites

Some here is some problem

_cm = cmIlias;
_n = 50;

_sa = [];
_cn = 0;

while{true}do{{if(((side _x)==east)and(_x iskindof"man"))then{
	if(!(_x in _sa))then{
		_x setvariable["cuae",[true,scriptnull],false];
		_sa = _sa + [_x];
	};
	_u = _x;
	if(_cn > 19)then{
		_la = [];
		{if(alive _x)then{_la = _la + [_x];};}foreach _sa;
		_sa = _la;
	};
	_cn = _cn + 1;
	_vtr = false;
	_a = _u getvariable "cuae";
	_st = false;
	_st1 = true;
	{if((side _x)==west)then{
	if(
		(
			if(typename(_vtr)!="bool")then{(
				(assignedTarget _x) == _u
			)}else{(
				_vtr
			)}
		)and(
			(
				(assignedTarget _x) == _u
			)or(
				(
					(_x getHideFrom _u) distance (getposatl _u)
				)<(
					if(
						(vehicle _u)iskindof "man"
					)then{
						_n
					}else{
						_n*2
					}
				)
			)
		)
	)then{
		_st=true;
	}else{
	if(!(
		(
			(assignedTarget _x)!= _u
		)or(
			(
				(_x getHideFrom _u) distance (getposatl _u)
			)>=(
				if(
					(vehicle _u)iskindof "man"
				)then{
					_n
				}else{
					_n*2
				}
			)
		)
	))then{
		_st1 = false;
	};
	};
	};}foreach allunits;
	if(_st)then{
		_cm addcuratoreditableobjects[[_u],true];
		terminate(_a select 1);
		[_u,_cm] spawn{_lu = _this select 0;_lu setvariable["cuae",[0,_thisscript],false];sleep 20;_this select 1 removecuratoreditableobjects[[_lu],true];};
	}else{
	if(_st1)then{
		_cm removecuratoreditableobjects[[_u],true];
		terminate(_a select 1);
		_u setvariable["cuae",[true,scriptnull],false];
	};
	};
};}foreach allunits;};

Share this post


Link to post
Share on other sites

Larrow,

Your method has an undefined variable "_CuratorObjects" I tried defining it myself but Wasn't sure exactly what it needed to be?

 

 

 

T.A.6,

Your post from yesterday works just how I need it.
Only thing I'd ask if you are willing is maybe document it a little bit?
is the "_n = 50" value how far away from the unit it will check?

Share this post


Link to post
Share on other sites

Larrow,

Your method has an undefined variable "_CuratorObjects" I tried defining it myself but Wasn't sure exactly what it needed to be?

As i said untested, it was more of a thought than working code. _curatorObjects would need defining before the while as a blank array, it was meant as an array to hold all current editable objects so they could be referenced and removed when no longer needed/in range etc.

Share this post


Link to post
Share on other sites

T.A.6,

Your post from yesterday works just how I need it.

Only thing I'd ask if you are willing is maybe document it a little bit?

is the "_n = 50" value how far away from the unit it will check?

How far enemy should be from point where friendlies think he is to delete him (for vehicles the value *2).

(Last one working 300% faster, but there is a problem somewhere).

Share this post


Link to post
Share on other sites

As i said untested, it was more of a thought than working code. _curatorObjects would need defining before the while as a blank array, it was meant as an array to hold all current editable objects so they could be referenced and removed when no longer needed/in range etc.

I'll have a play around with gathering all current editable objects see if i can't get that to work.

 

How far enemy should be from point where friendlies think he is to delete him (for vehicles the value *2).

(Last one working 300% faster, but there is a problem somewhere).

For some reason enemy vehicles don't get added to Curator, any ideas why? I've tried changing the "iskindof "man"" to Land or AllVehicles to try to pickup the cars but still no luck.

Share this post


Link to post
Share on other sites

I'll have a play around with gathering all current editable objects see if i can't get that to work.

 

For some reason enemy vehicles don't get added to Curator, any ideas why? I've tried changing the "iskindof "man"" to Land or AllVehicles to try to pickup the cars but still no luck.

I guies " allunits " - only units.

(i thought you need the script for zeus see where seen enemies are.?.)

and you can delete the checkings if do not have headquarters entities in mission.

Share this post


Link to post
Share on other sites

I guies " allunits " - only units.

(i thought you need the script for zeus see where seen enemies are.?.)

and you can delete the checkings if do not have headquarters entities in mission.

Haven't Tried all units as of yet.

To explain about the vehicles, if there's an enemy vehicle [so there's hostiles in it] I want it to be added to zeus just like the infantry currently are so it's easier to see and select friendly units to target it.

Share this post


Link to post
Share on other sites

Haven't Tried all units as of yet.

To explain about the vehicles, if there's an enemy vehicle [so there's hostiles in it] I want it to be added to zeus just like the infantry currently are so it's easier to see and select friendly units to target it.

You can target crew, it will be same, isnt it?

(for all entries can use " nearobjects ").

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

×