orionjade Posted March 4, 2014 Report Share Posted March 4, 2014 Unable to get this to fully work. It does everything it should but after its done I can't unlock the vehicle with the new key. I'm using the newest version and I'm running 1.0.4.2 Any help would be appreciated. Link to comment Share on other sites More sharing options...
xPr0di9yx Posted March 5, 2014 Report Share Posted March 5, 2014 First of all great work on this script Otter! Love your work. Everything works as intended on my sever with the following exception: I'm having the same issues that some other people are with Masterkey V 1.3 on Epoch 1.0.4.2a. Some vehicles are warping to other vehicles/gear deleted/vehicles destroyed upon restart. The only thing I noticed that is different about these re-keyed vehicles in the database (other than the CharacterID being the same for obvious reasons) is that all the re-keyed vehicles now have a single 0 in the ObjectUID column. Does the ObjectUID column make each vehicle unique? I would assume so since each object has a unique ObjectUID but I am not sure if ObjectUID is simply a receipt code or something similar when the vehicle gets created in the database or if that column even gets read during object placement on restart. Does this have anything to do with the vehicles warping onto each other etc. since all have the same number - 0? Anyone else seeing this in their database? Link to comment Share on other sites More sharing options...
Sellis Posted March 5, 2014 Report Share Posted March 5, 2014 Yes, I was just noticing that "0" in the database for the UID on my re-keyed vehicles. Anybody have any idea about that or what can be done about it? I don't see any replays from the original poster of the mod for a whole now, maybe somebody else should examin the issue? Link to comment Share on other sites More sharing options...
sjd6795 Posted March 5, 2014 Report Share Posted March 5, 2014 I keep getting public variable restriction #77. I've installed everything correctly I have a fully loaded server with absolutely no problems until I added this. I'm guessing your battleeye file is out of date. Link to comment Share on other sites More sharing options...
Rythron Posted March 5, 2014 Report Share Posted March 5, 2014 First of all great work on this script Otter! Love your work. Everything works as intended on my sever with the following exception: I'm having the same issues that some other people are with Masterkey V 1.3 on Epoch 1.0.4.2a. Some vehicles are warping to other vehicles/gear deleted/vehicles destroyed upon restart. The only thing I noticed that is different about these re-keyed vehicles in the database (other than the CharacterID being the same for obvious reasons) is that all the re-keyed vehicles now have a single 0 in the ObjectUID column. Does the ObjectUID column make each vehicle unique? I would assume so since each object has a unique ObjectUID but I am not sure if ObjectUID is simply a receipt code or something similar when the vehicle gets created in the database or if that column even gets read during object placement on restart. Does this have anything to do with the vehicles warping onto each other etc. since all have the same number - 0? Anyone else seeing this in their database? Same problem here. all ObjectUID 0 and CharacterID all the same. some vehicles dissapear and some vehicles go backto the last place the changed to the key. I have testing it and even my fueltruck changed to the repairtruck that was missing and somethimes 3 the same vehicles appear. All after restart . :( I hope somebody can find out why the ObjectUID all change to 0 and the same for the CharacterID change to the same number? Link to comment Share on other sites More sharing options...
xPr0di9yx Posted March 6, 2014 Report Share Posted March 6, 2014 I hope somebody can find out why the ObjectUID all change to 0 and the same for the CharacterID change to the same number? The CharacterID changes to the same number because that is how Epoch translates the keyid for vehicles. Changing the CharacterID to the same number makes both vehicles use the same key. So that works as intended. The ObjectUID is something I haven't had a chance to play around with to see if that is where the issue lies. Link to comment Share on other sites More sharing options...
Turk Posted March 8, 2014 Report Share Posted March 8, 2014 Have this disabled due to the issue,... really like this mod and would like to put it back in (or roll back to an older version is anyone has) Any word on a fix? Link to comment Share on other sites More sharing options...
Mr White Posted March 8, 2014 Report Share Posted March 8, 2014 Similar problems here, I didn't quite understand it, I had a helicopter that followed me around. I finally realized that the keychanged vehicles were interchanging with each-other upon restart. Link to comment Share on other sites More sharing options...
Gwandoya Posted March 10, 2014 Report Share Posted March 10, 2014 Hi! In first line thanks for the author for this great idea and code! To solve the problem with disappearing and replaced vehicles, open VehicleKeyChanger_init.sqf and place the following code after function ON_fnc_vkc_reset in line 56: dayz_objectUID_vkc = { private["_position","_dir","_key","_object"]; _object = _this; _position = getPosATL _object; _dir = direction _object; _key = [_dir,_position] call dayz_objectUID2_vkc; _key }; dayz_objectUID2_vkc = { private["_position","_dir","_key"]; _dir = _this select 0; _key = ""; _position = _this select 1; { _x = _x * 10; if ( _x < 0 ) then { _x = _x * -10 }; _key = _key + str(round(_x)); } forEach _position; _key = _key + str(round(_dir)); _key }; I suggest to reset some variables as well, place the following code after waitUntil {!isNil "dayz_animalCheck"}; in line 83: s_player_copyToKey=-1; lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; I also changed the self action menu text in that case when you claim a vehicle without a key, text "Change Vehicle Key" changed to "Claim Vehicle" in line 118. And I got an odd 'general error' in some cases (probably when I had no key in my inventory but all other requirements were fullfilled) so, I changed if (_carKey != "0") then { to } else { Now open VehicleKeyChanger.sqf and add the following code to line 129: /* Giving unique UID for claimed vehicles */ if (_targetVehicleUID=="0") then { _targetVehicleUID = _targetVehicle call dayz_objectUID_vkc; _targetVehicle setVariable ["ObjectUID",_targetVehicleUID,true]; // It does probably nothing and it's not needed :) }; With these modfifications you can Claim a server spawned vehicle which has only ObjectID (MySQL primary, autoincremented ID) but ObjectUID=0. On our server you can claim mission vehicles as well, because for mission vehicles we generate ObjectID="0" and ObjectUID=_vehicle call dayz_objectUID; (Server side call.) dayz_objectUID and dayz_objectUID2 are standard ObjectUID generator functions from server_functions.sqf, and we had to place them to client side (_vkc added to names). To fix objects stored in your database with ObjectUID=0 just run this MySQL command on object_data table: UPDATE object_data SET ObjectUID=ROUND(RAND(1)*1000000000000000) WHERE ObjectUID=0 [ Modifications made for Vehicle Key Changer - For making Masterkey - V 1.3 (Updated 02/20/2014) ] Rythron, koolaidman04 and Radec59437 3 Link to comment Share on other sites More sharing options...
Sellis Posted March 10, 2014 Report Share Posted March 10, 2014 Thanks Gwandoya! I have tested this on my server and it seems to eliminate the issue. I have also applied your SQL query to fix my other vehicles for good measure. I really appreciate your taking the time to figure this out and share it with us! One minor suggestion, you may wan to edit your post for the more inexperienced scripters. Where you say this: so, I changed if (_carKey != "0") then { to } else { Now open VehicleKeyChanger.sqf and You really need to delete the "};" that is closing the if block before that script for that to work. The way you have it, taken literally, it will cause errors. I think you meant: so, I changed 122. }; if (_carKey != "0") then { to } else { Now open VehicleKeyChanger.sqf and Thanks! -Shawn koolaidman04 1 Link to comment Share on other sites More sharing options...
Gwandoya Posted March 10, 2014 Report Share Posted March 10, 2014 Here's another update which allows you to claim vehicles which were not in database at server start but spawned by a mission script. Open your server_updateObject.sqf included in Vehicle Key Changer release and add after _object setVariable ["ObjectID", _vehicleID, true]; in line 244: /* Save the ObjectUID to the vehicles variable and make it public */ _object setVariable ["ObjectUID", _vehicleUID, true]; Add code after _object setVariable ["reargundeployed",0,true]; before the closing bracket to line 267: _object call fnc_veh_ResetEH; This is important to add the event handlers to the mission vehicles, otherways Epoch won't update the position, gear and damage of your vehicle, and after server restart it will spawn at that place where you claimed the vehicle. And one small note: mission vehicles will not be saved correctly if your mission script sets ObjectID="1" (and ObjectUID="1"). The next claimed vehicle will always overwrite the previous one because both have ObjectID 1 in database. To solve this, you might need to modify your AI mission script: (replace "_vehicle" with the appropriate variable name.) _uid = _vehicle call dayz_objectUID; _vehicle setVariable ["ObjectID", "0", true]; _vehicle setVariable ["ObjectUID", _uid, true]; (It doesn't matter if ObjectID is zero, HiveWrite will add a new record to object_data table.) And of course, object has to be in PVDZE_serverObjectMonitor :) PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor, _vehicle]; koolaidman04 1 Link to comment Share on other sites More sharing options...
Testo Posted March 11, 2014 Report Share Posted March 11, 2014 Very nice that someone took care of this script, it is very useful but caused more trouble than help. Do you think that you could actually sum it all up, make new post about it ( giving creds to author ofc) and stuff ? Its kinda in mess here and might be hard to implement for someone. Otherwise, thank you sir. Link to comment Share on other sites More sharing options...
jay8454 Posted March 12, 2014 Report Share Posted March 12, 2014 Are the last 4 posted relative to the very first one with the directions? I am trying to get this thing working and I am failing, it doesn't work, no menu to speak of. Any suggestions? AHconf CMD DONE server_updateObject.sqf DONE main ini.sqf DONE files installed DONE. NO RPT Errors All done according to the vary first post. With the exception to the BE filter PubVar I can not run this with infiSTAR I get lots of public kick variables. Link to comment Share on other sites More sharing options...
Radec59437 Posted March 13, 2014 Report Share Posted March 13, 2014 Hi! In first line thanks for the author for this great idea and code! To solve the problem with disappearing and replaced vehicles, open VehicleKeyChanger_init.sqf and place the following code after function ON_fnc_vkc_reset in line 56: dayz_objectUID_vkc = { private["_position","_dir","_key","_object"]; _object = _this; _position = getPosATL _object; _dir = direction _object; _key = [_dir,_position] call dayz_objectUID2_vkc; _key }; dayz_objectUID2_vkc = { private["_position","_dir","_key"]; _dir = _this select 0; _key = ""; _position = _this select 1; { _x = _x * 10; if ( _x < 0 ) then { _x = _x * -10 }; _key = _key + str(round(_x)); } forEach _position; _key = _key + str(round(_dir)); _key }; I suggest to reset some variables as well, place the following code after waitUntil {!isNil "dayz_animalCheck"}; in line 83: s_player_copyToKey=-1; lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; I also changed the self action menu text in that case when you claim a vehicle without a key, text "Change Vehicle Key" changed to "Claim Vehicle" in line 118. And I got an odd 'general error' in some cases (probably when I had no key in my inventory but all other requirements were fullfilled) so, I changed if (_carKey != "0") then { to } else { Now open VehicleKeyChanger.sqf and add the following code to line 129: /* Giving unique UID for claimed vehicles */ if (_targetVehicleUID=="0") then { _targetVehicleUID = _targetVehicle call dayz_objectUID_vkc; _targetVehicle setVariable ["ObjectUID",_targetVehicleUID,true]; // It does probably nothing and it's not needed :) }; With these modfifications you can Claim a server spawned vehicle which has only ObjectID (MySQL primary, autoincremented ID) but ObjectUID=0. On our server you can claim mission vehicles as well, because for mission vehicles we generate ObjectID="0" and ObjectUID=_vehicle call dayz_objectUID; (Server side call.) dayz_objectUID and dayz_objectUID2 are standard ObjectUID generator functions from server_functions.sqf, and we had to place them to client side (_vkc added to names). To fix objects stored in your database with ObjectUID=0 just run this MySQL command on object_data table: UPDATE object_data SET ObjectUID=ROUND(RAND(1)*1000000000000000) WHERE ObjectUID=0 [ Modifications made for Vehicle Key Changer - For making Masterkey - V 1.3 (Updated 02/20/2014) ] Link to comment Share on other sites More sharing options...
Mr White Posted March 13, 2014 Report Share Posted March 13, 2014 The way it is acting, is as if the key name is the name for the vehicle on the table. Duplicating the key creates two different vehicles with the same identifier... so when the server respawns vehicles, it weirds out. At least that is what the behavior is indicative of. I hate posting from a phone, it corrects my spelling and makes me look less like a crackhead. Link to comment Share on other sites More sharing options...
caboose1 Posted March 16, 2014 Report Share Posted March 16, 2014 Well at least you can get it working i dont get any option Link to comment Share on other sites More sharing options...
Havoc302 Posted March 16, 2014 Report Share Posted March 16, 2014 Hi, Firstly love the mod, makes life so much easier. We're just having an issue where we masterkey a vehicle / chopper and it'll move / disappear and be replaced by some other random vehicle that's locked that i don't have the key for in the exact place the one i did was, any ideas? Thanks, Havoc. Link to comment Share on other sites More sharing options...
Borg8401 Posted March 18, 2014 Report Share Posted March 18, 2014 . Link to comment Share on other sites More sharing options...
Affraid Posted March 19, 2014 Report Share Posted March 19, 2014 . Goto Post #134 on previous page. I have not personally tested it yet , but I will today. Link to comment Share on other sites More sharing options...
Affraid Posted March 19, 2014 Report Share Posted March 19, 2014 @GWANDOYA Did add the code right? I can't get it to work at all now. No option comes up when I'm at a vehicle. I did not add the claim vehicle change. Since I don't use that option. Thank you in advance /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ private ["_itemsPlayer","_magazinesPlayer","_temp_Keys","_temp_keysDisplayName","_temp_keysDisplayNameParse","_key_colors","_ownerKeyId","_carKey","_hasKey","_cTarget","_keyName","_carKeyName","_targetVehicleKey","_temp_keysParse"]; ///////////////////////////////////////////////// ///////////////////////////////////////////////// // Edit these settings to fit your needs/likes // ///////////////////////////////////////////////// ///////////////////////////////////////////////// /// Claim Vehicles that does not yet need Key /// ///////// 0 = Not allowed | 1 = Allowed ///////// vkc_claiming = 0; ///////////////////////////////////////////////// //////// Claim Vehicles costs this Item ///////// /// Any Item can be used here, some examples: /// //// ItemTinBar, ItemSilverBar, ItemGoldBar, //// ////// ItemSilverBar10oz, ItemGoldBar10oz, ////// ///// ItemBriefcase20oz, ItemBriefcase100oz ///// //////// set to "0" to disable the costs //////// vkc_claimingPrice = "ItemGoldBar10oz"; ///////////////////////////////////////////////// ////////// Change Key costs this Item// ///////// ////////////// see above examples /////////////// //////// set to "0" to disable the costs //////// vkc_Price = "0"; ///////////////////////////////////////////////// /////// Need KeyKit to use this function //////// ////////// 0 = Not needed | 1 = Needed ////////// vkc_needKeykit = 1; ///////////////////////////////////////////////// ///////////////////////////////////////////////// /////////////// DONT EDIT BELOW ! /////////////// ///////////////////////////////////////////////// /* Reset variables function */ ON_fnc_vkc_reset = { _cTarget = objNull; _itemsPlayer = []; _temp_keys = []; _carKey = objNull; _hasKey = false; _temp_keysDisplayName = []; _temp_keysDisplayNameParse = []; _temp_keysParse = []; _targetVehicleKey = objNull; _carKeyName = ""; player removeAction s_player_copyToKey; s_player_copyToKey = -1; }; /* Wait for player full ingame so we can access the action-menu */ waitUntil {!isNil "dayz_animalCheck"}; s_player_copyToKey=-1; lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; /* Start the loop check */ while{true} do { sleep 3; if (!isNull cursorTarget && speed player <= 1 && (vehicle player) == player && !isEngineOn cursorTarget && (cursorTarget isKindOf "Motorcycle" || cursorTarget isKindOf "Car" || cursorTarget isKindOf "Air" || cursorTarget isKindOf "Ship") && (cursorTarget distance player) <= 10 && cursorTarget getVariable ["VKC_disabled", 0] == 0 && cursorTarget getVariable ["VKC_claiming_disabled",0] == 0) then { _cTarget = cursorTarget; _itemsPlayer = items player; _magazinesPlayer = magazines player; if ((lastKeyChangeCursorTarget select 0) != _cTarget) then { if (s_player_copyToKey >= 0) then { player removeAction s_player_copyToKey; s_player_copyToKey = -1; }; }; lastKeyChangeCursorTarget set [0,_cTarget]; _carKey = _cTarget getVariable ["CharacterID","0"]; if (("ItemKeyKit" in _itemsPlayer || vkc_needKeykit == 0) && ((_carKey == "0" && vkc_claiming == 1 && (vkc_claimingPrice == "0" || vkc_claimingPrice in _magazinesPlayer)) || _carKey != "0") && (vkc_Price == "0" || vkc_Price in _magazinesPlayer)) then { if (_carKey == "0") then { _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_keys set [count _temp_keys,str(_ownerKeyId)]; }; } forEach _itemsPlayer; if ((count _temp_keys) > 0) then { if (s_player_copyToKey < 0) then { lastKeyChangeCursorTarget set [0,_cTarget]; s_player_copyToKey = player addAction [("" + ("Change Vehicle Key") + ""),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, "0", _temp_keysDisplayName, "0", "0", vkc_Price, vkc_claimingPrice],-1,false,false,"",""]; }; } else { [] call ON_fnc_vkc_reset; dayz_objectUID_vkc = { private["_position","_dir","_key","_object"]; _object = _this; _position = getPosATL _object; _dir = direction _object; _key = [_dir,_position] call dayz_objectUID2_vkc; _key }; dayz_objectUID2_vkc = { private["_position","_dir","_key"]; _dir = _this select 0; _key = ""; _position = _this select 1; { _x = _x * 10; if ( _x < 0 ) then { _x = _x * -10 }; _key = _key + str(round(_x)); } forEach _position; _key = _key + str(round(_dir)); _key }; }; if (_carKey != "0") then { _temp_keys = []; _temp_keysDisplayName = []; _temp_keysDisplayNameParse = []; _temp_keysParse = []; _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)]; _temp_keysParse set [_ownerKeyId, _x]; }; } forEach _itemsPlayer; _hasKey = _carKey in _temp_keys; if (_hasKey && (count _temp_keys) > 1) then { _carKeyName = (_temp_keysDisplayNameParse select (parseNumber _carKey)); _targetVehicleKey = (_temp_keysParse select (parseNumber _carKey)); _temp_keys = _temp_keys - [_carKey]; _temp_keysDisplayName = _temp_keysDisplayName - [_carKeyName]; if (s_player_copyToKey < 0) then { lastKeyChangeCursorTarget set [0,_cTarget]; s_player_copyToKey = player addAction [("" + ("Change Vehicle Key") + ""),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, _carKey, _temp_keysDisplayName, _carKeyName, _targetVehicleKey, vkc_Price, "0"],-1,false,false,"",""]; }; } else { [] call ON_fnc_vkc_reset; }; }; } else { [] call ON_fnc_vkc_reset; }; } else { lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; [] call ON_fnc_vkc_reset; }; }; Link to comment Share on other sites More sharing options...
Gwandoya Posted March 21, 2014 Report Share Posted March 21, 2014 I followed the and did the changes I posted. I wanted to upload my files, but somehow I can't do it here :huh: In the post you quite mixed codes up. server_updateObject.sqf /* [_object,_type] spawn server_updateObject; */ /* Additional */ /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ private ["_object","_type","_objectID","_uid","_lastUpdate","_needUpdate","_object_position","_object_inventory","_object_damage","_isNotOk","_parachuteWest","_firstTime","_object_killed","_object_repair","_isbuildable","_object_vehicleKey","_activatingPlayer","_vehicleClassname","_toKey","_toKeyName","_vehicle_ID","_vehicle_UID"]; _object = _this select 0; if(isNull(_object)) exitWith { diag_log format["Skipping Null Object: %1", _object]; }; _type = _this select 1; _parachuteWest = ((typeOf _object == "ParachuteWest") or (typeOf _object == "ParachuteC")); _isbuildable = (typeOf _object) in dayz_allowedObjects; _isNotOk = false; _firstTime = false; _objectID = _object getVariable ["ObjectID","0"]; _uid = _object getVariable ["ObjectUID","0"]; if ((typeName _objectID != "string") || (typeName _uid != "string")) then { diag_log(format["Non-string Object: ID %1 UID %2", _objectID, _uid]); //force fail _objectID = "0"; _uid = "0"; }; if (!_parachuteWest and !(locked _object)) then { if (_objectID == "0" && _uid == "0") then { _object_position = getPosATL _object; _isNotOk = true; }; }; // do not update if buildable and not ok if (_isNotOk and _isbuildable) exitWith { }; // delete if still not ok if (_isNotOk) exitWith { deleteVehicle _object; diag_log(format["Deleting object %1 with invalid ID at pos [%2,%3,%4]",typeOf _object,_object_position select 0,_object_position select 1, _object_position select 2]); }; _lastUpdate = _object getVariable ["lastUpdate",time]; _needUpdate = _object in needUpdate_objects; // TODO ---------------------- _object_position = { private["_position","_worldspace","_fuel","_key"]; _position = getPosATL _object; _worldspace = [ round(direction _object), _position ]; _fuel = 0; if (_object isKindOf "AllVehicles") then { _fuel = fuel _object; }; _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel]; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; }; _object_inventory = { private["_inventory","_previous","_key"]; _inventory = [ getWeaponCargo _object, getMagazineCargo _object, getBackpackCargo _object ]; _previous = str(_object getVariable["lastInventory",[]]); if (str(_inventory) != _previous) then { _object setVariable["lastInventory",_inventory]; if (_objectID == "0") then { _key = format["CHILD:309:%1:%2:",_uid,_inventory]; } else { _key = format["CHILD:303:%1:%2:",_objectID,_inventory]; }; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; }; }; _object_damage = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; _hitpoints = _object call vehicle_getHitpoints; _damage = damage _object; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _object setHit ["_selection", _hit] } forEach _hitpoints; _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage]; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; _object setVariable ["needUpdate",false,true]; }; _object_killed = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; _hitpoints = _object call vehicle_getHitpoints; //_damage = damage _object; _damage = 1; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _hit = 1; _object setHit ["_selection", _hit] } forEach _hitpoints; if (_objectID == "0") then { _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage]; } else { _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage]; }; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; _object setVariable ["needUpdate",false,true]; }; _object_repair = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; _hitpoints = _object call vehicle_getHitpoints; _damage = damage _object; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _object setHit ["_selection", _hit] } forEach _hitpoints; _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage]; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; _object setVariable ["needUpdate",false,true]; }; _object_vehicleKey = { private["_hitpoints","_array","_hit","_selection","_key","_damage","_fuel","_inventory","_class","_position","_worldspace","_newKey","_newKeyName","_player","_oldVehicleID","_vehicleID","_vehicleUID","_result","_outcome","_retry","_gotcha"]; /* Setting up variables */ _player = _this select 0; _class = _this select 1; _newKey = _this select 2; _newKeyName = _this select 3; _oldVehicleID = _this select 4; _vehicleUID = _this select 5; /* Get Damage of the Vehicle */ _hitpoints = _object call vehicle_getHitpoints; _damage = damage _object; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _object setHit ["_selection", _hit] } forEach _hitpoints; /* Get the Fuel of the Vehicle */ _fuel = 0; if (_object isKindOf "AllVehicles") then { _fuel = fuel _object; }; /* Get the Inventory of the Vehicle */ _inventory = [ getWeaponCargo _object, getMagazineCargo _object, getBackpackCargo _object ]; /* Get the position of the Vehicle */ _position = getPosATL _object; _worldspace = [ round(direction _object), _position ]; /* Delete the current Database entry */ [_oldVehicleID,_vehicleUID,_player] call server_deleteObj; sleep 1; /* Write the new Database entry and LOG the action*/ _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, _damage , _newKey, _worldspace, _inventory, _array, _fuel,_vehicleUID]; _key call server_hiveWrite; diag_log ("HIVE: WRITE: VEHICLE KEY CHANGER: "+ str(_key)); diag_log format["HIVE: WRITE: VEHICLE KEY CHANGER: Vehicle:%1 NewKey:%2 BY %3(%4)", _object, _newKeyName, (name _player), (getPlayerUID _player)]; /* Get the ObjectID of the entry in the Database */ _retry = 0; _gotcha = false; while {!_gotcha && _retry < 10} do { sleep 1; /* Send the request */ _key = format["CHILD:388:%1:",_vehicleUID]; diag_log ("HIVE: READ: VEHICLE KEY CHANGER: "+ str(_key)); _result = _key call server_hiveReadWrite; _outcome = _result select 0; /* We got a answer */ if (_outcome == "PASS") then { _vehicleID = _result select 1; /* Compare with old ObjectID to check if it not was deleted yet */ if (_oldVehicleID == _vehicleID) then { /* Not good lets give it another try */ _gotcha = false; _retry = _retry + 1; } else { /* GOTCHA! */ diag_log("CUSTOM: VEHICLE KEY CHANGER: Selected " + str(_vehicleID)); _gotcha = true; _retry = 11; }; } else { /* Something went wrong on the request give it another try */ diag_log("CUSTOM: VEHICLE KEY CHANGER: trying again to get id for: " + str(_vehicleUID)); _gotcha = false; _retry = _retry + 1; }; }; /* Lock the Vehicle */ _object setVehicleLock "locked"; /* Save the ObjectID to the vehicles variable and make it public */ _object setVariable ["ObjectID", _vehicleID, true]; /* Save the ObjectUID to the vehicles variable and make it public */ _object setVariable ["ObjectUID", _vehicleUID, true]; /* Set the lastUpdate time to current */ _object setVariable ["lastUpdate",time]; /* Set the CharacterID to the new Key so we can access it! */ _object setVariable ["CharacterID", _newKey, true]; /* Some other variables you might need for disallow lift/tow/cargo locked Vehicles and such */ /* Uncomment if you use this */ /* R3F Arty and LOG block lift/tow/cargo locked vehicles*/ _object setVariable ["R3F_LOG_disabled",true,true]; /* =BTC= Logistic block lift locked vehicles*/ _object setVariable ["BTC_Cannot_Lift",true,true]; _object setVariable ["sidegundeployed",0,true]; _object setVariable ["reargundeployed",0,true]; _object call fnc_veh_ResetEH; }; // TODO ---------------------- _object setVariable ["lastUpdate",time,true]; switch (_type) do { case "all": { call _object_position; call _object_inventory; call _object_damage; }; case "position": { if (!(_object in needUpdate_objects)) then { //diag_log format["DEBUG Position: Added to NeedUpdate=%1",_object]; needUpdate_objects set [count needUpdate_objects, _object]; }; }; case "gear": { call _object_inventory; }; case "damage": { if ( (time - _lastUpdate) > 5) then { call _object_damage; } else { if (!(_object in needUpdate_objects)) then { //diag_log format["DEBUG Damage: Added to NeedUpdate=%1",_object]; needUpdate_objects set [count needUpdate_objects, _object]; }; }; }; case "killed": { call _object_killed; }; case "repair": { call _object_damage; }; case "vehiclekey": { _activatingPlayer = _this select 2; _vehicleClassname = _this select 3; _toKey = _this select 4; _toKeyName = _this select 5; _vehicle_ID = _this select 6; _vehicle_UID = _this select 7; [_activatingPlayer, _vehicleClassname, _toKey, _toKeyName, _vehicle_ID, _vehicle_UID] call _object_vehicleKey; }; }; VehicleKeyChanger.sqf /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ /* Setup the private variables */ private ["_magazinesPlayer","_max","_j","_actionArray","_targetVehicle","_targetVehicleID","_targetVehicleUID","_playerKeys","_playerKeysDisplayName","_targetVehicleKeyName","_itemKeyName","_targetVehicleClassname","_targetVehiclePos","_targetVehicleDir","_Price","_claimingPrice"]; /* Remove the Action Menu entry */ player removeAction s_player_copyToKey; s_player_copyToKey = 0; /* Get the array and setup the variables */ _actionArray = _this select 3; _targetVehicle = _actionArray select 0; _targetVehicleID = _targetVehicle getVariable ["ObjectID","0"]; _targetVehicleUID = _targetVehicle getVariable ["ObjectUID","0"]; /* Check if the Vehicle is in the Database, if false exit */ if (_targetVehicleID == "0" && _targetVehicleUID == "0") exitWith {s_player_copyToKey = -1;}; /* Setup more variables */ _playerKeys = _actionArray select 1; _playerKeysDisplayName = _actionArray select 3; _targetVehicleKeyName = _actionArray select 4; _itemKeyName = _actionArray select 5; _Price = _actionArray select 6; _claimingPrice = _actionArray select 7; _targetVehicleClassname = typeOf _targetVehicle; _targetVehiclePos = getPosATL _targetVehicle; _targetVehicleDir = getDir _targetVehicle; /* Setup the Key Names list to select from */ keyNameList = []; for "_i" from 0 to (count _playerKeysDisplayName) -1 do { keyNameList set [(count keyNameList), _playerKeysDisplayName select _i]; }; /* Setup the Key Numbers list to select from */ keyNumberList = []; for "_i" from 0 to (count _playerKeys) -1 do { keyNumberList set [(count keyNumberList), _playerKeys select _i]; }; /* Resetting menu variables*/ keyNameSelect = ""; exitscript = true; snext = false; /* Creating the menu */ copyMenu = { private ["_keyMenu","_keyArray"]; _keyMenu = [["",true], ["Change Vehicle to Key:", [-1], "", -5, [["expression", ""]], "1", "0"]]; for "_i" from (_this select 0) to (_this select 1) do { _keyArray = [format['%1', keyNameList select (_i)], [_i - (_this select 0) + 2], "", -5, [["expression", format ["keyNameSelect = keyNameList select %1; keyNumberSelect = keyNumberList select %1", _i]]], "1", "1"]; _keyMenu set [_i + 2, _keyArray]; }; _keyMenu set [(_this select 1) + 2, ["", [-1], "", -5, [["expression", ""]], "1", "0"]]; if (count keyNameList > (_this select 1)) then { _keyMenu set [(_this select 1) + 3, ["Next", [12], "", -5, [["expression", "snext = true;"]], "1", "1"]]; } else { _keyMenu set [(_this select 1) + 3, ["", [-1], "", -5, [["expression", ""]], "1", "0"]]; }; _keyMenu set [(_this select 1) + 4, ["Exit", [13], "", -5, [["expression", "keyNameSelect = 'exitscript';"]], "1", "1"]]; showCommandingMenu "#USER:_keyMenu"; }; /* Wait for the player to select a Key from the list */ _j = 0; _max = 10; if (_max > 9) then {_max = 10;}; while {keyNameSelect == ""} do { [_j, (_j + _max) min (count keyNameList)] call copyMenu; _j = _j + _max; waitUntil {keyNameSelect != "" || snext}; snext = false; }; /* Player selected a Key, lets make the Vehicle update call */ if (keyNameSelect != "exitscript") then { /* Check again for the needed TinBar or claiming price and remove em from the players inventory */ _magazinesPlayer = magazines player; if (_Price != "0") then { if (_Price in _magazinesPlayer) then { [player, _Price, 1] call BIS_fnc_invRemove; systemChat (format["Keychange costs 1 %1, thanks for your Payment!", _Price]); } else { systemChat (format["Keychange costs 1 %1, you had it and tried to trick the system - Keychange for this Vehicle disabled!", Price]); _targetVehicle setVariable ["VKC_disabled", 1, true]; s_player_copyToKey = -1; breakOut "exit"; }; }; if (_claimingPrice != "0") then { if (_claimingPrice in _magazinesPlayer) then { [player, _claimingPrice, 1] call BIS_fnc_invRemove; systemChat (format["Claiming Vehicle costs 1 %1, thanks for your Payment!", _claimingPrice]); } else { systemChat (format["Claiming Vehicle costs 1 %1, you had it and tried to trick the system - Claiming for this Vehicle disabled!", Price]); _targetVehicle setVariable ["VKC_claiming_disabled", 1, true]; s_player_copyToKey = -1; breakOut "exit"; }; }; /* We got the Money lets do our Job */ /* Lock the vehicle */ _targetVehicle setVehicleLock "LOCKED"; /* The super duper OneForAllAnimation... */ player playActionNow "Medic"; /* Remove the Key from the Toolbelt of the player and put it in the Backpack - No Backpack and the Key gets lost */ if (_itemKeyName != "0") then { if (!isNull (unitBackpack player)) then { [player, _itemKeyName, 1] call BIS_fnc_invRemove; (unitBackpack (vehicle player)) addWeaponCargoGlobal [_itemKeyName, 1]; systemChat (format["%1 has been moved to your Backpack", _targetVehicleKeyName]); }; }; /* Giving unique UID for claimed vehicles */ if (_targetVehicleUID=="0") then { _targetVehicleUID = _targetVehicle call dayz_objectUID_vkc; _targetVehicle setVariable ["ObjectUID",_targetVehicleUID,true]; }; /* This calls the custom update function which we put it in server_updateObject.sqf */ PVDZE_veh_Update = [_targetVehicle, "vehiclekey", player, _targetVehicleClassname, keyNumberSelect, keyNameSelect, _targetVehicleID, _targetVehicleUID]; publicVariableServer "PVDZE_veh_Update"; /* Inform the player about the success and tell him to check the Key */ systemChat (format["Changed Vehicle Key to %1", keyNameSelect]); if (_targetVehicleKeyName != "0") then { systemChat (format["Please check Vehicle function with %1 before you throw away %2!", keyNameSelect, _targetVehicleKeyName]); }; }; /* Reset the action menu variable for a new run */ s_player_copyToKey = -1; /**************************************/ /* That's it, hope you enjoy this Mod */ /* */ /* Yours sincerly, */ /* Otter */ /**************************************/ VehicleKeyChanger_init.sqf /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ private ["_itemsPlayer","_magazinesPlayer","_temp_Keys","_temp_keysDisplayName","_temp_keysDisplayNameParse","_key_colors","_ownerKeyId","_carKey","_hasKey","_cTarget","_keyName","_carKeyName","_targetVehicleKey","_temp_keysParse"]; ///////////////////////////////////////////////// ///////////////////////////////////////////////// // Edit these settings to fit your needs/likes // ///////////////////////////////////////////////// ///////////////////////////////////////////////// /// Claim Vehicles that does not yet need Key /// ///////// 0 = Not allowed | 1 = Allowed ///////// vkc_claiming = 1; ///////////////////////////////////////////////// //////// Claim Vehicles costs this Item ///////// /// Any Item can be used here, some examples: /// //// ItemTinBar, ItemSilverBar, ItemGoldBar, //// ////// ItemSilverBar10oz, ItemGoldBar10oz, ////// ///// ItemBriefcase20oz, ItemBriefcase100oz ///// //////// set to "0" to disable the costs //////// vkc_claimingPrice = "ItemGoldBar10oz"; ///////////////////////////////////////////////// ////////// Change Key costs this Item// ///////// ////////////// see above examples /////////////// //////// set to "0" to disable the costs //////// vkc_Price = "ItemGoldBar"; ///////////////////////////////////////////////// /////// Need KeyKit to use this function //////// ////////// 0 = Not needed | 1 = Needed ////////// vkc_needKeykit = 1; ///////////////////////////////////////////////// ///////////////////////////////////////////////// /////////////// DONT EDIT BELOW ! /////////////// ///////////////////////////////////////////////// /* Reset variables function */ ON_fnc_vkc_reset = { _cTarget = objNull; _itemsPlayer = []; _temp_keys = []; _carKey = objNull; _hasKey = false; _temp_keysDisplayName = []; _temp_keysDisplayNameParse = []; _temp_keysParse = []; _targetVehicleKey = objNull; _carKeyName = ""; player removeAction s_player_copyToKey; s_player_copyToKey = -1; }; dayz_objectUID_vkc = { private["_position","_dir","_key","_object"]; _object = _this; _position = getPosATL _object; _dir = direction _object; _key = [_dir,_position] call dayz_objectUID2_vkc; _key }; dayz_objectUID2_vkc = { private["_position","_dir","_key"]; _dir = _this select 0; _key = ""; _position = _this select 1; { _x = _x * 10; if ( _x < 0 ) then { _x = _x * -10 }; _key = _key + str(round(_x)); } forEach _position; _key = _key + str(round(_dir)); _key }; /* Wait for player full ingame so we can access the action-menu */ waitUntil {!isNil "dayz_animalCheck"}; s_player_copyToKey=-1; lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; /* Start the loop check */ while{true} do { sleep 3; if (!isNull cursorTarget && speed player <= 1 && (vehicle player) == player && !isEngineOn cursorTarget && (cursorTarget isKindOf "Motorcycle" || cursorTarget isKindOf "Car" || cursorTarget isKindOf "Air" || cursorTarget isKindOf "Ship") && (cursorTarget distance player) <= 10 && cursorTarget getVariable ["VKC_disabled", 0] == 0 && cursorTarget getVariable ["VKC_claiming_disabled",0] == 0) then { _cTarget = cursorTarget; _itemsPlayer = items player; _magazinesPlayer = magazines player; if ((lastKeyChangeCursorTarget select 0) != _cTarget) then { if (s_player_copyToKey >= 0) then { player removeAction s_player_copyToKey; s_player_copyToKey = -1; }; }; lastKeyChangeCursorTarget set [0,_cTarget]; _carKey = _cTarget getVariable ["CharacterID","0"]; if (("ItemKeyKit" in _itemsPlayer || vkc_needKeykit == 0) && ((_carKey == "0" && vkc_claiming == 1 && (vkc_claimingPrice == "0" || vkc_claimingPrice in _magazinesPlayer)) || _carKey != "0") && (vkc_Price == "0" || vkc_Price in _magazinesPlayer)) then { if (_carKey == "0") then { _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_keys set [count _temp_keys,str(_ownerKeyId)]; }; } forEach _itemsPlayer; if ((count _temp_keys) > 0) then { if (s_player_copyToKey < 0) then { lastKeyChangeCursorTarget set [0,_cTarget]; s_player_copyToKey = player addAction [("<t color=""#c03636"">" + ("Claim Vehicle") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, "0", _temp_keysDisplayName, "0", "0", vkc_Price, vkc_claimingPrice],-1,false,false,"",""]; }; } else { [] call ON_fnc_vkc_reset; }; } else { _temp_keys = []; _temp_keysDisplayName = []; _temp_keysDisplayNameParse = []; _temp_keysParse = []; _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)]; _temp_keysParse set [_ownerKeyId, _x]; }; } forEach _itemsPlayer; _hasKey = _carKey in _temp_keys; if (_hasKey && (count _temp_keys) > 1) then { _carKeyName = (_temp_keysDisplayNameParse select (parseNumber _carKey)); _targetVehicleKey = (_temp_keysParse select (parseNumber _carKey)); _temp_keys = _temp_keys - [_carKey]; _temp_keysDisplayName = _temp_keysDisplayName - [_carKeyName]; if (s_player_copyToKey < 0) then { lastKeyChangeCursorTarget set [0,_cTarget]; s_player_copyToKey = player addAction [("<t color=""#c03636"">" + ("Change Vehicle Key") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, _carKey, _temp_keysDisplayName, _carKeyName, _targetVehicleKey, vkc_Price, "0"],-1,false,false,"",""]; }; } else { [] call ON_fnc_vkc_reset; }; }; } else { [] call ON_fnc_vkc_reset; }; } else { lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; [] call ON_fnc_vkc_reset; }; }; koolaidman04 1 Link to comment Share on other sites More sharing options...
Affraid Posted March 21, 2014 Report Share Posted March 21, 2014 I followed the and did the changes I posted. I wanted to upload my files, but somehow I can't do it here :huh: In the post you quite mixed codes up. server_updateObject.sqf /* [_object,_type] spawn server_updateObject; */ /* Additional */ /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ private ["_object","_type","_objectID","_uid","_lastUpdate","_needUpdate","_object_position","_object_inventory","_object_damage","_isNotOk","_parachuteWest","_firstTime","_object_killed","_object_repair","_isbuildable","_object_vehicleKey","_activatingPlayer","_vehicleClassname","_toKey","_toKeyName","_vehicle_ID","_vehicle_UID"]; _object = _this select 0; if(isNull(_object)) exitWith { diag_log format["Skipping Null Object: %1", _object]; }; _type = _this select 1; _parachuteWest = ((typeOf _object == "ParachuteWest") or (typeOf _object == "ParachuteC")); _isbuildable = (typeOf _object) in dayz_allowedObjects; _isNotOk = false; _firstTime = false; _objectID = _object getVariable ["ObjectID","0"]; _uid = _object getVariable ["ObjectUID","0"]; if ((typeName _objectID != "string") || (typeName _uid != "string")) then { diag_log(format["Non-string Object: ID %1 UID %2", _objectID, _uid]); //force fail _objectID = "0"; _uid = "0"; }; if (!_parachuteWest and !(locked _object)) then { if (_objectID == "0" && _uid == "0") then { _object_position = getPosATL _object; _isNotOk = true; }; }; // do not update if buildable and not ok if (_isNotOk and _isbuildable) exitWith { }; // delete if still not ok if (_isNotOk) exitWith { deleteVehicle _object; diag_log(format["Deleting object %1 with invalid ID at pos [%2,%3,%4]",typeOf _object,_object_position select 0,_object_position select 1, _object_position select 2]); }; _lastUpdate = _object getVariable ["lastUpdate",time]; _needUpdate = _object in needUpdate_objects; // TODO ---------------------- _object_position = { private["_position","_worldspace","_fuel","_key"]; _position = getPosATL _object; _worldspace = [ round(direction _object), _position ]; _fuel = 0; if (_object isKindOf "AllVehicles") then { _fuel = fuel _object; }; _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel]; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; }; _object_inventory = { private["_inventory","_previous","_key"]; _inventory = [ getWeaponCargo _object, getMagazineCargo _object, getBackpackCargo _object ]; _previous = str(_object getVariable["lastInventory",[]]); if (str(_inventory) != _previous) then { _object setVariable["lastInventory",_inventory]; if (_objectID == "0") then { _key = format["CHILD:309:%1:%2:",_uid,_inventory]; } else { _key = format["CHILD:303:%1:%2:",_objectID,_inventory]; }; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; }; }; _object_damage = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; _hitpoints = _object call vehicle_getHitpoints; _damage = damage _object; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _object setHit ["_selection", _hit] } forEach _hitpoints; _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage]; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; _object setVariable ["needUpdate",false,true]; }; _object_killed = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; _hitpoints = _object call vehicle_getHitpoints; //_damage = damage _object; _damage = 1; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _hit = 1; _object setHit ["_selection", _hit] } forEach _hitpoints; if (_objectID == "0") then { _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage]; } else { _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage]; }; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; _object setVariable ["needUpdate",false,true]; }; _object_repair = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; _hitpoints = _object call vehicle_getHitpoints; _damage = damage _object; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _object setHit ["_selection", _hit] } forEach _hitpoints; _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage]; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; _object setVariable ["needUpdate",false,true]; }; _object_vehicleKey = { private["_hitpoints","_array","_hit","_selection","_key","_damage","_fuel","_inventory","_class","_position","_worldspace","_newKey","_newKeyName","_player","_oldVehicleID","_vehicleID","_vehicleUID","_result","_outcome","_retry","_gotcha"]; /* Setting up variables */ _player = _this select 0; _class = _this select 1; _newKey = _this select 2; _newKeyName = _this select 3; _oldVehicleID = _this select 4; _vehicleUID = _this select 5; /* Get Damage of the Vehicle */ _hitpoints = _object call vehicle_getHitpoints; _damage = damage _object; _array = []; { _hit = [_object,_x] call object_getHit; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name"); if (_hit > 0) then {_array set [count _array,[_selection,_hit]]}; _object setHit ["_selection", _hit] } forEach _hitpoints; /* Get the Fuel of the Vehicle */ _fuel = 0; if (_object isKindOf "AllVehicles") then { _fuel = fuel _object; }; /* Get the Inventory of the Vehicle */ _inventory = [ getWeaponCargo _object, getMagazineCargo _object, getBackpackCargo _object ]; /* Get the position of the Vehicle */ _position = getPosATL _object; _worldspace = [ round(direction _object), _position ]; /* Delete the current Database entry */ [_oldVehicleID,_vehicleUID,_player] call server_deleteObj; sleep 1; /* Write the new Database entry and LOG the action*/ _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, _damage , _newKey, _worldspace, _inventory, _array, _fuel,_vehicleUID]; _key call server_hiveWrite; diag_log ("HIVE: WRITE: VEHICLE KEY CHANGER: "+ str(_key)); diag_log format["HIVE: WRITE: VEHICLE KEY CHANGER: Vehicle:%1 NewKey:%2 BY %3(%4)", _object, _newKeyName, (name _player), (getPlayerUID _player)]; /* Get the ObjectID of the entry in the Database */ _retry = 0; _gotcha = false; while {!_gotcha && _retry < 10} do { sleep 1; /* Send the request */ _key = format["CHILD:388:%1:",_vehicleUID]; diag_log ("HIVE: READ: VEHICLE KEY CHANGER: "+ str(_key)); _result = _key call server_hiveReadWrite; _outcome = _result select 0; /* We got a answer */ if (_outcome == "PASS") then { _vehicleID = _result select 1; /* Compare with old ObjectID to check if it not was deleted yet */ if (_oldVehicleID == _vehicleID) then { /* Not good lets give it another try */ _gotcha = false; _retry = _retry + 1; } else { /* GOTCHA! */ diag_log("CUSTOM: VEHICLE KEY CHANGER: Selected " + str(_vehicleID)); _gotcha = true; _retry = 11; }; } else { /* Something went wrong on the request give it another try */ diag_log("CUSTOM: VEHICLE KEY CHANGER: trying again to get id for: " + str(_vehicleUID)); _gotcha = false; _retry = _retry + 1; }; }; /* Lock the Vehicle */ _object setVehicleLock "locked"; /* Save the ObjectID to the vehicles variable and make it public */ _object setVariable ["ObjectID", _vehicleID, true]; /* Save the ObjectUID to the vehicles variable and make it public */ _object setVariable ["ObjectUID", _vehicleUID, true]; /* Set the lastUpdate time to current */ _object setVariable ["lastUpdate",time]; /* Set the CharacterID to the new Key so we can access it! */ _object setVariable ["CharacterID", _newKey, true]; /* Some other variables you might need for disallow lift/tow/cargo locked Vehicles and such */ /* Uncomment if you use this */ /* R3F Arty and LOG block lift/tow/cargo locked vehicles*/ _object setVariable ["R3F_LOG_disabled",true,true]; /* =BTC= Logistic block lift locked vehicles*/ _object setVariable ["BTC_Cannot_Lift",true,true]; _object setVariable ["sidegundeployed",0,true]; _object setVariable ["reargundeployed",0,true]; _object call fnc_veh_ResetEH; }; // TODO ---------------------- _object setVariable ["lastUpdate",time,true]; switch (_type) do { case "all": { call _object_position; call _object_inventory; call _object_damage; }; case "position": { if (!(_object in needUpdate_objects)) then { //diag_log format["DEBUG Position: Added to NeedUpdate=%1",_object]; needUpdate_objects set [count needUpdate_objects, _object]; }; }; case "gear": { call _object_inventory; }; case "damage": { if ( (time - _lastUpdate) > 5) then { call _object_damage; } else { if (!(_object in needUpdate_objects)) then { //diag_log format["DEBUG Damage: Added to NeedUpdate=%1",_object]; needUpdate_objects set [count needUpdate_objects, _object]; }; }; }; case "killed": { call _object_killed; }; case "repair": { call _object_damage; }; case "vehiclekey": { _activatingPlayer = _this select 2; _vehicleClassname = _this select 3; _toKey = _this select 4; _toKeyName = _this select 5; _vehicle_ID = _this select 6; _vehicle_UID = _this select 7; [_activatingPlayer, _vehicleClassname, _toKey, _toKeyName, _vehicle_ID, _vehicle_UID] call _object_vehicleKey; }; }; VehicleKeyChanger.sqf /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ /* Setup the private variables */ private ["_magazinesPlayer","_max","_j","_actionArray","_targetVehicle","_targetVehicleID","_targetVehicleUID","_playerKeys","_playerKeysDisplayName","_targetVehicleKeyName","_itemKeyName","_targetVehicleClassname","_targetVehiclePos","_targetVehicleDir","_Price","_claimingPrice"]; /* Remove the Action Menu entry */ player removeAction s_player_copyToKey; s_player_copyToKey = 0; /* Get the array and setup the variables */ _actionArray = _this select 3; _targetVehicle = _actionArray select 0; _targetVehicleID = _targetVehicle getVariable ["ObjectID","0"]; _targetVehicleUID = _targetVehicle getVariable ["ObjectUID","0"]; /* Check if the Vehicle is in the Database, if false exit */ if (_targetVehicleID == "0" && _targetVehicleUID == "0") exitWith {s_player_copyToKey = -1;}; /* Setup more variables */ _playerKeys = _actionArray select 1; _playerKeysDisplayName = _actionArray select 3; _targetVehicleKeyName = _actionArray select 4; _itemKeyName = _actionArray select 5; _Price = _actionArray select 6; _claimingPrice = _actionArray select 7; _targetVehicleClassname = typeOf _targetVehicle; _targetVehiclePos = getPosATL _targetVehicle; _targetVehicleDir = getDir _targetVehicle; /* Setup the Key Names list to select from */ keyNameList = []; for "_i" from 0 to (count _playerKeysDisplayName) -1 do { keyNameList set [(count keyNameList), _playerKeysDisplayName select _i]; }; /* Setup the Key Numbers list to select from */ keyNumberList = []; for "_i" from 0 to (count _playerKeys) -1 do { keyNumberList set [(count keyNumberList), _playerKeys select _i]; }; /* Resetting menu variables*/ keyNameSelect = ""; exitscript = true; snext = false; /* Creating the menu */ copyMenu = { private ["_keyMenu","_keyArray"]; _keyMenu = [["",true], ["Change Vehicle to Key:", [-1], "", -5, [["expression", ""]], "1", "0"]]; for "_i" from (_this select 0) to (_this select 1) do { _keyArray = [format['%1', keyNameList select (_i)], [_i - (_this select 0) + 2], "", -5, [["expression", format ["keyNameSelect = keyNameList select %1; keyNumberSelect = keyNumberList select %1", _i]]], "1", "1"]; _keyMenu set [_i + 2, _keyArray]; }; _keyMenu set [(_this select 1) + 2, ["", [-1], "", -5, [["expression", ""]], "1", "0"]]; if (count keyNameList > (_this select 1)) then { _keyMenu set [(_this select 1) + 3, ["Next", [12], "", -5, [["expression", "snext = true;"]], "1", "1"]]; } else { _keyMenu set [(_this select 1) + 3, ["", [-1], "", -5, [["expression", ""]], "1", "0"]]; }; _keyMenu set [(_this select 1) + 4, ["Exit", [13], "", -5, [["expression", "keyNameSelect = 'exitscript';"]], "1", "1"]]; showCommandingMenu "#USER:_keyMenu"; }; /* Wait for the player to select a Key from the list */ _j = 0; _max = 10; if (_max > 9) then {_max = 10;}; while {keyNameSelect == ""} do { [_j, (_j + _max) min (count keyNameList)] call copyMenu; _j = _j + _max; waitUntil {keyNameSelect != "" || snext}; snext = false; }; /* Player selected a Key, lets make the Vehicle update call */ if (keyNameSelect != "exitscript") then { /* Check again for the needed TinBar or claiming price and remove em from the players inventory */ _magazinesPlayer = magazines player; if (_Price != "0") then { if (_Price in _magazinesPlayer) then { [player, _Price, 1] call BIS_fnc_invRemove; systemChat (format["Keychange costs 1 %1, thanks for your Payment!", _Price]); } else { systemChat (format["Keychange costs 1 %1, you had it and tried to trick the system - Keychange for this Vehicle disabled!", Price]); _targetVehicle setVariable ["VKC_disabled", 1, true]; s_player_copyToKey = -1; breakOut "exit"; }; }; if (_claimingPrice != "0") then { if (_claimingPrice in _magazinesPlayer) then { [player, _claimingPrice, 1] call BIS_fnc_invRemove; systemChat (format["Claiming Vehicle costs 1 %1, thanks for your Payment!", _claimingPrice]); } else { systemChat (format["Claiming Vehicle costs 1 %1, you had it and tried to trick the system - Claiming for this Vehicle disabled!", Price]); _targetVehicle setVariable ["VKC_claiming_disabled", 1, true]; s_player_copyToKey = -1; breakOut "exit"; }; }; /* We got the Money lets do our Job */ /* Lock the vehicle */ _targetVehicle setVehicleLock "LOCKED"; /* The super duper OneForAllAnimation... */ player playActionNow "Medic"; /* Remove the Key from the Toolbelt of the player and put it in the Backpack - No Backpack and the Key gets lost */ if (_itemKeyName != "0") then { if (!isNull (unitBackpack player)) then { [player, _itemKeyName, 1] call BIS_fnc_invRemove; (unitBackpack (vehicle player)) addWeaponCargoGlobal [_itemKeyName, 1]; systemChat (format["%1 has been moved to your Backpack", _targetVehicleKeyName]); }; }; /* Giving unique UID for claimed vehicles */ if (_targetVehicleUID=="0") then { _targetVehicleUID = _targetVehicle call dayz_objectUID_vkc; _targetVehicle setVariable ["ObjectUID",_targetVehicleUID,true]; }; /* This calls the custom update function which we put it in server_updateObject.sqf */ PVDZE_veh_Update = [_targetVehicle, "vehiclekey", player, _targetVehicleClassname, keyNumberSelect, keyNameSelect, _targetVehicleID, _targetVehicleUID]; publicVariableServer "PVDZE_veh_Update"; /* Inform the player about the success and tell him to check the Key */ systemChat (format["Changed Vehicle Key to %1", keyNameSelect]); if (_targetVehicleKeyName != "0") then { systemChat (format["Please check Vehicle function with %1 before you throw away %2!", keyNameSelect, _targetVehicleKeyName]); }; }; /* Reset the action menu variable for a new run */ s_player_copyToKey = -1; /**************************************/ /* That's it, hope you enjoy this Mod */ /* */ /* Yours sincerly, */ /* Otter */ /**************************************/ VehicleKeyChanger_init.sqf /***********************************/ /* Vehicle Key Changer v1.3 */ /* Written by OtterNas3 */ /* January, 11, 2014 */ /* Last update: 02/20/2014 */ /***********************************/ private ["_itemsPlayer","_magazinesPlayer","_temp_Keys","_temp_keysDisplayName","_temp_keysDisplayNameParse","_key_colors","_ownerKeyId","_carKey","_hasKey","_cTarget","_keyName","_carKeyName","_targetVehicleKey","_temp_keysParse"]; ///////////////////////////////////////////////// ///////////////////////////////////////////////// // Edit these settings to fit your needs/likes // ///////////////////////////////////////////////// ///////////////////////////////////////////////// /// Claim Vehicles that does not yet need Key /// ///////// 0 = Not allowed | 1 = Allowed ///////// vkc_claiming = 1; ///////////////////////////////////////////////// //////// Claim Vehicles costs this Item ///////// /// Any Item can be used here, some examples: /// //// ItemTinBar, ItemSilverBar, ItemGoldBar, //// ////// ItemSilverBar10oz, ItemGoldBar10oz, ////// ///// ItemBriefcase20oz, ItemBriefcase100oz ///// //////// set to "0" to disable the costs //////// vkc_claimingPrice = "ItemGoldBar10oz"; ///////////////////////////////////////////////// ////////// Change Key costs this Item// ///////// ////////////// see above examples /////////////// //////// set to "0" to disable the costs //////// vkc_Price = "ItemGoldBar"; ///////////////////////////////////////////////// /////// Need KeyKit to use this function //////// ////////// 0 = Not needed | 1 = Needed ////////// vkc_needKeykit = 1; ///////////////////////////////////////////////// ///////////////////////////////////////////////// /////////////// DONT EDIT BELOW ! /////////////// ///////////////////////////////////////////////// /* Reset variables function */ ON_fnc_vkc_reset = { _cTarget = objNull; _itemsPlayer = []; _temp_keys = []; _carKey = objNull; _hasKey = false; _temp_keysDisplayName = []; _temp_keysDisplayNameParse = []; _temp_keysParse = []; _targetVehicleKey = objNull; _carKeyName = ""; player removeAction s_player_copyToKey; s_player_copyToKey = -1; }; dayz_objectUID_vkc = { private["_position","_dir","_key","_object"]; _object = _this; _position = getPosATL _object; _dir = direction _object; _key = [_dir,_position] call dayz_objectUID2_vkc; _key }; dayz_objectUID2_vkc = { private["_position","_dir","_key"]; _dir = _this select 0; _key = ""; _position = _this select 1; { _x = _x * 10; if ( _x < 0 ) then { _x = _x * -10 }; _key = _key + str(round(_x)); } forEach _position; _key = _key + str(round(_dir)); _key }; /* Wait for player full ingame so we can access the action-menu */ waitUntil {!isNil "dayz_animalCheck"}; s_player_copyToKey=-1; lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; /* Start the loop check */ while{true} do { sleep 3; if (!isNull cursorTarget && speed player <= 1 && (vehicle player) == player && !isEngineOn cursorTarget && (cursorTarget isKindOf "Motorcycle" || cursorTarget isKindOf "Car" || cursorTarget isKindOf "Air" || cursorTarget isKindOf "Ship") && (cursorTarget distance player) <= 10 && cursorTarget getVariable ["VKC_disabled", 0] == 0 && cursorTarget getVariable ["VKC_claiming_disabled",0] == 0) then { _cTarget = cursorTarget; _itemsPlayer = items player; _magazinesPlayer = magazines player; if ((lastKeyChangeCursorTarget select 0) != _cTarget) then { if (s_player_copyToKey >= 0) then { player removeAction s_player_copyToKey; s_player_copyToKey = -1; }; }; lastKeyChangeCursorTarget set [0,_cTarget]; _carKey = _cTarget getVariable ["CharacterID","0"]; if (("ItemKeyKit" in _itemsPlayer || vkc_needKeykit == 0) && ((_carKey == "0" && vkc_claiming == 1 && (vkc_claimingPrice == "0" || vkc_claimingPrice in _magazinesPlayer)) || _carKey != "0") && (vkc_Price == "0" || vkc_Price in _magazinesPlayer)) then { if (_carKey == "0") then { _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_keys set [count _temp_keys,str(_ownerKeyId)]; }; } forEach _itemsPlayer; if ((count _temp_keys) > 0) then { if (s_player_copyToKey < 0) then { lastKeyChangeCursorTarget set [0,_cTarget]; s_player_copyToKey = player addAction [("<t color=""#c03636"">" + ("Claim Vehicle") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, "0", _temp_keysDisplayName, "0", "0", vkc_Price, vkc_claimingPrice],-1,false,false,"",""]; }; } else { [] call ON_fnc_vkc_reset; }; } else { _temp_keys = []; _temp_keysDisplayName = []; _temp_keysDisplayNameParse = []; _temp_keysParse = []; _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)]; _temp_keysParse set [_ownerKeyId, _x]; }; } forEach _itemsPlayer; _hasKey = _carKey in _temp_keys; if (_hasKey && (count _temp_keys) > 1) then { _carKeyName = (_temp_keysDisplayNameParse select (parseNumber _carKey)); _targetVehicleKey = (_temp_keysParse select (parseNumber _carKey)); _temp_keys = _temp_keys - [_carKey]; _temp_keysDisplayName = _temp_keysDisplayName - [_carKeyName]; if (s_player_copyToKey < 0) then { lastKeyChangeCursorTarget set [0,_cTarget]; s_player_copyToKey = player addAction [("<t color=""#c03636"">" + ("Change Vehicle Key") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[_cTarget, _temp_keys, _carKey, _temp_keysDisplayName, _carKeyName, _targetVehicleKey, vkc_Price, "0"],-1,false,false,"",""]; }; } else { [] call ON_fnc_vkc_reset; }; }; } else { [] call ON_fnc_vkc_reset; }; } else { lastKeyChangeCursorTarget = [objNull,objNull,objNull,objNull,objNull]; [] call ON_fnc_vkc_reset; }; }; And you got the files to work? I'll givethem a try . Thank You Link to comment Share on other sites More sharing options...
Vindomire Posted March 22, 2014 Report Share Posted March 22, 2014 The fix posted solved all the problems, thank you. Link to comment Share on other sites More sharing options...
koolaidman04 Posted March 24, 2014 Report Share Posted March 24, 2014 I will second the thanks to both Otter and Gwandoya. Link to comment Share on other sites More sharing options...
AnnoKDFW Posted March 25, 2014 Report Share Posted March 25, 2014 I have a big problem. I install the Script like the tutorial and change it like one of the last posts. Now i have the option to change the key. But since i install the script i cant unlock or lock a vehicle. Need pls fast help. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now