Jump to content

[Release] Remote key for locking/unlocking vehicles (0.3)


Recommended Posts

 

Howdy,

 

This is my first post here, so.. Hi..  :)

 

 

This script adds a new right-click option for keys.

 

If the player is near a vehicle (a distance of 50, can be changed) that matches the key, the option to lock or unlock the vehicle becomes available.

 

Clicking either locks or unlocks the vehicle.

 

 

Feel free to come with comments and suggestions.

Changelog

0.1 Initial public release.

0.2 Not able to use this while in a vehicle, added remote engine start feature.

0.3 Fixed so that remote key feature (and inventory overall) can be used within locked vehicles.

Known issues 

* Remote engine start only works if players have gotten into the car first at some point.

* Remote engine stop does not work.

1. Setup a custom compiles.sqf (skip this if you already have this)

The functions you need to replace are ui_selectSlot and fn_gearMenuChecks.

Copy compiles\ui_selectSlot.sqf from your dayz_code pbo to the custom folder in your mission folder and rename it to player_selectSlot.sqf.

Do the same with fn_gearMenuChecks.sqf.

 

 

2. Modify player_selectSlot.sqf

Open custom\player_selectSlot.sqf in your mission folder.

 

Find the following (most likely the first line):

private ["_control","_button","_parent" ...
In the end of this line, add:

,"_key_colors","_ownerKeyId","_itemsPlayer","_hasKey","_objects","_ownerID","_i"
Your complete line should look something like this:

private ["_control","_button","_parent","_group","_pos","_item","_conf","_name","_cfgActions","_numActions","_height","_menu","_config","_type","_script","_outputOriented","_compile","_array","_outputClass","_outputType","_key_colors","_ownerKeyId","_itemsPlayer","_hasKey","_objects","_ownerID","_i"];
Now find this line:

_pos set [3,_height];
Before this line, add the following code:

	/*
		Begin: Vehicle remote lock/unlock
	*/
		_itemsPlayer = items player;
		
		_temp_keys = [];
		_temp_keys_names = [];
		// find available keys
		_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
		if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _item)) in _key_colors) then {
			_ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _item >> "keyid");
			_ownerKeyName = getText(configFile >> "CfgWeapons" >> _item >> "displayName");
			_temp_keys_names set [_ownerKeyId,_ownerKeyName];
			
			_objects = nearestObjects [getPos player, ["LandVehicle","Helicopter","Plane","Ship"], 50];
			_i = 0;
			{
				if (alive _x) then {
					_ownerID = _x getVariable ["CharacterID", "0"];
					_hasKey = (_ownerID == str(_ownerKeyId));
					_oldOwner = (_ownerID == dayz_playerUID);

					if(_hasKey or _oldOwner) then {
						if(locked _x) then {
							//Unlock
							_menu =  _parent displayCtrl (1600 + _numActions);
							_menu ctrlShow true;
							_text =  "Unlock";
							_script =  "[""" + _ownerID + """] execVM ""scripts\remote_unlock.sqf""";
							_height = _height + (0.025 * safezoneH);
							uiNamespace setVariable ['uiControl', _control];
							_menu ctrlSetText _text;
							_menu ctrlSetEventHandler ["ButtonClick",_script];
						} else {
							//Lock
							_menu =  _parent displayCtrl (1600 + _numActions);
							_menu ctrlShow true;
							_text =  "Lock";
							_script =  "[""" + _ownerID + """] execVM ""scripts\remote_lock.sqf""";
							_height = _height + (0.025 * safezoneH);
							uiNamespace setVariable ['uiControl', _control];
							_menu ctrlSetText _text;
							_menu ctrlSetEventHandler ["ButtonClick",_script];
						};
						//Engine start
						_menu =  _parent displayCtrl (1600 + _numActions + 1);
						_menu ctrlShow true;
						_text =  "Engine";
						_script =  "[""" + _ownerID + """] execVM ""scripts\remote_engine.sqf""";
						_height = _height + (0.025 * safezoneH);
						uiNamespace setVariable ['uiControl', _control];
						_menu ctrlSetText _text;
						_menu ctrlSetEventHandler ["ButtonClick",_script];
					};
					
					_i = _i + 1;
				};
			} forEach _objects;
		};
	/*
		End: Vehicle remote lock/unlock
	*/
3. Modify fn_gearMenuChecks.sqf

Find:

if((locked _cTarget) and _isOk and (((vehicle player) distance _cTarget) < 12)) then {
Replace it with:

 

if((locked _cTarget) and _isOk and !_inVehicle and(((vehicle player) distance _cTarget) < 12)) then {
4. Create remote_lock.sqf

Create a new file in your scripts folder in your missions folder (create the folder if it does not already exist) named remote_lock.sqf.

 

Add the following code to that file:

private ["_ownerID","_objects","_i","_ownerID2","_vehicle"];
_ownerID = _this select 0;

_objects = nearestObjects [getPos player, ["LandVehicle","Helicopter","Plane","Ship"], 50];
_i = 0;
{
	_vehicle = _x;
	if (alive _vehicle) then {
		_ownerID2 = _vehicle getVariable ["CharacterID", "0"];

		if(_ownerID == _ownerID2) then {
			if(!locked _vehicle) then {
				if(player distance _vehicle < 50) then {
					DZE_ActionInProgress = true;
					{player removeAction _x} forEach s_player_lockunlock;s_player_lockunlock = [];
					s_player_lockUnlock_crtl = 1;

					PVDZE_veh_Lock = [_vehicle,true];
					if (local _vehicle) then {
						PVDZE_veh_Lock spawn local_lockUnlock
					} else {
						publicVariable "PVDZE_veh_Lock";
					};
					
					titleText ["Vehicle has been locked","PLAIN DOWN"];
					
					s_player_lockUnlock_crtl = -1;
					DZE_ActionInProgress = false;
				};
			};
		};
		
		_i = _i + 1;
	};
} forEach _objects;
5. Create remote_unlock.sqf

Create a new file in your scripts folder in your missions folder (create the folder if it does not already exist) named remote_unlock.sqf.

 

Add the following code to that file:

private ["_ownerID","_objects","_i","_ownerID2","_vehicle"];
_ownerID = _this select 0;

_objects = nearestObjects [getPos player, ["LandVehicle","Helicopter","Plane","Ship"], 50];
_i = 0;
{
	_vehicle = _x;
	if (alive _vehicle) then {
		_ownerID2 = _vehicle getVariable ["CharacterID", "0"];
		
		if(_ownerID == _ownerID2) then {
			if(locked _vehicle) then {
				if(player distance _vehicle < 50) then {
					DZE_ActionInProgress = true;
					{player removeAction _x} forEach s_player_lockunlock;s_player_lockunlock = [];
					s_player_lockUnlock_crtl = 1;

					PVDZE_veh_Lock = [_vehicle,false];
					if (local _vehicle) then {
						PVDZE_veh_Lock spawn local_lockUnlock
					} else {
						publicVariable "PVDZE_veh_Lock";
					};

					titleText ["Vehicle has been unlocked","PLAIN DOWN"];
					
					s_player_lockUnlock_crtl = -1;
					DZE_ActionInProgress = false;
				};
			};
		};
		
		_i = _i + 1;
	};
} forEach _objects;
6. Create remote_engine.sqf

Create a new file in your scripts folder in your missions folder named remote_engine.sqf.

 

Add the following code to that file:

private ["_ownerID","_objects","_i","_ownerID2","_vehicle","_driver","_aigroup"];
_ownerID = _this select 0;

_objects = nearestObjects [getPos player, ["LandVehicle","Helicopter","Plane","Ship"], 50];
_i = 0;
{
	_vehicle = _x;
	if (alive _vehicle) then {
		_ownerID2 = _vehicle getVariable ["CharacterID", "0"];

		if(_ownerID == _ownerID2) then {
			if(!locked _vehicle) then {
				if(player distance _vehicle < 50) then {
					DZE_ActionInProgress = true;
					
					if (isEngineOn _vehicle) then {
						player action ["engineOff", _vehicle];
					} else {
						player action ["engineOn", _vehicle];
					};

					player action ["engineOn", _vehicle];
					
					DZE_ActionInProgress = false;
				};
			};
		};
		
		_i = _i + 1;
	};
} forEach _objects;
7. Optional: Add the iconic "beep beep" sound when locking or unlocking a vehicle.

As an additional bonus, here's how to add a car alarm arm/disarm sound when locking or unlocking a vehicle (including when using the key remote).

 

I claim no credits for this part, credits goes to Sukkaed i think - 

 

Open the description.ext file in your mission folder.

 

Find the following line:

class RscLoadingText : RscText
Before this line, add the following:

class CfgSounds
{
    sounds[] =
    {
		carLock
    };
    class carLock
    {
		name="carLock";
		sound[]={carlock.ogg,0.9,1};
		titles[] = {};
    };
};
... Or if you already have CfgSounds defined, add the appropriate information to it.

 

Now change your compiles.sqf files reference to local_lockUnlock to the following:

local_lockUnlock =			compile preprocessFileLineNumbers "custom\local_lockUnlock.sqf";		//When vehicle is local to unit perform locking vehicle
Create a new file custom\local_lockUnlock.sqf in your mission folder, add the following:

private ["_vehicle","_status","_sounddist"];
_vehicle = _this select 0;
_status = _this select 1;
_sounddist = 20;

if (local _vehicle) then {
	if(_status) then {
		_vehicle setVehicleLock "LOCKED";
		player action ["lightOn", _vehicle];
		_nul = [objNull, _vehicle, rSAY, "carLock", _sounddist] call RE;
		sleep 0.5;
		player action ["lightOff", _vehicle];
	} else {
		_vehicle setVehicleLock "UNLOCKED";
		player action ["lightOn", _vehicle];
		_nul = [objNull, _vehicle, rSAY, "carLock", _sounddist] call RE;
		sleep 0.5;
		player action ["lightOff", _vehicle];
	};
};
Add a carlock.ogg file with the sound to want to be played to your mission folder and you should be all done.

 

I have uploaded a sample ogg file here: carlock.ogg.

 

 

8. All done!

Save all, repack, upload and enjoy.

Credits / attribution / thank you

J.Dohja

shaundibble69

raymix

maca134

Sukkaed

dgx

Link to comment
Share on other sites

Hey.

I have a suggestion. The script seems really nice, but one thing you could add, so admins could turn it on and off.

This is a nice thing when zombies chase you and you gotta run for ya life to the car to drive off. But it's a little too easy, too OP.
Could you add some sort of a transmitter to it, so that it works only if a player has a key and a transmitter in a toolbelt.
That way it would balance the pros and cons, and would make a brilliant addition to epoch.

This option should be toggleable, cause some admins might not know how to add this transmitter to their loottable, or simply would not want their game to be too difficult. We would love to use this on our server, but we don't want to make it too easy for our players

You could use 'IRStrobe' as a transmitter model, and make a 'how-to' on how to add this as a toolbelt item so that admins could add this properly to the loot tables  :)

I myself have no idea about scripting so I'm not even sure if changing this 'IRStrobe' from a regular item to a toolbelt item is doable without some more serious changes to the server.pbo :D

Link to comment
Share on other sites

 

 

This isn't in Epoch, its a script for admins to install, so if admins want it disabled, they simply don't install it lol

 

Did you even read what I wrote? :D

Did you understand it, or just replied without thinking?

I know it's a script. I know that the best way of having it disabled is to not install it.

What I wrote, and you failed to comprehend, was that I wanted a transmitter option to be toggleable, so admins could decide, whether to use it or not. 

For me, simple right click, to open a car from a distance is too easy. 

The author of the script could enhance his script with this transmitter option, that way he would please both, easygoing players and admins, who like the game to be easy AND players and admins who require something more (like finding something extra, to make something work).

 

It is best to add such things by the author, cause that way he can make sure it's added the way he wanted it to be done in the first place. I probably could add this by myself with the 'monkey sees, monkey does' method, but I am nowhere near of knowing what I'm doing, so I would probably spam this topic more and more with questions on how to set this properly.

Why not ask someone who came up with this great idea of a remote key, to add this another feature to his script?  

Savvy?

Link to comment
Share on other sites

Did you even read what I wrote? :D

Did you understand it, or just replied without thinking?

I know it's a script. I know that the best way of having it disabled is to not install it.

What I wrote, and you failed to comprehend, was that I wanted a transmitter option to be toggleable, so admins could decide, whether to use it or not. 

For me, simple right click, to open a car from a distance is too easy. 

The author of the script could enhance his script with this transmitter option, that way he would please both, easygoing players and admins, who like the game to be easy AND players and admins who require something more (like finding something extra, to make something work).

 

It is best to add such things by the author, cause that way he can make sure it's added the way he wanted it to be done in the first place. I probably could add this by myself with the 'monkey sees, monkey does' method, but I am nowhere near of knowing what I'm doing, so I would probably spam this topic more and more with questions on how to set this properly.

Why not ask someone who came up with this great idea of a remote key, to add this another feature to his script?  

Savvy?

 

I will take the suggestion to mind and perhaps expand upon this script with configuration options, which would include this.

 

In the meanwhile, to achieve what you want you can change the section of the player_selectSlot.sqf to this:

	/*
		Begin: Vehicle remote lock/unlock
	*/
	if ("IRStrobe" in items player) then { //<----
	_itemsPlayer = items player;
	
	// find available keys
	_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
	if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _item)) in _key_colors) then {
		_ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _item >> "keyid");
		
		_objects = nearestObjects [getPos player, ["LandVehicle","Helicopter","Plane","Ship"], 50];
		_i = 0;
		{
			if (alive _x) then {
				_ownerID = _x getVariable ["CharacterID", "0"];
				_hasKey = (_ownerID == str(_ownerKeyId));
				_oldOwner = (_ownerID == dayz_playerUID);

				if(_hasKey or _oldOwner) then {
					if(locked _x) then {
						_menu =  _parent displayCtrl (1600 + _numActions);
						_menu ctrlShow true;
						_text =  "Unlock";
						_script =  "[""" + _ownerID + """] execVM ""scripts\remote_unlock.sqf""";
						_height = _height + (0.025 * safezoneH);
						uiNamespace setVariable ['uiControl', _control];
						_menu ctrlSetText _text;
						_menu ctrlSetEventHandler ["ButtonClick",_script];
					} else {
						_menu =  _parent displayCtrl (1600 + _numActions);
						_menu ctrlShow true;
						_text =  "Lock";
						_script =  "[""" + _ownerID + """] execVM ""scripts\remote_lock.sqf""";
						_height = _height + (0.025 * safezoneH);
						uiNamespace setVariable ['uiControl', _control];
						_menu ctrlSetText _text;
						_menu ctrlSetEventHandler ["ButtonClick",_script];
					};
				};
				
				_i = _i + 1;
			};
		} forEach _objects;
	};
	}; //<----
	/*
		End: Vehicle remote lock/unlock
	*/

Changes from the original post are marked with "//<----". Basically, the code which produce the context menu is conditioned so that if the player does not have a "IRStrobe" in the inventory, the context menu wont appear.

 

Monkey saw, now monkey do.  :)

Link to comment
Share on other sites

Hey, david, thank you, good sir, you're the best ;)

I failed to comprehend something too :D I took a right-click for scroll-menu, that is why I thought of this as too easy. Scrolling mouse while running doesn't require opening your inventory. Had I seen your video before, I wouldn't think of it as too easy :D With the right click from the inventory it adds some risk, AI, zeds or other players can take you down while unlocking car - it is good! :D Plus this transmitter thingy, it will force players to go out of their bases to search for it - it is good! :D 
Thanks for your help with this!
 

Link to comment
Share on other sites

First suggestion  : Add remote "Panic button", honk horn flash lights

 

Good one. Gave me an idea to have this "alarm mode" activated if people shoot at or try to salvage locked vehicles.

 

Hey, david, thank you, good sir, you're the best ;)

I failed to comprehend something too :D I took a right-click for scroll-menu, that is why I thought of this as too easy. Scrolling mouse while running doesn't require opening your inventory. Had I seen your video before, I wouldn't think of it as too easy :D With the right click from the inventory it adds some risk, AI, zeds or other players can take you down while unlocking car - it is good! :D Plus this transmitter thingy, it will force players to go out of their bases to search for it - it is good! :D 

Thanks for your help with this!

 

 

Cheers. IR strobes aren't spawned naturally though, so you need to add it to the traders, loot tables, AI loadout, mission loot or something like that.

Link to comment
Share on other sites

Good Stuff! I love it! I modified it a bit to go with another sound posted in that same thread. So that now it only makes the beep sound when right clicking lock. That way close to it you still hear the key jingle and turn as well as the beep far away but only on key click.I would be interested in adding another right click option like alarm or maybe even start for a remote start engine even?! lol jus for bells and whistles but I have a serious question how about using this same concept for a remote garage door opener? That would be just as helpful! thanks for reading

Link to comment
Share on other sites

Good Stuff! I love it! I modified it a bit to go with another sound posted in that same thread. So that now it only makes the beep sound when right clicking lock. That way close to it you still hear the key jingle and turn as well as the beep far away but only on key click.I would be interested in adding another right click option like alarm or maybe even start for a remote start engine even?! lol jus for bells and whistles but I have a serious question how about using this same concept for a remote garage door opener? That would be just as helpful! thanks for reading

 

Neat ideas. This same concept should be doable for doors as well but I'm not sure what inventory item would make sense to use. The closest match I can think of would be the walkie talkie I guess.

Link to comment
Share on other sites

When i try to edit my CfgSounds my server says wait for host. This is my original Cfg how would i edit it to add the carlock?

 

 

class CfgSounds
{
    sounds[] =
    {
    cureEffect
    };
    class cureEffect
    {
    name="cureEffect";
    sound[]={cure_effect.ogg,0.9,1};
    titles[] = {};
    };    
};
Link to comment
Share on other sites

 

When i try to edit my CfgSounds my server says wait for host. This is my original Cfg how would i edit it to add the carlock?

 

 

class CfgSounds
{
    sounds[] =
    {
    cureEffect
    };
    class cureEffect
    {
    name="cureEffect";
    sound[]={cure_effect.ogg,0.9,1};
    titles[] = {};
    };    
};

 

 

Your new CfgSounds class should look like this:

class CfgSounds
{
    sounds[] =
    {
    cureEffect
    , carLock
    };
    class cureEffect
    {
    name="cureEffect";
    sound[]={cure_effect.ogg,0.9,1};
    titles[] = {};
    };    
    class carLock
    {
    name="carLock";
    sound[]={carlock.ogg,0.9,1};
    titles[] = {};
    };    
};

Remember to put the carlock.ogg file in the mission folder, and best of luck to you.

Link to comment
Share on other sites

only problem with the script is that you can lock yourself in your vehicle and cant get out. 

 

CANT ACCESS INVENTORY OF LOCKED VEHICLE.

 

Thanks, will work out a solution for that tonight.

Link to comment
Share on other sites

How about adding a check if player is inside a vehicle, then use either:

1) hotkey (refering to DIK_KeyCodes), lets say a space bar 0x39 (might want to add sleep timer to prevent people from spamming button)

2) action menu using fn_selfActions

 

Should be easy enough to check ID of vehicle player is currently inside

Link to comment
Share on other sites

the 'beep beep' noise should only happen when locking/unlocking the car remotely.

Can this be modified in any way so that when standing next to car and scrolling to lock/unlock, the beep doesn't happen?

The beep sound is played from local_lockUnlock.sqf, which handles nearly all propper locking/unlocking calls. To make it play only when clicked from the menu, you need to add it to the player_selectSlot.sqf instead which handles the menu stuff.

Remove this line from custom\local_lockUnlock.sqf (both occurrences):

_nul = [objNull, _vehicle, rSAY, "carLock", _sounddist] call RE;
And add this line in player_selectSlot.sqf:

_nul = [objNull, _x, rSAY, "carLock", _sounddist] call RE;
... directly below this line:

if(_hasKey or _oldOwner) then {
Link to comment
Share on other sites

closeDialog 0;

Excuse me, but in which file(s) and where exactly do I put this? I'm assuming it goes directly above the last }; but wanted to be sure. I can follow directions and have managed to Frankenstein a few scripts together but I'm still very much learning. I'm split between putting it at the end of player_selectSlot or remote_lock and remote_unlock.

 

To the OP: Thank you so much for posting this!!! I have taken all of the customizations and bundled them together for our server. I can't wait to see what our players think of this! Keep up the awesome work! Also, please do not give up on the remote Garage Door idea. I know many, many people would absolutely love that! I'm thinking of tying this to a radio instead of an IR strobe simply because it makes a little more sense in my mind. If they want radios they can go hunt down some AIs in the missions. Tying the garages to the radios as well would be an added bonus for me.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
×
×
  • Create New...