Jump to content
kocrachon

If knows about, and distance, foreach?

Recommended Posts

Hey All,

 

I am trying to write a script that essentially does this.

 

For every unit on EAST/Opfor,, check to see if _x enemy group knows about _x units in BlueFor group.I am trying to write a script that says "If any OpFor group knowsabout > 2 the bluefor group, and is a distance of 100 from them, set a seek and destroy waypoint a random area around them.

 

The problem I am running into, is how do I make it work so that it does a check for every group on east side. I tried this on each group, but does not seem to work

 

 

_test = [] spawn {{ 
if (enemygroup1 knowsAbout _x > 2) then  

hint "enemy knows"; 
}; 
} forEach units squad1;}

Share this post


Link to post
Share on other sites

This will return all EAST groups which know about at least one unit in the group squad1:
 

_enemyGroups = allGroups select {
	side _x isEqualTo EAST &&
	{
		private _group = _x;
		{(_group knowsAbout _x) > 2} count (units squad1) > 0
	}
};

 

Share this post


Link to post
Share on other sites
1 minute ago, hallyg said:

This will return all EAST groups which know about at least one unit in the group squad1:
 


allGroups select {
	side _x isEqualTo EAST &&
	{
		private _group = _x;
		{(_group knowsAbout _x) > 2} count (units squad1) > 0
	}
};

 

 

 

So, dumb question.

 

Where would I put this? init?

 

This is part of where I run into issues. I often times have no idea how or where to exectute these types of things.

Share this post


Link to post
Share on other sites

Wherever you are running your script from but for now the init should suffice. The _enemyGroups will contain all the enemy groups so you can then use that to operate on for you S&D waypoints.

This will only take the groups at the start of the mission, though.

Share this post


Link to post
Share on other sites
8 minutes ago, hallyg said:

Wherever you are running your script from but for now the init should suffice. The _enemyGroups will contain all the enemy groups so you can then use that to operate on for you S&D waypoints.

This will only take the groups at the start of the mission, though.

 

Yeah all groups exist at the start of the mission, nothing is created or spawned, so this works great.

 

Last question, if I run this in init, does it do a continuous check, or do I need to do something like a while true loop? Because each time a new group learns about "Squad1" I want them to add a waypoint to them, basically I want the AI to constantly respond to the enemy threat. So I want this to be checking the entire time the mission runs, constantly checking for each group. 

Share this post


Link to post
Share on other sites
4 minutes ago, kocrachon said:

 

Yeah all groups exist at the start of the mission, nothing is created or spawned, so this works great.

 

Last question, if I run this in init, does it do a continuous check, or do I need to do something like a while true loop? Because each time a new group learns about "Squad1" I want them to add a waypoint to them, basically I want the AI to constantly respond to the enemy threat. So I want this to be checking the entire time the mission runs, constantly checking for each group. 


You'll need to create you own while loop, yeah

Share this post


Link to post
Share on other sites
32 minutes ago, hallyg said:


You'll need to create you own while loop, yeah

 

Hmm, trything this, but it tells me I am missing a break some where..

 


 

while {true} do { if (
allGroups select {
    side _x isEqualTo EAST &&
    {
        private _group = _x;
        {(_group knowsAbout _x) > 2} count (units squad1) > 0
        }
    }) then (hint "they know")
};

 

Share this post


Link to post
Share on other sites

@kocrachon The code I posted returns an array and is stored in the local variable _enemyGroups. The 'if' statement requires its condition to return a BOOLEAN. To do this you could check if the resultant array, _enemyGroups, has a count greater than 0. The array is empty when no groups know about the units. It is populated when the group(s) know about the units.

Therefore, you can use this:
 

while {true} do {
	_enemyGroups = allGroups select {
		side _x isEqualTo EAST &&
		{
			private _group = _x;
			{(_group knowsAbout _x) > 2} count (units squad1) > 0
		}
	};
		
	if (count _enemyGroups > 0) then {
		hint "they know";
	};
		
	sleep 0.025;
};

 

Share this post


Link to post
Share on other sites
15 minutes ago, hallyg said:

@kocrachon The code I posted returns an array and is stored in the local variable _enemyGroups. The 'if' statement requires its condition to return a BOOLEAN. To do this you could check if the resultant array, _enemyGroups, has a count greater than 0. The array is empty when no groups know about the units. It is populated when the group(s) know about the units.

Therefore, you can use this:
 


while {true} do {
	_enemyGroups = allGroups select {
		side _x isEqualTo EAST &&
		{
			private _group = _x;
			{(_group knowsAbout _x) > 2} count (units squad1) > 0
		}
	};
		
	if (count _enemyGroups > 0) then {
		hint "they know";
	};
		
	sleep 0.025;
};

 

 

Sweet, perfect, thank you.

 

VERY last question. One thing I am looking to do, is limit who reacts. So basically, I want to do (If THIS group knows about Squad1 AND is distance <= 100). So far, it seems like what you have shown me is how to make it so that every single group would react. How do I make it so that only react?

 

Say like. if (_enemyGroups distance squad1 <= 100) then {createwaypoint blah blah blah) would that work? 

Share this post


Link to post
Share on other sites

The distance command requires its parameters to be of the type ARRAY or OBJECT. Squad1 and the enemy groups have the type GROUP so you need to calculate their position before you can calculate the distance. This can be done by either taking the mean position of all the units in the group or by taking the position of the leader of the group. The latter can be done by using:
 

_pos = getPosASL leader GROUP

This can be used in the following to return an array of groups which are within 100m of the group squad1:
 

while {true} do {
	_enemyGroups = allGroups select {
		side _x isEqualTo EAST &&
		{
			private _group = _x;
			{(_group knowsAbout _x) > 2} count (units squad1) > 0
		}
	};
		
	if (count _enemyGroups > 0) then {
		hint "they know";
	};
	
	_closeGroups = _enemyGroups select {((getPosASL leader _x) distance (getPosASL leader squad1))<= 100};

		
	sleep 0.025;
};

You can then select the groups from the _closeGroups array and add waypoints to them as you wish.

  • Like 1

Share this post


Link to post
Share on other sites

@hallyg

 

Thanks for all the help. Although I do Python scripting a lot, SQF/SQM is still very weird to be when combined with the arma commands. Thank you for all the help!

  • 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

×