Advertisement
Guest User

server_spawnVehicle.sqf

a guest
May 20th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. private ["_player","_vehicledata","_arrow","_key","_garage","_class","_cid","_colour1","_inventory","_fuel","_damage","_hitpoints","_location","_dir","_worldspace","_uid","_vehiclelist","_newlist"];
  2. _player = _this select 0;
  3. _vehicledata = _this select 1;
  4. _arrow = _this select 2;
  5. _garage = _this select 3;
  6.  
  7. _class = _vehicledata select 0;
  8. _cid = str(_vehicledata select 1);
  9. _colour1 = _vehicledata select 2;
  10. _colour2 = _vehicledata select 3;
  11. _inventory = _vehicledata select 4;
  12. _fuel = _vehicledata select 5;
  13. _damage = _vehicledata select 6;
  14. _hitpoints = _vehicledata select 7;
  15.  
  16. _location = getPosATL _arrow;
  17. diag_log format ["[Schwedes-Debug] _location: %1 | getPos _arrow: %2",_location, (getPos _arrow)];
  18. _dir = getDir _garage;
  19. _worldspace = [_dir,_location];
  20.  
  21. _uid = _worldspace call dayz_objectUID3;
  22. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, 0 , _cid, _worldspace, [], [], 1,_uid];
  23. diag_log ("HIVE: WRITE: "+ str(_key));
  24. _key call server_hiveWrite;
  25.  
  26. [_arrow,_uid,_cid,_class,_dir,_location,_player,_colour1,_colour2,_inventory,_fuel,_damage,_hitpoints] spawn {
  27. private ["_object","_uid","_characterID","_done","_retry","_key","_result","_outcome","_oid","_class","_location","_object_para","_activatingPlayer","_colour1","_colour2","_inventory","_fuel","_damage","_hitpoints","_clrinit","_clrinit2","_objWpnTypes","_objWpnQty","_countr"];
  28. _object = _this select 0;
  29. _uid = _this select 1;
  30. _characterID = _this select 2;
  31. _class = _this select 3;
  32. _dir = _this select 4;
  33. _location = _this select 5;
  34. _activatingPlayer = _this select 6;
  35. _colour1 = _this select 7;
  36. _colour2 = _this select 8;
  37. _inventory = _this select 9;
  38. _fuel = _this select 10;
  39. _damage = _this select 11;
  40. _hitpoints = _this select 12;
  41.  
  42. _done = false;
  43. _retry = 0;
  44. while {_retry < 10} do {
  45. sleep 1;
  46. _key = format["CHILD:388:%1:",_uid];
  47. diag_log ("HIVE: WRITE: "+ str(_key));
  48. _result = _key call server_hiveReadWrite;
  49. _outcome = _result select 0;
  50. if (_outcome == "PASS") then {
  51. _oid = _result select 1;
  52. diag_log("CUSTOM: Selected " + str(_oid));
  53. _done = true;
  54. _retry = 100;
  55. } else {
  56. diag_log("CUSTOM: trying again to get id for: " + str(_uid));
  57. _done = false;
  58. _retry = _retry + 1;
  59. };
  60. };
  61. deleteVehicle _object;
  62.  
  63. if(!_done) exitWith { diag_log("CUSTOM: failed to get id for : " + str(_uid)); };
  64.  
  65. _object = createVehicle [_class, _location, [], 0, "CAN_COLLIDE"];
  66. diag_log format ["[Schwedes-Debug] Object getPos: %1 | getPosASL: %2",(getPosASL _object), (getPos _object)];
  67. _object setpos _location;
  68. diag_log format ["[Schwedes-Debug] Object getPosASL after setpos: %1",(getPosASL _object)];
  69. _object setDir _dir;
  70. _object setvehiclelock "locked";
  71.  
  72. clearWeaponCargoGlobal _object;
  73. clearMagazineCargoGlobal _object;
  74.  
  75. _object setVariable ["ObjectID", _oid, true];
  76. _object setVariable ["lastUpdate",time];
  77. _object setVariable ["CharacterID",_characterID, true];
  78.  
  79. if (_colour1 != "0") then {
  80. _object setVariable ["Colour",_colour1,true];
  81. _clrinit = format ["#(argb,8,8,3)color(%1)",_colour1];
  82. _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];";
  83. };
  84. if (_colour2 != "0") then {
  85. _object setVariable ["Colour2",_colour2,true];
  86. _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2];
  87. _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];";
  88. };
  89.  
  90. _objWpnTypes = (_inventory select 0) select 0;
  91. _objWpnQty = (_inventory select 0) select 1;
  92. _countr = 0;
  93. {
  94. if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  95. _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  96. };
  97. _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  98. _countr = _countr + 1;
  99. } count _objWpnTypes;
  100.  
  101. _objWpnTypes = (_inventory select 1) select 0;
  102. _objWpnQty = (_inventory select 1) select 1;
  103. _countr = 0;
  104. {
  105. if (_x == "BoltSteel") then { _x = "WoodenArrow" };
  106. if (_x == "ItemTent") then { _x = "ItemTentOld" };
  107. _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  108. _countr = _countr + 1;
  109. } count _objWpnTypes;
  110.  
  111. _objWpnTypes = (_inventory select 2) select 0;
  112. _objWpnQty = (_inventory select 2) select 1;
  113. _countr = 0;
  114. {
  115. _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  116. _countr = _countr + 1;
  117. } count _objWpnTypes;
  118.  
  119. _object setFuel _fuel;
  120. _object setDamage _damage;
  121.  
  122. {
  123. private ["_selection","_dam"];
  124. _selection = _x select 0;
  125. _dam = _x select 1;
  126. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  127. [_object,_selection,_dam] call object_setFixServer;
  128. } forEach _hitpoints;
  129.  
  130. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  131. _object call fnc_veh_ResetEH;
  132. PVDZE_veh_Init = _object;
  133. publicVariable "PVDZE_veh_Init";
  134. };
  135.  
  136. _vehiclelist = _garage getVariable ["StoredVehicles",[]];
  137.  
  138. _newlist = [];
  139. {
  140. private ["_data","_toremove"];
  141. _toremove = false;
  142. if ((_x select 1) == _cid) then { _toremove = true; };
  143. if (!_toremove) then {
  144. _data = [(_x select 0),(_x select 1),(_x select 2),(_x select 3),(_x select 4),(_x select 5),(_x select 6),(_x select 7)];
  145. _newlist set [count _newlist,_data];
  146. };
  147. } count _vehiclelist;
  148.  
  149. _garage setVariable ["StoredVehicles",_newlist,true];
  150.  
  151. diag_log format["VIRTUAL GARAGE: Player %1 (%2) has spawned a %3 | "+str _newlist+"",(name _player),(getPlayerUID _player),_class];
  152.  
  153. [_garage,"gear",_newlist] spawn server_updateObject;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement