Jump to content
Sign in to follow this  
ZU23

Make AI reveal all units

Recommended Posts

Hello Im trying to make a script that causes all of the AI to reveal all units on the map, I tried this but it did not work

[]spawn {
while {true} do {
{
(_x) reveal [_x,1];
} forEach allUnits;
};
};

 

Share this post


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

Hello Im trying to make a script that causes all of the AI to reveal all units on the map, I tried this but it did not work


[]spawn {
while {true} do {
{
(_x) reveal [_x,1];
} forEach allUnits;
};
};

 

Hey ZU23!

Basically what you are doing is revealing them from therselves since _x is the same, until it hops onto the next unit.

 

_X is triggered for allUnits. So lets take _Unit0 as an example for this. You are revealin _unit0 to _unit0. ( _Unit0 reveal [_unit0,1];

 

You need tochange the second _x value to prevent that from happening.

 

Cheers,

CP~

Edited by CreativeProduct
Misclicked

Share this post


Link to post
Share on other sites

If you have a set number of units, I THINK (s not tested yet, duh.) you could do the following:

 

P.S.: It's late, so there could be some errors.

 

Cheers,

CP~

_MaxUnits = count Allunits;
While {true} do 
{
  	_Count = 0;
	if (_count < _MaxUnits) then 
	{
		{
			_count = _count + 1;
			_x reveal [(allUnits select _count),1];
		} forEach allUnits;
	};
 Sleep 20; //To prevent explosions
};

Share this post


Link to post
Share on other sites
2 minutes ago, CreativeProduct said:

If you have a set number of units, I THINK (s not tested yet, duh.) you could do the following:

 

P.S.: It's late, so there could be some errors.

 

Cheers,

CP~


_MaxUnits = 20 //Lets assume you have 20 units running around
While {true} do 
{
  	_Count = 0;
	if (_count < _MaxUnits) then 
	{
		{
			_count = _count + 1;
			_x reveal [(allUnits select _count),1];
		} forEach allUnits;
	};
 Sleep 20; //To prevent explosions
};

Thanks, the key here was "(allUnits select _count)" got it working by simplifying it to this

[]spawn {
while {true} do {
{
(_x) reveal [(allUnits select 0),1];
} forEach allUnits;
};
};

 

Share this post


Link to post
Share on other sites
Just now, ZU23 said:

Thanks, the key here was "(allUnits select _count)" got it working by simplifying it to this


[]spawn {
while {true} do {
{
(_x) reveal [(allUnits select 0),1];
} forEach allUnits;
};
};

 

Oh, even a lot simpler than I thought. Interesting.

 

Keep it up!

 

Cheers,

CP~

Share this post


Link to post
Share on other sites

 

5 hours ago, ZU23 said:

Hello Im trying to make a script that causes all of the AI to reveal all units on the map, I tried this but it did not work


[]spawn {
while {true} do {
{
(_x) reveal [_x,1];
} forEach allUnits;
};
};

 

 

As said before, this will reveal every unit to itself, defeating the purpose.

Also "while {true}" loops are bad practice, always use variables so you're able to stop the loop from running whenever you want, especially for debugging so you don't have to restart the mission to stop the loop from running.

 

3 hours ago, CreativeProduct said:

If you have a set number of units, I THINK (s not tested yet, duh.) you could do the following:

 

P.S.: It's late, so there could be some errors.

 

Cheers,

CP~


_MaxUnits = count Allunits;
While {true} do 
{
  	_Count = 0;
	if (_count < _MaxUnits) then 
	{
		{
			_count = _count + 1;
			_x reveal [(allUnits select _count),1];
		} forEach allUnits;
	};
 Sleep 20; //To prevent explosions
};

 

This will most likely only run once, since you never reset _count. Once _count reaches the amount of all units the if condition will always return false, unless you spawn more units.

 

3 hours ago, ZU23 said:

Thanks, the key here was "(allUnits select _count)" got it working by simplifying it to this


[]spawn {
while {true} do {
{
(_x) reveal [(allUnits select 0),1];
} forEach allUnits;
};
};

 

 

This will only reveal the first unit from allUnits to allUnits in a loop that's running forever without sleep, worst thing you can do performance wise.

 

If I understood right you want to reveal every unit to every unit @ZU23?

 

Sounds like it's going to be quite performance heavy, so lets check for performance first.

To test performance I placed 10x 10-man groups for each east and west for worst performance outcome:

{

	_unit = _x;
	{_unit reveal _x} forEach allUnits;

} forEach allUnits;

Result:
44.5217 ms

Cycles:
23/10000

Ouch, that's something you DEFINITELY don't want to run in a while true loop without sleep.

Now, we know that groups share all target info amongst the units inside them, so we could share all unit to group leaders only:

{ 
 
_group = _x;
{_group reveal _x} forEach allUnits; 
 
} forEach allGroups;

Result:
4.65581 ms

Cycles:
215/10000

That's already better but still expensive as hell, considering code only runs for 3ms, halts and continues on the next frame.

 

We also know that forEach isn't the best command for speed, so let's try count instead:

{  
    
_group = _x; 
{_group reveal _x,true} count allUnits;  //count expects bool, so we return true inside
    
} forEach allGroups;

Result:
4.44889 ms

Cycles:
225/10000

Only a tiny increase, but there's still apply, which should be even faster:

 

{  
    
_group = _x; 
allUnits apply {_group reveal _x};  
    
} forEach allGroups;

Result:
3.66058 ms

Cycles:
274/10000

 

3.66ms, that's fair enough for such a cpu heavy operation.

As stated before, this could be optimized further depending on what @ZU23 wants, but for revealing all units to all units that's as good as it gets, if anyone has a faster solution feel free to post!

These snippets were tested on the VR map with one player unit, 10x 10man blufor groups, 10x 10man opfor groups.

 

Now for the final loop:

_autoReveal = [] spawn {

	ZU23_fnc_autoRevealActive = true;

	while {ZU23_fnc_autoRevealActive} do {

		{ 
		 
			_group = _x;
			allUnits apply {_group reveal _x}; 
		 
		} forEach allGroups;

		sleep 5;

	};
};

 

Cheers

  • Like 2

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  

×