Jump to content
Sign in to follow this  
sgt_hawkins

Only Pilots can Fly,Only Crewman can Crew

Recommended Posts

I thought for sure this would have been asked dozens of times on this forum :confused:..but I could not find not one post..Maybe I'm not wording it right..(sigh)

What is the method to make helicopters only usable by pilots...I'm sure the same method is done with Crewman and Armor...

I know this was done in one of sharkattacks missions in Arma..but I dont remember how he did it...

Share this post


Link to post
Share on other sites

Basically you'll add a GETIN eventhandler that would check the class of the unit entering and if it's not Pilot or Crew you'd eject them.

Evolution had this, and with lag you could get around it, but it basically works.

It's really much easier to either play a class limited mission with non-pubbers who will Play Rightâ„¢ or just realize a public mission is gonna be a mess and avoid trying to limit things people will just break. heh

Share this post


Link to post
Share on other sites

I'm sure there are many ways and variations for this.

Here's something I used in a mission, just replace the allowed pilot classname. If there are multiple classes that can fly, the script needs little modification.

 if (typeof player != "USMC_Soldier_Pilot") then {
   private "_v";
   while {alive player} do {
     waituntil {vehicle player != player};
     _v = vehicle player;
     if (_v iskindof "Helicopter" && !(_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.";
       };
     };
   };
 };

---------- Post added at 09:07 PM ---------- Previous post was at 09:03 PM ----------

Getin EH can be cheated by first entering as cargo and then just changing seats.

Share this post


Link to post
Share on other sites

Not working for me..can u be a little more specific on what needs to be done...or send me a link to your mission so I can just figure out what you did...

Edited by Sgt_Hawkins

Share this post


Link to post
Share on other sites

Save that code to a file called pilotCheck.sqf and replace USMC_Soldier_Pilot with US_Soldier_Pilot_EP1. Then in your player's init put:

nul = [] execVM "pilotCheck.sqf";

or run it from the init.sqf:

player execVM "pilotCheck.sqf";

Share this post


Link to post
Share on other sites

Thanks kylania works like a charm...now what can be done about the crewman can only drive tanks..is that a completely different script...well obviously...

Share this post


Link to post
Share on other sites

One way of doing this would be:

_vehicleType = _this select 0;  // "Helicopter" / "Tank"
_crewType = _this select 1;  // "US_Soldier_Pilot_EP1"

//hint format["%1 - %2",_crewType, _vehicleType];
 if (typeof player != _crewType) then {
   private "_v";
   while {alive player} do {
     waituntil {vehicle player != player};
     _v = vehicle player;
     if (_v iskindof _vehicleType && !(_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.";
       };
     };
   };
 };

Then call that from init.sqf as:

["Helicopter", "US_Soldier_Pilot_EP1"] execVM "pilotCheck.sqf";
["Tank", "US_Soldier_Crew_EP1"] execVM "pilotCheck.sqf";

Share this post


Link to post
Share on other sites

I got it working..I basically used the first code..switched the pilot class to the crewman class and switched the word Helicopter to the word Tank... then i put: player execVM "CrewCheck.sqf"; in the Init

Share this post


Link to post
Share on other sites
Getin EH can be cheated by first entering as cargo and then just changing seats.

Sorry to resurrect an old thread - does anyone know if this can be resolved using EH now, or is the above still an issue?

Share this post


Link to post
Share on other sites
Sorry to resurrect an old thread - does anyone know if this can be resolved using EH now, or is the above still an issue?

It'd still be the problem. The getin and getout eventhandlers only fire when you enter or leave a vehicle, but not when you change seats, so imo eventhandlers aren't a good approach.

If it helps, I have good experience in using a FSM for this purpose:

http://fh-warzone.de/downloads/boninf/vehiclecheck_fsm.jpg

Share this post


Link to post
Share on other sites
Are you using that method in your TForce missions?

Yes, well, with some mission-specific adjustments. But the actual "check if the player is allowed" thing is done just in the structure I posted above and came out to be a good method for me.

Share this post


Link to post
Share on other sites

Bon, can you point me in the direction of one of your missions that uses your method? Because the other method mentioned above doesn't work at all for me. I tried the script from this thread and if a non-pilot gets in and then gets kicked out and the hint then appears, and the real pilot then tries to get in after him, the real pilot then gets kicked too and is given the same hint message. I can only seem to get it to work if the leader is the pilot. I have only 1 friendly vehicle in my missions (Chinook). And I have only 1 pilot slot and I don't want anybody else flying. Is there a more simple approach I could use if there is only 1 vehicle and only 1 pilot in the squad?

Share this post


Link to post
Share on other sites
Bon, can you point me in the direction of one of your missions that uses your method? Because the other method mentioned above doesn't work at all for me. I tried the script from this thread and if a non-pilot gets in and then gets kicked out and the hint then appears, and the real pilot then tries to get in after him, the real pilot then gets kicked too and is given the same hint message. I can only seem to get it to work if the leader is the pilot. I have only 1 friendly vehicle in my missions (Chinook). And I have only 1 pilot slot and I don't want anybody else flying. Is there a more simple approach I could use if there is only 1 vehicle and only 1 pilot in the squad?

If you just need it for a few vehicles then you can use this set up I made. Its really simple. Make sure you have a functions module down for the rHint's.

I made this for a helo but you can change it to suit your needs.

In the init an array of your allowed crew.

init.sqf:

h1pilots = [p2,p3,p4];

create a trigger set on repeated activation.

In the condition field: (h1 is the name of the vehicle)

!isNull driver h1

in the onactivation field:

drivr = driver h1;if !((driver h1) in h1pilots) then {drivr action ["eject", h1];[nil,drivr,"loc",rHINT,"You cannot operate this vehicle."] call RE;};

If you use ACE then use this:

drivr = driver h1;if !((driver h1) in h1pilots) then {  [h1, drivr] execVM "x\ace\addons\sys_eject\jumpout.sqf";[nil,drivr,"loc",rHINT,"You cannot operate this vehicle."] call RE;};

Now this is really just best for a few vehicles and simple set ups, but it does work in in mp and it will even work for re-spawning vehicles if you use a script like simple vehicle re-spawn that sets the name back to the same.

Share this post


Link to post
Share on other sites

Thanks a million Riouken

It works like a charm. It is exactly what I needed.

Share this post


Link to post
Share on other sites

1 problem when I tested as a pilot... After I respawned it kicked me out of the pilots seat. Would it be possible to fix this?

---------- Post added at 08:12 AM ---------- Previous post was at 07:56 AM ----------

Never mind. It's working again. Not sure what the problem was, maybe the trigger wasn't set to repeatedly.

---------- Post added at 08:16 AM ---------- Previous post was at 08:12 AM ----------

Is there a way to make it so only the player that gets kicked from the pilot seat sees the hint message "You cannot operate this vehicle." ??? I don't want everybody seeing that.

Share this post


Link to post
Share on other sites
Is there a way to make it so only the player that gets kicked from the pilot seat sees the hint message "You cannot operate this vehicle." ??? I don't want everybody seeing that.

It is local:

It uses the multi-player framework.

Quote from there:

Hint on client where object miles is local:

[nil,miles,"loc",rHINT,"Miles is local here."] call RE;

All hints are local. But with the multi player framework you can remotely execute the hints on other clients based of the conditions that you set.

But in this case it is local to the pilot of the veh. I just like to use "RE" for all my hints in multi-player to avoid locality problems.

Share this post


Link to post
Share on other sites

I really appreciate all this help guys. This is good stuff. Very helpful for others that search for this.

Bon, your sample mission works great. I applied it to my mission and everything works perfect, but it seems to be conflicting with something. I am using Norrin's revive in the mission which was also working fine, but now that I've applied the "only pilots can fly" stuff to the mission, for some reason when I respawn I am injured. As the team leader I can see that it shows me as "red" the moment I respawn. I tested it a few times and it happened every time. I then removed the "pilots only" stuff and I stopped respawning injured. Is there something I need to do to make it compatible with Norrin's revive script?

Share this post


Link to post
Share on other sites

Bon, your sample mission works great. I applied it to my mission and everything works perfect, but it seems to be conflicting with something. I am using Norrin's revive in the mission which was also working fine, but now that I've applied the "only pilots can fly" stuff to the mission, for some reason when I respawn I am injured. As the team leader I can see that it shows me as "red" the moment I respawn. I tested it a few times and it happened every time. I then removed the "pilots only" stuff and I stopped respawning injured. Is there something I need to do to make it compatible with Norrin's revive script?

The only thing the FSM has to do with respawn is to check IF the unit respawned. That's it. There is nothing done except those checks. Apart from the lists allowed_pilots and allowed_crewmen it doesn't even use global variables at all.

So if there is something conflicting with norrin revive, it must be some global variables called allowed_pilots and allowed_crewmen.

If the norrin revive breaks because another script does some checks, I'd reconsider using this revive script if I were you. :o (however, it most probably is something else).

Edited by Bon

Share this post


Link to post
Share on other sites

execute with:

_null = [b][i]this[/i][/b] execVM "getin.sqf"

this is name of vehicle if you need to execute it not in the init of vehicle, like for example in a spawned or respawned script.

save this as getin.sqf

_this addEventHandler ["GetIn",
{
_veh = _this select 0;
_pos = _this select 1;
_unit = _this select 2;

_type = typeOf _unit;
_crew = ["US_Soldier_Crew_EP1"];
_pilot = ["US_Soldier_Pilot_EP1"];
_kick = false;

if (_veh iskindOf "LandVehicle" AND !(_type in _crew)) then {_kick = true};
if (_veh iskindOf "Air" AND !(_type in _pilot)) then {_kick = true};
if (_pos == "driver") then {
	if (_kick) then {
		if (isEngineOn _veh) then {_veh engineOn false};
		unassignVehicle _unit;
		_unit action ["Eject", _veh];
		if (_unit == player) then {
			hint format["%1 you are not allowed to operate this vehicle",name player];
		};
	};
} else {
	if (_kick) then {
		_allowed = _unit spawn {
			_veh = vehicle _this;
			while {alive _this AND (vehicle _this) == _veh} do {
				if (alive _this AND (vehicle _this) == _veh AND (driver _veh) == _this) then {
					if (isEngineOn _veh) then {_veh engineOn false};
					unassignVehicle _this;
					_this action ["Eject", _veh];
					if (_this == player) then {
						hint format["%1 you are not allowed to operate this vehicle",name player];
					};
				};
				sleep 1;
			};
		};
	};
};
}];

You need to do a few small things before using this.

place down any crew member used in your mission in editor and put this in its init and preview:

hint format["""%1""",typeOf this]; copyToClipboard format["""%1""",typeOf this];

now you can left click and paste the unit type, add or replace below:

_crew = [[b][i]"US_Soldier_Crew_EP1"[/i][/b]];

You can have as many units and types in there as you want, just remember to seperate with ,comma:

_crew = [[b][i]"US_Soldier_Crew_EP1","US_Soldier_Crew_EP1"[/i][/b]];

repeat same for pilots allowed and in the line:

_pilot = [[b][i]"US_Soldier_Pilot_EP1"[/i][/b]];

Next, this script is meant to controll all land and air vehicles, you can simply change that by changing the isKindOf check.

locate this line:

_veh iskindOf [b][i]"LandVehicle"[/i][/b]

replace "LandVehicle" with for exampel "Tank" to only be for tanks, "Car" for cars etc...

Do same for the line with "Air" in aswell if you need changes.

Note: as the script is now, it will be for all land/air vehicles(including guns), driver positions.

anyone can enter all other positions, but driver position will be limited.

more cfgVehicles here:

http://community.bistudio.com/wiki/ArmA_2:_CfgVehicles

EDIT: you can also place the getin.sqf code directly in a vehicles initline, but then replace the first _this at top with this (no front underscore)

Edited by Demonized

Share this post


Link to post
Share on other sites

I got it working Bon, you were right, it must've been something else. It works perfectly. I appreciate the help very much, you too Demonized.

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  

×