Jump to content

Recommended Posts

Hey everyone, 

I was wondering if someone could help me develop a script that would allow blufor units to only be able to enter Blufor vehicles as well as Opfor only being able to enter Opfor vehicles. I would need an array to be specific to what vehicles I would allow units to enter. I do not want the unit to be killed, just kicked out of the vehicle. 

 

Thanks, 

Kdubyadog556

Share this post


Link to post
Share on other sites
this addEventHandler ["GetIn", 
{
	_spot = _this select 1; //the seat the unit got into
	_unit = _this select 2; //the unit itself

	if (!(side _unit == west)) then //if the unit got into the vehicle is not side west
	{ 
		_unit action ["Eject", vehicle _unit]; //eject the unit
		hint "You can't enter this vehicle!" //show a hint
	};
		
}]; 

Adjust as needed.

Share this post


Link to post
Share on other sites
16 hours ago, L3TUC3 said:

this addEventHandler ["GetIn", 
{
	_spot = _this select 1; //the seat the unit got into
	_unit = _this select 2; //the unit itself

	if (!(side _unit == west)) then //if the unit got into the vehicle is not side west
	{ 
		_unit action ["Eject", vehicle _unit]; //eject the unit
		hint "You can't enter this vehicle!" //show a hint
	};
		
}]; 

Adjust as needed.

Does not work. Keep getting error messages. My version:

 

this addEventHandler ["GetIn",true]
{
    _spot = _this select 1; //the seat the unit got into
    _unit = _this select 2; //the unit itself

    if (!(side _unit == west)) then //if the unit got into the vehicle is not side west
    { 
        _unit action ["Eject", vehicle _unit]; //eject the unit
        hint "You can't enter this vehicle!" //show a hint
    };
        
}];

this addEventHandler ["GetIn",true]
{
    _spot = _this select 1; //the seat the unit got into
    _unit = _this select 2; //the unit itself

    if (!(side _unit == east)) then //if the unit got into the vehicle is not side east
    { 
        _unit action ["Eject", vehicle _unit]; //eject the unit
        hint "You can't enter this vehicle!" //show a hint
    };
        
}];

///This does not work either. Any hints?

 

Share this post


Link to post
Share on other sites

You could try this basic example. The vehicle's side is taken from the config. If the unit's side does not equal the defined vehicle's side then the player is moved out of the vehicle:
This only works for the type of unit- it does not take in to account their group.
 

if (local this) then {
	this addEventhandler ["GetInMan", {
		params ["_unit", "", "_vehicle"];
		
		private _side = getNumber (configfile >> "CfgVehicles" >> typeOf _vehicle >> "side");
		private _faction = getNumber (configfile >> "CfgFactionClasses" >> faction _unit >> "side");
		
		if (_side != _faction) then {
			moveOut _unit;
			hint "You can't enter a vehicle that does not belong to your faction!";
		};
	}];
};

 

  • Like 1

Share this post


Link to post
Share on other sites
19 hours ago, hallyg said:

You could try this basic example. The vehicle's side is taken from the config. If the unit's side does not equal the defined vehicle's side then the player is moved out of the vehicle:
This only works for the type of unit- it does not take in to account their group.
 


if (local this) then {
	this addEventhandler ["GetInMan", {
		params ["_unit", "", "_vehicle"];
		
		private _side = getNumber (configfile >> "CfgVehicles" >> typeOf _vehicle >> "side");
		private _faction = getNumber (configfile >> "CfgFactionClasses" >> faction _unit >> "side");
		
		if (_side != _faction) then {
			moveOut _unit;
			hint "You can't enter a vehicle that does not belong to your faction!";
		};
	}];
};

 

Yeah, still doesn't work. Isn't there a script that denies access to enemy vehicles all-together? I've seen this done on the KOTH servers. 

Share this post


Link to post
Share on other sites
4 minutes ago, KdubyaDOG556 said:

Yeah, still doesn't work. Isn't there a script that denies access to enemy vehicles all-together? I've seen this done on the KOTH servers. 

What doesn't work? The snippet I posted works provided it is placed in the object's init.
What specifically is not working; where are you putting the script?

Share this post


Link to post
Share on other sites
1 minute ago, hallyg said:

What doesn't work? The snippet I posted works provided it is placed in the object's init.
What specifically is not working; where are you putting the script?

ah, was trying to use in a vehicleLock.sqf. 

 

Share this post


Link to post
Share on other sites
2 minutes ago, KdubyaDOG556 said:

ah, was trying to use in a vehicleLock.sqf. 

 

Change 'this' to 'player'.

Share this post


Link to post
Share on other sites
1 minute ago, hallyg said:

Change 'this' to 'player'.

"params ["_unit", "", "_vehicle"];" does anything need to go in between the middle quotations?

 

Share this post


Link to post
Share on other sites
8 minutes ago, hallyg said:

What doesn't work? The snippet I posted works provided it is placed in the object's init.
What specifically is not working; where are you putting the script?

With placing this script in the init field of a vehicle, I encountered an error. The error is :

'{

if {side _x == opfor} then {

_x |#|addaction ["Eject"];

}} forEach AllUnit...'

Error 1 elements provided, 3 expected

 

 

Share this post


Link to post
Share on other sites
14 minutes ago, KdubyaDOG556 said:

"params ["_unit", "", "_vehicle"];" does anything need to go in between the middle quotations?

 

The params command automatically parses the arguments provided to the code in to their own corresponding private variables. In this case the arguments are automatically handled by the event handler so there is no need to change this.


In your vehicleLock.sqf

params [
	["_unit", objNull, [objNull]]
];

if (local _unit) then {
	_unit addEventhandler ["GetInMan", {
		params ["_unit", "", "_vehicle"];
		
		private _side = getNumber (configfile >> "CfgVehicles" >> typeOf _vehicle >> "side");
		private _faction = getNumber (configfile >> "CfgFactionClasses" >> faction _unit >> "side");
		
		if (_side != _faction) then {
			moveOut _unit;
			if (isPlayer _unit) then {
				hint "You can't enter a vehicle that does not belong to your side!";
			};
		};
	}];
};

You can run this using:
[UNITNAME] execVM "vehicleLock.sqf"

Share this post


Link to post
Share on other sites
11 minutes ago, hallyg said:

The params command automatically parses the arguments provided to the code in to their own corresponding private variables. In this case the arguments are automatically handled by the event handler so there is no need to change this.


In your vehicleLock.sqf


params [
	["_unit", objNull, [objNull]]
];

if (local _unit) then {
	_unit addEventhandler ["GetInMan", {
		params ["_unit", "", "_vehicle"];
		
		private _side = getNumber (configfile >> "CfgVehicles" >> typeOf _vehicle >> "side");
		private _faction = getNumber (configfile >> "CfgFactionClasses" >> faction _unit >> "side");
		
		if (_side != _faction) then {
			moveOut _unit;
			if (isPlayer _unit) then {
				hint "You can't enter a vehicle that does not belong to your side!";
			};
		};
	}];
};

You can run this using:
[UNITNAME] execVM "vehicleLock.sqf"

I encountered no errors which is a good sign. However, the script does NOT kick the enemy faction out of the vehicles. 

Share this post


Link to post
Share on other sites
2 minutes ago, KdubyaDOG556 said:

I encountered no errors which is a good sign. However, the script does NOT kick the enemy faction out of the vehicles. 

I think there has been a miscommunication. This script will kick out any unit that tries to enter a vehicle which does not belong, as defined in the config, to their side. It does not kick out already mounted units.

Share this post


Link to post
Share on other sites
Just now, hallyg said:

I think there has been a miscommunication. This script will kick out any unit that tries to enter a vehicle which does not belong, as defined in the config, to their side. It does not kick out already mounted units.

No, you're exactly correct. There are no units in the vehicle. I would like the script to kick the opposite faction from the friendly vehicles. Basically preventing any enemy unit from entering the vehicle at all. In other words "no stealing vehicles".

Share this post


Link to post
Share on other sites
4 minutes ago, KdubyaDOG556 said:

No, you're exactly correct. There are no units in the vehicle. I would like the script to kick the opposite faction from the friendly vehicles. Basically preventing any enemy unit from entering the vehicle at all. In other words "no stealing vehicles".

In which case you will need to add the eventHandler to each enemy unit (which I should have specified earlier). You could do this by iterating through the allUnits array and selecting enemy side units only. 

Init.sqf
 

{
	[_x] execVM "vehicleLock.sqf";
	false
} count (allUnits select {side _x isEqualTo ENEMYSIDE});


 

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, hallyg said:

In which case you will need to add the eventHandler to each enemy unit. You could do this by iterating through the allUnits array and selecting enemy side units only. 

Init.sqf
 

{
	[_x] execVM "vehicleLock.sqf";
	false
} count (allUnits select {side _x isEqualTo ENEMYSIDE});

   This works beautifully! For anyone wanting the same thing this what to do:

 

///vehicleLock.sqf:

 

params [
    ["_unit", objNull, [objNull]]
];

if (local _unit) then {
    _unit addEventhandler ["GetInMan", {
        params ["_unit", "", "_vehicle"];
        
        private _side = getNumber (configfile >> "CfgVehicles" >> typeOf _vehicle >> "side");
        private _faction = getNumber (configfile >> "CfgFactionClasses" >> faction _unit >> "side");
        
        if (_side != _faction) then {
            moveOut _unit;
            if (isPlayer _unit) then {
                hint "You can't enter a vehicle that does not belong to your side!";
            };
        };
    }];
};

_______________________________________________________________________________________________________________________________________________________

place in init.sqf:

 

{
    [_x] execVM "vehicleLock.sqf";
    false
} count (allUnits select {side _x isEqualTo Opfor});

{
    [_x] execVM "vehicleLock.sqf";
    false
} count (allUnits select {side _x isEqualTo Blufor});

{

Share this post


Link to post
Share on other sites
9 minutes ago, hallyg said:

In which case you will need to add the eventHandler to each enemy unit. You could do this by iterating through the allUnits array and selecting enemy side units only. 

Init.sqf
 


{
	[_x] execVM "vehicleLock.sqf";
	false
} count (allUnits select {side _x isEqualTo ENEMYSIDE});

 

Thankyou for all your help sir. You really saved me some time! I appreciate it. Is there anything I can do for you?

 

Share this post


Link to post
Share on other sites
7 minutes ago, KdubyaDOG556 said:

Thankyou for all your help sir. You really saved me some time! I appreciate it. Is there anything I can do for you?

 


Not at all, I'm happy to help.

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

×