Jump to content
thy_

[SOLVED] Show this, except for all players in UAV Gunner position (Help!)

Recommended Posts

My cute A3 dudes, need some help here. 

 

Look this simple example:

 

{
  if ( (_x distance getMarkerPos markerMainbase) < 100 ) then 
  {
		hint "To fight, I must leave the mainbase area!";
  };
} forEach _playersAlive;

 

Now, how can I code for the same message to NOT be shown for players in gunner positions in UAV's from _arrayMyDrones?

 


I already read this content but all my tries are failing... 😞

 

https://community.bistudio.com/wiki/UAVControl

https://community.bistudio.com/wiki/connectTerminalToUAV

https://community.bistudio.com/wiki/isUAVConnected

https://community.bistudio.com/wiki/getConnectedUAV

 

 

 

Share this post


Link to post
Share on other sites

Something like this, maybe?

_uav = getConnectedUAV _x;  
_isGunner = (UAVControl _uav#1);
if ((!isNull _uav) && _isGunner == "GUNNER") then
{
	<_x is a UAV gunner, so what now?>
};

 

Share this post


Link to post
Share on other sites

Almost there.

 

Your code works and I must study it a bit longer to understand how to build it below: a mainbase fire protection where you are NOT able to shoot from within, except whether you're a UAV crew who will play the role from the mainbase insides. 

 

Piece of code:

private ["_arrayMyDrones","_headlessClients","_playersAlive","_playersInUAV","_isUavGunner","_playerFiring","_projectile"];

if (!isServer) exitWith {};

_arrayMyDrones = [uav01, uav02, uav03];



0 = [] spawn
{
	while {true} do
	{  				
		_headlessClients = entities "HeadlessClient_F";	
		_playersAlive = (allPlayers - _headlessClients) select {alive _x};
		
		{
			// _playersInUAV is all _playersAlive connected in a UAV:
			_playersInUAV = getConnectedUAV _x;
			
			// _isUavGunner is the player alive who gets the gunner position in a UAV:
			_isUavGunner = (UAVControl _playersInUAV#1);
			
			// if the player alive is NOT the gunner in a UAV, so...
			if ( _isUavGunner != "GUNNER" ) then 
			{
				// You CANNOT firing from the mainbase:
				_x addEventHandler ["firedman",
				{
					_playerFiring = _this select 0;
					_projectile = _this select 6;
					
					if ( _playerFiring distance (getMarkerPos "blu-air-mainbase") < 300 ) then
					{
						deleteVehicle _projectile;
						"STOP!" hintC ["Don't fire from inside the base!"];
					};
				}];	
			
			};
		
		} forEach _playersAlive;
		
		sleep 1;
	};
};

 

When I run the code below, I try these behaviors from INSIDE the mainbase protection:

...the soldier fires their handgun, the projectile is deleted and shows up a message (CORRECT ✔️);

...the soldier connect the UAV, leave the UAV still on, takes their handgun and fire. The projectile is deleted and shows up a message (CORRECT ✔️); 

...the soldier connects the UAV and, as GUNNER, fires. The projectile is deleted and shows up a message (CORRECT ✔️);
...the soldier connects the UAV and, as DRIVER, fires. The projectile hits something (INCORRECT , should be deleted as well);

 

When I run the code below, I try these behaviors from OUTSIDE the mainbase protection (but UAV crew keeps inside the mainbase):

...the soldier fires their handgun. The projectile hits something (CORRECT ✔️); 

...the soldier connects the UAV and, as GUNNER, fires.  The projectile is deleted and shows up a message (INCORRECT , should be allowed outside the main)

...the soldier connects the UAV and, as DRIVER, fires. The projectile hits something (CORRECT ✔️); 

 

 

Some ideas to fix those bad behaviors?

Share this post


Link to post
Share on other sites

First, for clarity:

_uav = getConnectedUAV _x;     //GET THE UAV THAT PLAYER IS CONNECTED TO, IF ANY
_isGunner = (UAVControl _uav#1);     //GET PLAYER POSITION IN UAV
if ((!isNull _uav) && _isGunner == "GUNNER") then     //IF PLAYER IS INDEED IN UAV AND IS GUNNER
{
	<_x is a UAV gunner, so what now?>
};

So "_isGunner" is a bad name - my fault. I should have used something like "_UAVPosition"

Your variable "_playersInUAV"  (my variable "_uav") is the UAV that a player is in, not the player.

 

So, you want a safezone in your base. There is a safezone object (ProtectionZone_F) you can use, or the ever popular "grenadeStop.sqf" which you can find easily using search. The second might be a good option for you to look at for ideas. I actually don't recall if it addresses UAV gunners or not.

Right now, you are adding an event handler to every player every second, which might not be ideal.

 

Unfortunately, work calls, I'll check in later to help with the rest, unless someone beats me to it.

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, Harzach said:

Right now, you are adding an event handler to every player every second, which might not be ideal.

 

Thanks for said that, @Harzach.

 

I've thinking and a smart move to do is remove that  that addEventHandler "firedman" to preserve the game performance. And putting that aside, it loses the point of identifying whether or not the UAV gunner is operating a UAV.

Soon I will release my mainbase protection here in BIS forum. 

Anyone, thanks for support 😄

 

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

×