Jump to content
Sign in to follow this  
heinzmcdurgen

Locking helo except for pilots

Recommended Posts

Does anyone have any thoughts on how to do this?

I want to have the ability to lock all players out of helos unless they are helo pilots. Allowing access by named units would be the easiest/best solution.

Thanks!

Share this post


Link to post
Share on other sites

Put this in your init.sqf :

allowedPlayers = ["P1","P2"];

put this on the vehicles you want to restrict :

this addEventHandler ["GetIn", {

if (driver (_this select 0) == (_this select 2) ) then {

if (!(vehicleVarName (_this select 2) in allowedPlayers)) then {

moveOut (_this select 2);

Hint "You are not Allowed!";

};

};

}];

Note: add unit names to allowedplayers array to allow access, this currently only looking at the name of unit given to it in the editor, if you want to use real player name just change "vehicleVarName" to "playerName";

this has no infinite loop so there is close to no server stress.

Share this post


Link to post
Share on other sites

Outstanding. I was a little shocked when you said P1 and P2... that's what the unit names are! Haha.

I'll give it a shot. Thanks again!

---------- Post added at 04:51 AM ---------- Previous post was at 04:28 AM ----------

Put this in your init.sqf :

put this on the vehicles you want to restrict :

Note: add unit names to allowedplayers array to allow access, this currently only looking at the name of unit given to it in the editor, if you want to use real player name just change "vehicleVarName" to "playerName";

this has no infinite loop so there is close to no server stress.

Alright, so this is only letting "P1" access the pilot seat. Other named units (such as P2 and a third slot) cannot access the helo at all. They can open the inventory, but cannot even ride in the back. Non-named units can get in the pilot seat, but are kicked out. They can ride in the back however.

Share this post


Link to post
Share on other sites
just checked it, works fine

Yep. Tested it server-side and it works great. It wasn't working previewing the mission. Sorry for the confusion. Thanks again!

Share this post


Link to post
Share on other sites

Thanks for this! how would i use this to restrict players from a uav, and also tanks, and items like pda or what ever

Share this post


Link to post
Share on other sites

restricting players from items and uav is a different ball game, but this should work for the tank, it will strict the tank driver, if you want to strict the gunner then replace "driver" with "gunner"

Share this post


Link to post
Share on other sites
restricting players from items and uav is a different ball game, but this should work for the tank, it will strict the tank driver, if you want to strict the gunner then replace "driver" with "gunner"

Will it work for land vehicles?

For air vehicles, the player cannot switch seats to the pilot seat(s).

For land vehicles, the player can 'getIn' as cargo and then switch seats to driver, bypassing the EHs purpose.

Share this post


Link to post
Share on other sites

so just figured out on a mp server when ever anyone trys to enter the pilot seat whos not a pilot, it tells all the users on the server that they are not a pilot. Also when entering a little bird and getting the not pilot msg it then blows up after.

Share this post


Link to post
Share on other sites
so just figured out on a mp server when ever anyone trys to enter the pilot seat whos not a pilot, it tells all the users on the server that they are not a pilot. Also when entering a little bird and getting the not pilot msg it then blows up after.

Here is a tweak of iConics code for MP.

this addEventHandler [
"GetIn",
{
	_v = _this select 0;
	_player = _this select 2;
	_on = owner _player;
	if (_player == (driver _v)) then {
		if (!((vehicleVarName _player) in allowedPlayers)) then {
			[
				{
					sleep 2;
					if (!((vehicle player) isKindOf "Man")) then {
						moveOut player;
					}; 
					hintSilent "You are not Allowed!";
				},
				"BIS_fnc_spawn",
				_on,
				FALSE
			] spawn BIS_fnc_MP;
		};
	};
}
];

Edited by MDCCLXXVI

Share this post


Link to post
Share on other sites

if (typeof player != "B_Helipilot_F") then {
  private "_v";
  while {alive player} do {
    waituntil {vehicle player != player};
    _v = vehicle player;
    if (_v iskindof "air,aircraft" && !(_v iskindof "ParachuteBase")) then {
       if (driver _v == player) then {
         player action ["eject",_v];
         waituntil {vehicle player == player};
         hint "We shall leave the piloting to those with the appropriate training.";
       };
     };
   };
 };

this is working for tanks, but not for air. It will give me the msg but will not remove me.

I wanted to try to figure out something for the gunner position in the tanks aswell so that only crew can maintain those 2 spots.

also another issue with your script was i was able to get into the copilot and thank take the controls to still fly.

Edited by onedigita

Share this post


Link to post
Share on other sites
if (typeof player != "B_Helipilot_F") then {
  private "_v";
  while {alive player} do {
    waituntil {vehicle player != player};
    _v = vehicle player;
    if (_v iskindof "air,aircraft" && !(_v iskindof "ParachuteBase")) then {
       if (driver _v == player) then {
         player action ["eject",_v];
         waituntil {vehicle player == player};
         hint "We shall leave the piloting to those with the appropriate training.";
       };
     };
   };
 };

this is working for tanks, but not for air. It will give me the msg but will not remove me.

I wanted to try to figure out something for the gunner position in the tanks aswell so that only crew can maintain those 2 spots.

also another issue with your script was i was able to get into the copilot and thank take the controls to still fly.

if (typeof player != "B_Helipilot_F") then {
  private "_v";
  while {alive player} do {
    waituntil {vehicle player != player};
    _v = vehicle player;
    if (_v iskindof [color="#FF0000"]"air"[/color] && !(_v iskindof "ParachuteBase")) then {
       if (driver _v == player [color="#FF0000"]|| gunner _v == player[/color]) then {
         player action ["eject",_v];
         waituntil {vehicle player == player};
         hint "We shall leave the piloting to those with the appropriate training.";
       };
     };
   };
 };

haven't tested but this should work for air units and also gunner position (Marked red for changes).

Share this post


Link to post
Share on other sites

so it still will not boot them out of choppers or air, but it does pick up the gunner seat. is there a way to kick them out of co pilot aswell?

Share this post


Link to post
Share on other sites

Try this which I use for both my air and ground vehicles and prevents people from bypassing the restriction by swapping to protected seats.

vehicle init

this addEventHandler ['GetIn', {_this execVM 'scripts\Vehicle\Crew.sqf'}];

scripts\Vehicle\Crew.sqf

/*
Crew check script - v0.3
Checks for crew in positions of vehicle
Created by BearBison
*/
/* Private variables */
private ["_Vehicle","_Soldier","_Position","_CrewCheck"];
/* Defines the variables */
_Vehicle = _this select 0;
_Position = _this select 1;
_Soldier = _this select 2;
/* Checks the crew */
_CrewCheck =
{
   switch (_Position) do
   {
       case "driver":
       {
           switch (true) do
           {
               case (_Vehicle isKindOf "Air"):
               {
                   if (typeOf _Soldier == "B_Helipilot_F") exitWith {};
                   _Vehicle vehicleChat "Let's leave piloting to those with the appropriate training!";
                   sleep 1;
                   _Soldier action ["getout",_Vehicle];
               };
               default
               {
                   if (typeOf _Soldier == "B_crew_F") exitWith {};
                   _Vehicle vehicleChat "Let's leave driving to those with the appropriate training!";
                   sleep 1;
                   _Soldier action ["getout",_Vehicle];
               };
           };
       };
       case "gunner":
       {
           switch (true) do
           {
               case (_Vehicle isKindOf "Air"):
               {
                   if (typeOf _Soldier == "B_Helipilot_F") exitWith {};
                   _Vehicle vehicleChat "Let's leave gunning to those with the appropriate training!";
                   sleep 1;
                   _Soldier action ["getout",_Vehicle];
               };
               default
               {
                   if (typeOf _Soldier == "B_crew_F") exitWith {};
                   _Vehicle vehicleChat "Let's leave gunning to those with the appropriate training!";
                   sleep 1;
                   _Soldier action ["getout",_Vehicle];
               };
           };
       };
       case "Turret":
       {
           switch (true) do
           {
               case (_Vehicle isKindOf "Air"):
               {
                   if (typeOf _Soldier == "B_Helipilot_F") exitWith {};
                   _Vehicle vehicleChat "Let's leave gunning to those with the appropriate training!";
                   sleep 1;
                   _Soldier action ["getout",_Vehicle];
               };
               default
               {
                   if (typeOf _Soldier == "B_crew_F") exitWith {};
                   _Vehicle vehicleChat "Let's leave gunning to those with the appropriate training!";
                   sleep 1;
                   _Soldier action ["getout",_Vehicle];
               };
           };
       };
   };
};
/* Calls crew check */
call _CrewCheck;
/* Waits until position is changed */
waitUntil {((assignedVehicleRole _Soldier) select 0 != "cargo")||(vehicle _Soldier == _Soldier)};
sleep 1;
/* Exits if no longer in a vehicle */
if (vehicle _Soldier == _Soldier) exitwith {};
/* Gets new position */
_Position = (assignedVehicleRole _Soldier) select 0;
/* Calls crew check */
call _CrewCheck;


Edited by BearBison
fixed init

Share this post


Link to post
Share on other sites

got an error with that event handler so i tried this

this addEventHandler ['GetIn', {_this execVM 'scripts\Vehicle\Crew.sqf'};]

added a bracket ] at the end

also got this rpt

12:35:59 Error in expression <ition","_CrewCheck"];

_Vehicle = _this select 0;

_Position = _this select 1;

_S>

12:35:59 Error position: <select 0;

_Position = _this select 1;

_S>

12:35:59 Error select: Type Object, expected Array,String,Config entry

12:35:59 File scripts\vehicleRestrictions\CrewCheck.sqf, line 9

Share this post


Link to post
Share on other sites

Serves me right for doing the init quickly :)

Should be

this addEventHandler ['GetIn', {_this execVM 'scripts\Vehicle\Crew.sqf'}];

Share this post


Link to post
Share on other sites

thank you bear but the script still seems to not be working

my rpt regarding it not working

12:35:59 Error in expression <ition","_CrewCheck"];

_Vehicle = _this select 0;
_Position = _this select 1;
_S>
12:35:59 Error position: <select 0;
_Position = _this select 1;
_S>
12:35:59 Error select: Type Object, expected Array,String,Config entry
12:35:59 File scripts\vehicleRestrictions\CrewCheck.sqf, line 9

also just wanted to throw in this needs to work on a multiplayer/dedicated server

---------- Post added at 18:36 ---------- Previous post was at 18:29 ----------

lmfao, i figured it out this addEventHandler ['GetIn', {_this execVM 'scripts\Vehicle\Crew.sqf'}]; is not the same folder or name i named the script :( whoops lol seems were both 2 quick lol

Share this post


Link to post
Share on other sites

It works in MP on a dedi server as it's the only time I play.

Did you move the bracket to the correct position?

A working example of the script can be seen in this test mission for you.

Share this post


Link to post
Share on other sites

ok just checking, about the mp/dedi.

yes it working now 100% now I had not put the correct path in the inti filed to the script.

the only issue and its a small one is when going in a copilot seat it says that i cannot gun but thats small scale. now that was in heli that dosent have a gunner seat but than again would make sense it a cas chopper.

again thats small scale, ill be sure to add your name in a credits text file ill be creating when i make my mission public! :)

Share this post


Link to post
Share on other sites

Hey So this wont seem to work in mp/dedicated servers. any ideas anyone?. it worked in editor but still with some errors but im hoping to get in func in dedi, and would effect anyone who joins after the mission starts aswell

Share this post


Link to post
Share on other sites

Do you have it setup exactly the same as the test mission that I provided as I cannot see why it isn't working for you in dedi, as it works in all of our groups missions for all players without any errors?

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  

×