Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. _object_vehicleKey = {
  2.     private ["_hit","_selection","_fuel","_gotcha","_retry","_vehicleID","_key","_result","_outcome","_player","_class","_newKey","_newKeyName","_oldVehicleID","_oldVehicleUID","_hitpoints","_damage","_array","_inventory","_vehicleUID","_position","_dir","_worldspace"];
  3.     
  4.     /* Setting up variables */
  5.     _player = _this select 0;
  6.     _class = _this select 1;
  7.     _newKey = _this select 2;
  8.     _newKeyName = _this select 3;
  9.     _oldVehicleID = _this select 4;
  10.     _oldVehicleUID = _this select 5;
  11.  
  12.     /* Get Damage of the Vehicle */
  13.     _hitpoints = _object call vehicle_getHitpoints;
  14.     _damage = damage _object;
  15.     _array = [];
  16.     {
  17.         _hit = [_object,_x] call object_getHit;
  18.         _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  19.         if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  20.         _object setHit ["_selection", _hit];
  21.     } forEach _hitpoints;
  22.     
  23.     /* Get the Fuel of the Vehicle */
  24.     _fuel = 0;
  25.     if (_object isKindOf "AllVehicles") then {
  26.         _fuel = fuel _object;
  27.     };
  28.     
  29.     /* Get the Inventory of the Vehicle */
  30.     _inventory = [
  31.         getWeaponCargo _object,
  32.         getMagazineCargo _object,
  33.         getBackpackCargo _object
  34.     ];
  35.     
  36.     /* Get the position of the Vehicle */
  37.     _position     = getPosASL _object;
  38.     if !(surfaceIsWater _position) then {
  39.         _position =  ASLToATL _position;
  40.     };
  41.     _dir         = getDir _object;
  42.     _worldspace = [_dir,_position];
  43.  
  44.     /* Delete the current Database entry */
  45.     [_oldVehicleID,_oldVehicleUID,_player] call server_deleteObj;
  46.     sleep 1;
  47.     
  48.     /* Generate a new UID */
  49.     _vehicleUID = _worldspace call dayz_objectUID3;
  50.  
  51.     /* Write the new Database entry and LOG the action*/
  52.     _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, _damage , _newKey, _worldspace, _inventory, _array, _fuel,_vehicleUID];
  53.     _key call server_hiveWrite;
  54.     diag_log ("HIVE: WRITE: VEHICLE KEY CHANGER: "+ str(_key)); 
  55.     diag_log format["HIVE: WRITE: VEHICLE KEY CHANGER: Vehicle:%1 NewKey:%2 BY %3(%4)", _object, _newKeyName, (name _player), (getPlayerUID _player)];
  56.  
  57.     /* Get the ObjectID of the entry in the Database */
  58.     _retry = 0;
  59.     _gotcha = false;
  60.     while {!_gotcha && _retry < 10} do {
  61.         sleep 1;
  62.         
  63.         /* Send the request */
  64.         _key = format["CHILD:388:%1:",_vehicleUID];
  65.         diag_log ("HIVE: READ: VEHICLE KEY CHANGER: "+ str(_key));
  66.         _result = _key call server_hiveReadWrite;
  67.         _outcome = _result select 0;
  68.         
  69.         /* We got a answer */
  70.         if (_outcome == "PASS") then {
  71.             _vehicleID = _result select 1;
  72.             
  73.             /* Compare with old ObjectID to check if it not was deleted yet */
  74.             if (_oldVehicleID == _vehicleID) then {
  75.                 /* Not good lets give it another try */
  76.                 _gotcha = false;
  77.                 _retry = _retry + 1;
  78.                 if (_retry > 8) then {
  79.                     PVDZE_vkc_Success = false;
  80.                     (owner _player) publicVariableClient "PVDZE_vkc_Success";
  81.                 };
  82.             } else {
  83.                 /* GOTCHA! */
  84.                 diag_log("CUSTOM: VEHICLE KEY CHANGER: Selected " + str(_vehicleID));
  85.                 _gotcha = true;
  86.                 _retry = 11;
  87.  
  88.                 _object setVariable ["VKC_disabled", 1,true];
  89.                 _object setVariable ["VKC_claiming_disabled", 1,true];
  90.  
  91.                 [_object] spawn {
  92.                     private ["_veh"];
  93.                     _veh = _this select 0;
  94.  
  95.                     sleep 30;
  96.                     _veh setVariable ["VKC_disabled", 0,true];
  97.                     _veh setVariable ["VKC_claiming_disabled", 0,true];
  98.                 };
  99.  
  100.                 PVDZE_vkc_Success = true;
  101.                 (owner _player) publicVariableClient "PVDZE_vkc_Success";
  102.  
  103.                 /* Lock the Vehicle */
  104.                 _object setVehicleLock "locked";
  105.     
  106.                 /* Save the ObjectID and ObjectUID to the vehicles variable and make it public */
  107.                 _object setVariable ["ObjectID", _vehicleID, true];
  108.                 _object setVariable ["ObjectUID", _vehicleUID, true];
  109.     
  110.                 /* Set the lastUpdate time to current */
  111.                 _object setVariable ["lastUpdate",time,true];
  112.     
  113.                 /* Set the CharacterID to the new Key so we can access it! */
  114.                 _object setVariable ["CharacterID", _newKey, true];
  115.     
  116.                 /* Some other variables you might need for disallow lift/tow/cargo locked Vehicles and such */
  117.                 /* Uncomment if you use this */
  118.     
  119.                 /* R3F Arty and LOG block lift/tow/cargo locked vehicles*/
  120.                 _object setVariable ["R3F_LOG_disabled",true,true];
  121.  
  122.                 /* =BTC= Logistic block lift locked vehicles*/
  123.                 _object setVariable ["BTC_Cannot_Lift",true,true];
  124.             };
  125.         } else {
  126.             /* Something went wrong on the request give it another try */
  127.             diag_log("CUSTOM: VEHICLE KEY CHANGER: trying again to get id for: " + str(_vehicleUID));
  128.             _gotcha = false;
  129.             _retry = _retry + 1;
  130.         };
  131.     };
  132. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement