Jump to content

[RELEASE] Vehicle Key Changer - For making Masterkey - V 1.4 (Updated 06/15/2014)


OtterNas3

Recommended Posts

Got it working with Otter's help!

 

Make sure you have the version with the added ; in Vehiclefunctions.sqf

 

Also, I removed the _hasKeyKit requirement.

 

Here is my Vehiclefunctions.sqf (not the path to the folder is different since I use a Scripts folder:

private ["_itemsPlayer","_temp_Keys","_temp_keysDisplayName","_temp_keysDisplayNameParse","_key_colors","_ownerKeyId","_carKey","_hasKey","_cTarget","_keyName","_carKeyName"];
waitUntil {!isNil "dayz_animalCheck"};
while{true} do {
	sleep 3;
	if (speed player <= 1 && (vehicle player) == player && !isEngineOn cursorTarget && (cursorTarget isKindOf "Car" || cursorTarget isKindOf "Air" || cursorTarget isKindOf "Ship")) then {
		_cTarget = cursorTarget;
		_carKey = _cTarget getVariable ["CharacterID","0"];
		if (_carKey != "0") then {
			_itemsPlayer = items player;
			_temp_keys = [];
			_temp_keysDisplayName = [];
			_temp_keysDisplayNameParse = [];
			_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
			{
				if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in _key_colors) then {
					_ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _x >> "keyid");
					_keyName = getText(configFile >> "CfgWeapons" >> _x >> "displayName");
					_temp_keysDisplayName set [count _temp_keysDisplayName,_keyName];
					_temp_keysDisplayNameParse set [_ownerKeyId,_keyName];
					_temp_keys set [count _temp_keys,str(_ownerKeyId)];
				};
			} forEach _itemsPlayer;
			_hasKey = _carKey in _temp_keys;
			if (_hasKey && (count _temp_keys) > 1 && (_ctarget distance player) <= 10) then {
				_carKeyName = (_temp_keysDisplayNameParse select (parseNumber _carKey));
				_temp_keys = _temp_keys - [_carKey];
                _temp_keysDisplayName = _temp_keysDisplayName - [_carKeyName];
				if (s_player_copyToKey < 0) then {
					s_player_copyToKey = player addAction [("<t color=""#0000FF"">" + ("Change Vehicle Key") + "</t>"),"Scripts\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, _carKey, _temp_keysDisplayName, _carKeyName],-1,false,false,"",""];
				};
			} else {
				player removeAction s_player_copyToKey;
				s_player_copyToKey = -1;
			};
		} else {
			player removeAction s_player_copyToKey;
			s_player_copyToKey = -1;
		};
	} else {
		player removeAction s_player_copyToKey;
		s_player_copyToKey = -1;
	};
};

Link to comment
Share on other sites

Please check your custom\vehiclefunctions.sqf

It has to look like this:

private ["_itemsPlayer","_temp_Keys","_temp_keysDisplayName","_temp_keysDisplayNameParse","_key_colors","_ownerKeyId","_carKey","_hasKey","_cTarget","_keyName","_carKeyName"];
waitUntil {!isNil "dayz_animalCheck"};
while{true} do {
	sleep 3;
	if (speed player <= 1 && (vehicle player) == player && !isEngineOn cursorTarget && (cursorTarget isKindOf "Car" || cursorTarget isKindOf "Air" || cursorTarget isKindOf "Ship")) then {
		_cTarget = cursorTarget;
		_carKey = _cTarget getVariable ["CharacterID","0"];
		if (_carKey != "0") then {
			_itemsPlayer = items player;
			_hasKeyKit = "ItemKeyKit" in _itemsPlayer;
			_temp_keys = [];
			_temp_keysDisplayName = [];
			_temp_keysDisplayNameParse = [];
			_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
			{
				if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in _key_colors) then {
					_ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _x >> "keyid");
					_keyName = getText(configFile >> "CfgWeapons" >> _x >> "displayName");
					_temp_keysDisplayName set [count _temp_keysDisplayName,_keyName];
					_temp_keysDisplayNameParse set [_ownerKeyId,_keyName];
					_temp_keys set [count _temp_keys,str(_ownerKeyId)];
				};
			} forEach _itemsPlayer;
			_hasKey = _carKey in _temp_keys;
			if (_hasKey && _hasKeyKit && (count _temp_keys) > 1 && (_ctarget distance player) <= 10) then {
				_carKeyName = (_temp_keysDisplayNameParse select (parseNumber _carKey));
				_temp_keys = _temp_keys - [_carKey];
				_temp_keysDisplayName = _temp_keysDisplayName - [_carKeyName];
				if (s_player_copyToKey < 0) then {
					s_player_copyToKey = player addAction [("<t color=""#0000FF"">" + ("Change Vehicle Key") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, _carKey, _temp_keysDisplayName, _carKeyName],-1,false,false,"",""];
				};
			} else {
				player removeAction s_player_copyToKey;
				s_player_copyToKey = -1;
			};
		} else {
			player removeAction s_player_copyToKey;
			s_player_copyToKey = -1;
		};
	} else {
		player removeAction s_player_copyToKey;
		s_player_copyToKey = -1;
	};
};

Specially look at this line:

			_hasKeyKit = "ItemKeyKit" in _itemsPlayer;

the ; on the end of the line was missing in one version of the downloadpackage!

If it's missing in your's add it to the end of the line or just redownload the VehicleChangeKey.zip from first post amd replace the file.

Link to comment
Share on other sites

This is great.

However I can see some issues with players trying to use this for vehicles on weird places (tight spaces, helipads, etc.) since the vehicle seems to basically respawn and frequently bounces around a little.

Also, I don't know how to replicate it but it once duped a Humvee I had spawned via the HIVE function of InfiSTAR.

It did that only once and it doesn't seem to do it with any other vehicle, perhaps it was due to some temporary desync issue.

Link to comment
Share on other sites

working great so far thankz for this.... great work

Thank you

 

OtterNas3, you sir are a genius, works flawlessly now. Many thanks for this.

Your welcome, but there are other coders here who should be called - Genius!

Im just putting my thoughts together.

 

This is great.

However I can see some issues with players trying to use this for vehicles on weird places (tight spaces, helipads, etc.) since the vehicle seems to basically respawn and frequently bounces around a little.

Also, I don't know how to replicate it but it once duped a Humvee I had spawned via the HIVE function of InfiSTAR.

It did that only once and it doesn't seem to do it with any other vehicle, perhaps it was due to some temporary desync issue.

The script uses the "upgrade" function of Epoch, thats why they seem to -bump- a bit.

It deletes them and spawns a new one on the same position.

Cause there is no reset of the velocity in the respawn function, the vehicles bumps on uneven ground.

 

So there is no way i could reset the velocity for the Vehicle when its respawned, I tested a bit and this would be the best way to stop the movement:

 

unpbo your dayz_server.pbo

Edit file dayz_server\compiles\server_publishVehicle3.sqf

 

Go to line 90, it should look like this:

	_object setPosATL _location;

replace the line with this block:

	_location = [(_location) select 0, (_location) select 1, ((_location) select 2) + 0.2];
	_object setPosATL _location;
	sleep 0.1;
	_object setVelocity [0,0,0.1];

This stops the movement on all surfaces, also when you upgrade the vehicle with one of the upgrade documents.

 

For the duping, i guess you spawned the Vehicle and did not get in as a Driver once before you changed the Key?

I'm pretty sure this is what cause the duping.

Link to comment
Share on other sites

Thats why Epoch dont use these Vehicles and created for the most Vehicles a  _DZ or _DZE version.

you could change the code for the respawning part in server_publishVehicle3.sqf to clear the Weapon, Magazine and Backpack Cargo before it readds the loot that was in before changing the key.

I will have a look hold on...

 

EDIT:

 

Find this in the server_publishVehicle3.sqf:

        // switch var to new vehicle at this point.
        _object = _newobject;

Replace with:

	// switch var to new vehicle at this point.
	_object = _newobject;
	clearWeaponCargoGlobal  _object;
	clearMagazineCargoGlobal  _object;
	clearBackpackCargoGlobal _object;

Should fix it

Link to comment
Share on other sites

Yep, having the same problem. A player reported changing a key on a UN Ural, the ural duped its contents and threw them all on the floor.

Also, a player has reported getting a blackscreen right after duping the key and getting into the vehicle (but I think he didn't wait it out and got into the old, despawning vehicle and got broken); rejoining fixed it, but it's probably worth warning people to wait a few seconds before re-entering the new vehicle.

Link to comment
Share on other sites

The respawn of the Vehicles depends on the Server load, if your server fps is very low it takes some time for the server to respawn the vehicle.

Database reaction time does matter too.

 

I could insert a lock of the vehicle so noone can hop in whille changing the key for it.

Or maybe moving the original Key for the vehicle into the players backpack.

Will have a look tomorrow.

 

For the duping, i never had such a thing on my server with normal Epoch vehicles.

For Arma2/OA vehicles which holds any gear in it try the fix i posted 2 posts ago

Link to comment
Share on other sites

Love the mod but it seems to make around 6 or 7 dupes of a vehicle for regular players or spawn a extra one after restart. Anyone get this fixed? If so can you point me in the right direction please and I have the a for mentioned changes to publishvehicle3 changed. I run Epoch 1.0.3 Thanks  

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...