Advertisement
Guest User

server_publishVehicle3.sqf

a guest
Aug 8th, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.32 KB | None | 0 0
  1. private ["_activatingPlayer","_isOK","_object","_worldspace","_location","_dir","_class","_uid","_key","_keySelected","_characterID","_donotusekey"];
  2. //PVDZE_veh_Publish2 = [_veh,[_dir,_location],_part_out,false,_keySelected,_activatingPlayer];
  3. _object =       _this select 0;
  4. _worldspace =   _this select 1;
  5. _class =        _this select 2;
  6. _donotusekey =  _this select 3;
  7. _keySelected =  _this select 4;
  8. _activatingPlayer =  _this select 5;
  9. _characterID = _keySelected;
  10.  
  11. _isOK = isClass(configFile >> "CfgVehicles" >> _class);
  12. if(!_isOK || isNull _object) exitWith { diag_log ("HIVE-pv3: Vehicle does not exist: "+ str(_class)); };
  13.  
  14. diag_log ("PUBLISH: Attempt " + str(_object));
  15. _dir =      _worldspace select 0;
  16. _location = _worldspace select 1;
  17.  
  18. //Generate UID test using time
  19. _uid = _worldspace call dayz_objectUID3;
  20.  
  21. //Send request
  22. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, 0 , _characterID, _worldspace, [], [], 1,_uid];
  23. diag_log ("HIVE: WRITE: "+ str(_key));
  24. _key call server_hiveWrite;
  25.  
  26. // Switched to spawn so we can wait a bit for the ID
  27. [_object,_uid,_characterID,_class,_dir,_location,_donotusekey,_activatingPlayer] spawn {
  28.    private ["_object","_uid","_characterID","_done","_retry","_key","_result","_outcome","_oid","_class","_location","_donotusekey","_activatingPlayer","_countr","_objectID","_objectUID","_dir","_newobject","_weapons","_magazines","_backpacks","_objWpnTypes","_objWpnQty"];
  29.  
  30.    _object = _this select 0;
  31.    _objectID    = _object getVariable ["ObjectID","0"];
  32.    _objectUID   = _object getVariable ["ObjectUID","0"];
  33.    _uid = _this select 1;
  34.    _characterID = _this select 2;
  35.    _class = _this select 3;
  36.    _dir = _this select 4;
  37.    // _location = _this select 5;
  38.    _location = getPosATL _object;
  39.    _donotusekey = _this select 6;
  40.    _activatingPlayer = _this select 7;
  41.  
  42.    _done = false;
  43.     _retry = 0;
  44.     // TODO: Needs major overhaul for 1.1
  45.     while {_retry < 10} do {
  46.        
  47.         sleep 1;
  48.         // GET DB ID
  49.         _key = format["CHILD:388:%1:",_uid];
  50.         diag_log ("HIVE: WRITE: "+ str(_key));
  51.         _result = _key call server_hiveReadWrite;
  52.         _outcome = _result select 0;
  53.         if (_outcome == "PASS") then {
  54.             _oid = _result select 1;
  55.             //_object setVariable ["ObjectID", _oid, true];
  56.             diag_log("CUSTOM: Selected " + str(_oid));
  57.             _done = true;
  58.             _retry = 100;
  59.  
  60.         } else {
  61.             diag_log("CUSTOM: trying again to get id for: " + str(_uid));
  62.             _done = false;
  63.             _retry = _retry + 1;
  64.         };
  65.     };
  66.  
  67.     if(!_done) exitWith { diag_log("CUSTOM: failed to get id for : " + str(_uid)); };
  68.  
  69.     // add items from previous vehicle here
  70.     _weapons =      getWeaponCargo _object;
  71.     _magazines =    getMagazineCargo _object;
  72.     _backpacks =    getBackpackCargo _object;
  73.  
  74.     clearWeaponCargoGlobal  _object;
  75.     clearMagazineCargoGlobal  _object;
  76.     clearBackpackCargoGlobal _object;
  77.  
  78.     // Remove marker
  79.     deleteVehicle _object;
  80.  
  81.     _newobject = createVehicle [_class, [0,0,0], [], 0, "CAN_COLLIDE"];
  82.  
  83.     // remove old vehicle from DB
  84.     [_objectID,_objectUID,_activatingPlayer] call server_deleteObj;
  85.  
  86.     // switch var to new vehicle at this point.
  87.     _object = _newobject;
  88.  
  89.     _object setDir _dir;
  90.     _object setPosATL _location;
  91.  
  92.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvBLK_overlay.jpg''];';};
  93.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvDSRT_overlay.jpg''];';};
  94.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvGRY_overlay.jpg''];';};
  95.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvKTY_overlay.jpg''];';};
  96.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvLF_overlay.jpg''];';};
  97.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvRED_overlay.jpg''];';};
  98.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suvUSA_overlay.jpg''];';};
  99.     if (_class == "SUV_TK_CIV_EP1") then {_object setVehicleInit 'this setObjectTexture [0, ''custom\suv_overlay.png''];';};
  100.  
  101.     //Add weapons
  102.     _objWpnTypes =  _weapons select 0;
  103.     _objWpnQty =    _weapons select 1;
  104.     _countr = 0;
  105.     {
  106.         _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  107.         _countr = _countr + 1;
  108.     } count _objWpnTypes;
  109.    
  110.     //Add Magazines
  111.     _objWpnTypes = _magazines select 0;
  112.     _objWpnQty = _magazines select 1;
  113.     _countr = 0;
  114.     {
  115.         _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  116.         _countr = _countr + 1;
  117.     } count _objWpnTypes;
  118.  
  119.     //Add Backpacks
  120.     _objWpnTypes = _backpacks select 0;
  121.     _objWpnQty = _backpacks select 1;
  122.     _countr = 0;
  123.     {
  124.         _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  125.         _countr = _countr + 1;
  126.     } count _objWpnTypes;
  127.  
  128.     _object setVariable ["ObjectID", _oid, true];
  129.    
  130.     _object setVariable ["lastUpdate",time];
  131.    
  132.     _object setVariable ["CharacterID", _characterID, true];
  133.  
  134.     PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  135.  
  136.     _object call fnc_veh_ResetEH;
  137.    
  138.     // for non JIP users this should make sure everyone has eventhandlers for vehicles.
  139.     PVDZE_veh_Init = _object;
  140.     publicVariable "PVDZE_veh_Init";
  141.     processInitCommands;
  142.    
  143.     diag_log ("PUBLISH: " + str(_activatingPlayer) + " Upgraded " + (_class) + " with ID " + str(_uid));
  144. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement