Forum Jump :

Author Message


Posts: 6
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2014-06-28 07:34        
     
So I am trying to set up a simple script to make it so you can only get into this one vehicle if your UID is on the list. Otherwise it kicks you out of the vehicle if you try to get in. However every time I get in the vehicle it doesnt do anything and I don't know why.

I have the following sqf file:

VehicleLock.sqf
_PlayerUIDs = ["666666","123456","135462013"];
waitUntil {not isNull (_this select 1)};
waitUntil {(getPlayerUID (_this select 1)) != ""};
_CurrentPlayer = _this select 1;
_CurrentUID = getPlayerUID _CurrentPlayer;
_CurrentPlayerName = name _CurrentPlayer;
if(_CurrentUID in _PlayerUIDs) then {
	hint format ['Hello, %1', _CurrentPlayerName];
	} 
	else {
	hint 'This ain't your ride bro!';
	};

and the following code in a striders init box in the editor:

this addEventHandler ["GetIn", "execVM 'VehicleLock.sqf'"]


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#2 Posted at 2014-06-28 15:22        
     
You appear to not have passed the parameters into the script.
try:

this addEventHandler ["GetIn", "_this execVM 'VehicleLock.sqf'"]

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface

Advertisement


Author Message


Posts: 6
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2014-06-28 20:36        
     
Thanks for the reply, I put that in and it still didn't work so I put in a bit more code to see where it was hanging up.

_PlayerUIDs = ["666666","123456","135462013"];
hint "working";
waitUntil {not isNull (_this select 1)};
hint "working1";
waitUntil {(getPlayerUID (_this select 1)) != ""};
hint "working2";
_CurrentPlayer = _this select 1;
_CurrentUID = getPlayerUID _CurrentPlayer;
_CurrentPlayerName = name _CurrentPlayer;
hint "working3";
if(_CurrentUID in _PlayerUIDs) then {
		hint format ['Hello, %1', _CurrentPlayerName];
	} 
	else {
		hint 'This ain't your ride bro!';
		_CurrentPlayer action ["Eject", vehicle _CurrentPlayer];
	};

It only gets to "working" so that means its not getting past the waitUntil and I have no idea why. Any help is appreciated.


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#4 Posted at 2014-06-28 21:04        
     
Try putting _this select 2 instead of _this select 1

The biki says that the unit is the third parameter not the second.
https://community.bistudio.com/wiki/Armed_Assault:_EventHandlers_List#GetIn

Technically you could just get rid of all the waitUntil loops anyway since Im not sure its that necessary for this situation.

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface

Author Message


Posts: 6
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2014-06-28 22:51        
     
Thanks that got it to work. I have one more question though. I wanted to make it so only when its locked it runs that code when you get in, otherwise if you unlock it(via action menu), then it wont run that code when you get in. However I don't know how to differentiate between when the script is being called by the action menu or when its being called by the eventHandler. If there isn't a way to do that then how would I connect 2 scripts together like that(one to change a "Locked" variable through the action menu)?


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#6 Posted at 2014-06-29 12:15        
     
I suspect you could try something like this:

_this addAction
[
	"lock",
	{
		[
			[_this, {(_this select 0) setVariable ["vehIsLocked", true, true];}],
			"BIS_fnc_spawn",
			true,
			false
		] spawn BIS_fnc_MP;
	},
	[],
	1.5,
	true,
	false,
	"",
	"!(_target getVariable 'vehIsLocked')"
];

_this addAction
[
	"unlock",
	{
		[
			[_this, {(_this select 0) setVariable ["vehIsLocked", false, true];}],
			"BIS_fnc_spawn",
			true,
			false
		] spawn BIS_fnc_MP;		
	},
	[],
	1.5,
	true,
	false,
	"",
	"(_target getVariable 'vehIsLocked')"
];


_this addEventHandler 
[
	"GetIn", 
	{	
		if ((_this select 0) call {_this getVariable "vehIsLocked"}) then
		{
			_playerUIDs = ["666666","123456","135462013"];
			
			hint "working";
			
			waitUntil {not isNull (_this select 2)};
			
			hint "working1";
			
			waitUntil {(getPlayerUID (_this select 2)) != ""};
			
			hint "working2";
			
			_currentPlayer = _this select 2;
			
			hint "working3";
			
			if((getPlayerUID _CurrentPlayer) in _playerUIDs) then 
			{
				hint format ['Hello, %1', name _currentPlayer];
			}
			else 
			{
				hint 'This aint your ride bro!';
				_CurrentPlayer action ["Eject", vehicle _currentPlayer];
			};
		};
	}
];

You would put this in an SQF file and call it something like vehicleLock.sqf, you then run it by putting in the init lines for each vehicle:

this execVM "vehicleLock.sqf";

it's worth a shot

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface