Jump to content
Sign in to follow this  
alleycat

Problem with kicking non crew class from vehicle

Recommended Posts

Trying to kick a player from vehicles if they are not crew:

	_commander 	= commander _vehicle;
_gunner		= gunner _vehicle;
_driver		= driver _vehicle;

if (	(!(_commander isKindOf "O_crew_F"))	||	(!(_commander isKindOf "B_crew_F"))) then	{			_commander action 	["GetOut",_vehicle];	};
if (	(!(_gunner isKindOf "O_crew_F"))	||	(!(_gunner isKindOf "B_crew_F"))) then		{			_gunner action 		["GetOut",_vehicle];	};
if (	(!(_driver isKindOf "O_crew_F"))	||	(!(_driver isKindOf "B_crew_F"))) then		{			_driver action 		["GetOut",_vehicle];	};	

However it kicks the player every time, even if the class is crewman. Something broken on the logic?

Share this post


Link to post
Share on other sites

Is this code on server or client(s)?

Assuming it is and should be running on the client, this block might help you piece together something which works

private ["_v"];
_allowedClasses = ["O_crew_F","B_crew_F","I_crew_F"];

if ((typeOf (vehicle player)) in _allowedClasses) exitWith {};

// players vehicle type is not in the _allowedClasses array

while {TRUE} do {
_v = vehicle player;
if (!(_v isKindOf 'Man')) then {
	// player is in a vehicle
	_testSeats = [(driver _v),(_v turretUnit [0]),(_v turretUnit [1])];
	if (player in _testSeats) then {
		// player is in driver/gunner/commander seat of the vehicle
		player action ["getOut",_v];
	};
};
       sleep 3;
};

---------- Post added at 01:17 ---------- Previous post was at 01:11 ----------

And to troubleshoot your block, try excluding the 'commander' test. Not sure but if there is only one person in a vehicle, he may be the commander no matter what seat he is in.

Share this post


Link to post
Share on other sites

Your script works as intended on driver and gunner, but does not seem to do for commander, which is not much of an issue. Still wondering what is wrong with my script. I excluded the commander check and it still does it. The code is attached to a vehicle when it is placed with zeus and so far I tested it in SP. Also about your script, I added a 5 second delay between each loop to save on performance. Would it hit the FPS of a player if it would run every frame or whatever interval while uses?

Share this post


Link to post
Share on other sites
Also about your script, I added a 5 second delay between each loop to save on performance. Would it hit the FPS of a player if it would run every frame or whatever interval while uses?

Not noticeably.

Something which would hurt performance a lot (and you can try it out) is this:

private ['_objList','_displayName'];
while {TRUE} do {
_objList = (getPos player) nearObjects ['All',10000];
{
	_displayName = getText (configFile >> "CfgVehicles" >> (typeOf _x) >> "displayName");
} forEach _objList;
};

Which vehicle is the problem one, or just all vehicles with commander seats?

Share this post


Link to post
Share on other sites

I'm a little confused here, do you want to eject all of the non-"crew" from a vehicle, or just kicking out everyone that isn't the "crew" class? If it's the former, this might suit your needs:

DE_ejectVehicleCargo =
{
//accepts vehicles as input. Behavior with non-vehicle input is undefined.
//Example: myCar call DE_ejectVehicleCargo
//Returns: BOOLEAN
	//true if cargo successfully ejected
	//false if cargo was not ejected (this should never happen but it's nice to include things like this to your functions)

_veh = _this;
_count = 0;
_output = false;

_check = count (crew _veh);

{
	if ((_veh getCargoIndex _x) > -1) then
	{
		if (alive _x) then
		{
			_count = _count + 1;
			_x action ["Eject", _veh]; //"Eject" can be replaced with "GetOut"
		};
	};
}forEach (crew _veh);

if ((count (crew _veh)) == (_check - _count)) then
{
	_output = true;
};

_output;
};

EDIT: Just remembered that dead units can't do "actions" so added an condition that only counts alive units for the success check

Example usage:

_test = false;
while {!_test} do
{
_test = myVehicle call DE_ejectVehicleCargo;
}; //Doing it this way guarantees that the action will be completed successfully

Edited by DreadedEntity

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  

×