Jump to content
Sign in to follow this  
Matosh

vehicle restriction

Recommended Posts

It works for me with the following exceptions.

You can still get in as loader, that I believe is a turret and I'm not sure how to check for that.

It also fails to work when I spawn it but without the spawn it works.

It seems to exit the script when spawned and the hint displays done.

_vehlist = ["HMMWV_M998_crows_M2_DES_EP1","HMMWV_Ambulance","CH_47F_EP1","CH_47F_BAF","UH60M_MEV_EP1","BAF_Merlin_HC3_D"];

_soldier = ["US_Soldier_EP1","US_Soldier_Officer_EP1"];


//[] spawn {

while {true} do 
{
{
	_vehchoice = vehicle player;
   if ((driver _vehchoice == player) or (gunner _vehchoice ==  player) or (commander _vehchoice == player)) then 
	  {
	 	if (_vehchoice iskindof _x) then          
	 		{			

                           if (typeof player in _soldier) then
					{ 

						player action ["ENGINEOFF", _vehchoice];
						player action ["eject", _vehchoice];
						sleep 0.5;
						_vehchoice engineOn false;
						waituntil {vehicle player == player};	
						hint format ["You are not allowed to enter %1", _x];
					};

			};
		};
		} foreach _vehlist;	
		sleep 0.1;
	};
//};

hint "done";

Share this post


Link to post
Share on other sites

cheers f2k sel - thanks for the test dude

generally i use

if (is !dedicated) then { [] spawn etc - hence my use of the spawn - although to be honest im not 100% sure of its useage in this orientation.

matosinec - not sure why it does not work for you - as f2k sel has shown it does work in his given circumstances - try those and see how you get on. maybe you are experiencing the same issues.

*note* - i test my stuff using the multiplayer option of the editor.

just working on the [FOCK]ers most wanted V6 - just fixing a similar script for vehicle access with the use of eventhandler "get in" (cpu effiency) - once i get that going ill pm you.

Share this post


Link to post
Share on other sites

I did a little more testing and this may be of use, it will kick you out of all positions including turrets unless tour cargo.

_vehlist = ["HMMWV_M998_crows_M2_DES_EP1","HMMWV_Ambulance","CH_47F_EP1","CH_47F_BAF","UH60M_MEV_EP1","BAF_Merlin_HC3_D","M1A2_US_TUSK_MG_EP1"];

_soldier = ["US_Soldier_EP1","US_Soldier_Officer_EP1"];


//[] spawn {

while {true} do 
{
//waituntil {count playableUnits >= 1};
{
	_vehchoice = vehicle player;
	_role = assignedVehicleRole player;

if (_role select 0 != "cargo") then {	
  //  if ((driver _vehchoice == player) or (gunner _vehchoice ==  player) or (commander _vehchoice == player)) then 

	//  {
	 	if (_vehchoice iskindof _x) then          
	 		{			

                           if (typeof player in _soldier) then
					{ 

						player action ["ENGINEOFF", _vehchoice];
						player action ["eject", _vehchoice];
						sleep 0.5;
						_vehchoice engineOn false;
						waituntil {vehicle player == player};	
						hint format ["You are not allowed to enter %1", _x];
					};
			//	};

			};
		};
		} foreach _vehlist;	
		sleep 0.1;
	};
//};

hint "done";

Share this post


Link to post
Share on other sites
Isnt this gonna kick you out from all vehicle seats?

Nope...why should it? Here it as again...tested and working. Took out the spawn...and changed playableunits to swichableunits for testing in SP.

_vehlist = ["AAV","LAV25"];
_soldier = ["US_Soldier_EP1","US_Soldier_Officer_EP1"];

while {true} do {
waituntil {count switchableUnits >= 1};
waituntil {vehicle player != player};
_vehchoice = vehicle player;
if ((typeof _vehchoice in _vehlist) and (typeof player in _soldier)) then {
	player action ["eject", _vehchoice];
	sleep 0.5;
	_vehchoice engineOn false;
	hint format ["You are not allowed to enter %1", typeof _vehchoice];
};
   sleep 1;
};

EDIT: Tested more....you don't need the "ENGINEOFF" line! Took it out.

You really don't need all that looping foreach stuff at all.

**UPDATE**

This will allow the player to only get into "CARGO" positions.

_vehlist = ["AAV","LAV25"];
_soldier = ["US_Soldier_EP1","US_Soldier_Officer_EP1"];
_allowed = ["Cargo"];

while {true} do {
waituntil {count switchableUnits >= 1};
waituntil {vehicle player != player};
_vehchoice = vehicle player;
_typeofveh = typeof _vehchoice;
_assignedr = (assignedvehiclerole player) select 0;
if ((_typeofveh in _vehlist) and (typeof player in _soldier) and (not (_assignedr in _allowed))) then {
	player action ["eject", _vehchoice];
	sleep 0.5;
	_vehchoice engineOn false;
	hint format ["You are not allowed to enter %1", typeOf _vehchoice];
};
   sleep 1;
};

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

That cleans it up quite nicely but it will kick you out of all seats including the cargo positions.

You can check the cargo position and make allowance for it.

_vehlist = ["AAV","LAV25"];
_soldier = ["US_Soldier_EP1","US_Soldier_Officer_EP1"];

while {true} do {
   waituntil {count switchableUnits >= 1};
   waituntil {vehicle player != player};
   _vehchoice = vehicle player;
   if ((typeof _vehchoice in _vehlist) and (typeof player in _soldier) and ((assignedVehicleRole player) select 0 != "cargo")) then {
       player action ["eject", _vehchoice];
       sleep 0.5;
       _vehchoice engineOn false;
       hint format ["You are not allowed to enter %1", typeof _vehchoice];
   };
   sleep 1;
};  

Edited by F2k Sel

Share this post


Link to post
Share on other sites

F2K...that's cool.

I just removed it cause it didn't actually work the way I was checking for cargo.... did something stupid! I will test and update my post again.

Share this post


Link to post
Share on other sites
F2K...that's cool.

I just removed it cause it didn't actually work the way I was checking for cargo.... did something stupid! I will test and update my post again.

I see I thought I'd just imagined it :o

Share this post


Link to post
Share on other sites
I see I thought I'd just imagined it :o

OK...it's back. Must be ju ju magic! Lol!

assignedvehiclerole returns an array....that screwed me up!

Share this post


Link to post
Share on other sites

The script works great, thanks a lot everyone.

Share this post


Link to post
Share on other sites

just a quick update on trial of event handlers for "getin" to vehicles. appears to work - haven't implemented the work of twirly and f2k_sel- used the first batch of code. change to suit

tested below on mp editor - not checked on dedi

init of the vehicle - vehctrl = [this] execVM "vehCtrlinit.sqf";

vehCtrlinit.sqf

_vehicle=_this select 0;

_vehicle addEventHandler ["GetIn", "if (player == (_this select 2)) then {[(_this select 0),(_this select 1),(_this select 2)] execVM 'vehRank.sqf';}"];

vehRank.sqf

_vehicle = _this select 0;
_vehseat = _this select 1;
_unitin = _this select 0;
hint "Got in Vehicle";

hint format ["%1  in %2",_unitin,_vehicle];
_vehlist = ["HMMWV_M998_crows_M2_DES_EP1","HMMWV_Ambulance","C H_47F_EP1","CH_47F_BAF","UH60M_MEV_EP1","BAF_Merli n_HC3_D"];

while {_unitin ==_vehicle} do

{ 	
//       waituntil {count playableUnits >= 1};
_vehchoice = vehicle player;
	{	
waitUntil {(gunner _vehchoice == player)};
   if (gunner _vehchoice == player) then 
		  {
	 	if (_vehchoice iskindof _x) then          
	 		{									 
                           if (typeOf player == "US_Soldier_Officer_EP1") then
					{ 

						player action ["ENGINEOFF", _vehchoice];
						player action ["eject", _vehchoice];
						sleep 0.5;
						_vehchoice engineOn false;
						waituntil {vehicle player == player};	
						hint format ["you cannot access the gun of %1 vehicles", _x];
					};
			};
		   };
	} foreach _vehlist;
		sleep 0.5;
  }; //while

Share this post


Link to post
Share on other sites

I need restriction for vehicles when they spawn after players complete missions. So i dont know how can i put your code in init field.

Share this post


Link to post
Share on other sites

when you create the vehicle -

_veh = createVehicle ["ah1w", position player, [], 0, "FLY"];

[_veh] execVM "vehCtrlinit.sqf";

Share this post


Link to post
Share on other sites

What is the difference between yours and F2k Sel last message with script ?

Share this post


Link to post
Share on other sites

nothing - really.

best bet is to replace the code i used within the while loop with the code given by f2k-sel and twirly, but use the eventhandler to call it. this stops the while loop running until you get in the car. it stops when you get out of the car. uses less cpu regardless of the waituntil used - as far as im aware.

Share this post


Link to post
Share on other sites

Its working, thanks.

Share this post


Link to post
Share on other sites

Actually this code _veh = createVehicle ["ah1w", position player, [], 0, "FLY"]; will create vehicle at whateverposition, right ? But different script will handle creating the vehicle (domination).

Share this post


Link to post
Share on other sites

_veh = createvehilcle etc - was just an example of when u create a vehicle. if you are using this script with domi, then if it is a mission u are creating within domi, you need to place this after the code that creates the said vehicle. amend as required - point it towards the correct vehicle. if it code you are creating for your own side mission, you can use the createvehicle method. if u use spawnvehicle - u need to ascertain the vehicle from the code, and then add it to that. sorry for the waffle. hope this makes sense

Share this post


Link to post
Share on other sites

Im not sure if i understood you, you are saying that i have to put the code inside the script which creates/spawns vehicle ?

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  

×