Jump to content
wogz187

NearEntities (or something)

Recommended Posts

The "Fly ArmA 3" framework is coming along nicely but unlike FTA there are no named entities.

I need something like this to detect and report nearby air-traffic to the player.

trafficAIR=count ((vehicle player) nearEntities ["air", 3000]);

If I use,

    trafficAIR=count ((vehicle player) nearEntities ["air", 3000]); 
    while {true} do {if (trafficAIR  !=0 && proxyWARN==0 ) then {xxxx 

It activates immediately and repeats as per its timer. Counting the player, I assume.

If I use,

    trafficAIR=count ((vehicle player) nearEntities ["air", 3000]); 
    while {true} do {if (trafficAIR >1 && proxyWARN==0 ) then { xxxx

It won't activate at all regardless of the count (as I wrote that I realized I need to hint the count).

Any other ideas how to count nearby air-traffic and make a useful variable out of it?

edit:

Upon further investigation it actually does work as intended. I'm not sure why it wouldn't fire before but as soon as I added the hint it counted "1" at the appropriate time and fired the function.

 

Cool, I guess.

 

Spoiler

fnc_proxyWARNING=
{
null=[]spawn{ 
	trafficAIR=count ((vehicle player) nearEntities ["air", 3000]); 
	while {true} do {if (trafficAIR >1 && proxyWARN==0 ) then { 
 																proxyWARN=1; 
																hint "Air Traffic Caution"; 
																systemChat "Tower, Glorious Bastard. There's traffic in your area. Use caution."; 
														sleep 3; 
																hintSilent ""; 
																player sidechat "Copy, Tower. Traffic acknowledged. Thanks for the heads-up, Tower. Over."; 
														sleep 240; 
												proxyWARN=0; };
		sleep 10;	}; 
			};
};

 


Thanks!

Share this post


Link to post
Share on other sites

Yeah, no. Disregard that. I can't figure out what the above script does. Well, it returns "1" every 10 seconds (when I remove the cool-down timer). I don't know what it's counting but it isn't nearby aircraft.

Solutions? Surely we've counted airplanes before.

More testing,

It is counting but the count doesn't update each time the script runs. It just sticks with whatever the first count was.

 

More testing,

It counts each time the variable is determined separately.

Share this post


Link to post
Share on other sites

Not tested.

 

Spoiler

fnc_proxyWARNING=
{
	null = [] spawn
	{ 
		while {true} do
		{
			//	Moved count inside the loop so it updates.
			trafficAIR = count ((vehicle player) nearEntities ["air", 3000]);

			if (trafficAIR >1 && proxyWARN==0 ) then
			{ 
				proxyWARN=1; 
				hint "Air Traffic Caution"; 
				systemChat "Tower, Glorious Bastard. There's traffic in your area. Use caution."; 
				sleep 3; 
				hintSilent ""; 
				player sidechat "Copy, Tower. Traffic acknowledged. Thanks for the heads-up, Tower. Over."; 
				sleep 240; 
				proxyWARN=0;
			};
			sleep 10;
		}; 
	};
};

 

 

I hope that helps.

  • Thanks 1

Share this post


Link to post
Share on other sites

@Maff,

Thanks for your help. I don't think the variable updates either way. Now that I know the count works I'll just count every once in a while (like the cooldown timer) and if count > threshold then proxywarn.

Thanks again!


 

Spoiler

fnc_atcRadar1=
{
trafficAIR=count ((vehicle player) nearEntities ["AIR", 3000]);

if (trafficAIR >1) exitWith {

trafficAIR=trafficAIR-1;

systemChat format ["Tower, Glorious Bastard. There's traffic in your area. %1 aircraft in visual range. Use caution.", trafficAIR];
trafficAIR=trafficAir+1;
sleep 1;

null=[]spawn fnc_proxyWarning;
	
	};
};

fnc_proxyWARNING=
{
hint "Air Traffic Caution";
sleep 3;
hintSilent "";
player sidechat "Copy, Tower. Traffic acknowledged. Thanks for the heads-up, Tower. Over.";
};

 


This is probably a slicker, albeit more analog solution. It's way more simple and if performance was a factor, this is less strenuous. It's maybe less dynamic but the cool-down timer in the first script nerfed the dynamic element anyway.

Edited by wogz187
updated

Share this post


Link to post
Share on other sites

I gave it a quick test in debug and received an error about proxyWARN.

 

I added proxyWARN = 0; before the while do and it works.

_trafficAIR is updated every loop.

 

 

Spoiler

fnc_proxyWARNING=
{
	null = [] spawn
	{
		proxyWARN = 0;	//	No idea if you have this elsewhere.

		while {true} do
		{
			_trafficAIR = count (vehicle player nearEntities ["air", 3000]); // Changed to private.

			if (_trafficAIR > 1 && {proxyWARN == 0}) then
			{ 
				proxyWARN = 1; 
				hint "Air Traffic Caution"; 
				systemChat "Tower, Glorious Bastard. There's traffic in your area. Use caution."; 
				sleep 3; 
				hintSilent ""; 
				player sidechat "Copy, Tower. Traffic acknowledged. Thanks for the heads-up, Tower. Over."; 
				sleep 240; 
				proxyWARN = 0;
			};
			sleep 10;
		}; 
	};
};

 

 

 

Why are you using spawn inside the function?

Can you not just spawn the function?

 

 

EDIT:

Nevermind. I just saw your edit.

 

Edited by Maff
  • Thanks 1

Share this post


Link to post
Share on other sites

@Maff,

Quote

Why are you using spawn inside the function?


Oh. I think I misunderstood before. Yes. Yes I can. Totally.

The reason it's split into to two functions (remember the text is just testing) is because the first function will always lead to the second function, but the second function can still be called from some place else without extra conditions-- like that proxywarn thing from above.

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

×