Advertisement
Guest User

server_publishVehicle.sqf

a guest
Apr 7th, 2015
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. private ["_object","_worldspace","_location","_dir","_class","_uid","_dam","_hitpoints","_selection","_array","_damage","_fuel","_key","_totaldam","_spawnDMG","_characterID"];
  2. //[_veh,[_dir,_location],"V3S_Civ",true]
  3. _object = _this select 0;
  4. _worldspace = _this select 1;
  5. _class = _this select 2;
  6. _spawnDMG = _this select 3;
  7. _characterID = _this select 4;
  8.  
  9. _fuel = 1;
  10. _damage = 0;
  11. _array = [];
  12.  
  13. diag_log ("PUBLISH: Attempt " + str(_object));
  14. _dir = _worldspace select 0;
  15. _location = _worldspace select 1;
  16.  
  17. //Generate UID test using time
  18. // _uid = str( round (dateToNumber date)) + str(round time);
  19. _uid = _worldspace call dayz_objectUID2;
  20. //_uid = format["%1%2",(round time),_uid];
  21.  
  22. if (_spawnDMG) then {
  23. _fuel = 0;
  24. if (getNumber(configFile >> "CfgVehicles" >> _class >> "isBicycle") != 1) then {
  25.  
  26. // Create randomly damaged parts
  27.  
  28. _totaldam = 0;
  29. _hitpoints = _object call vehicle_getHitpoints;
  30. {
  31. // generate damage on all parts
  32. _dam = call generate_new_damage;
  33.  
  34. _selection = getText(configFile >> "cfgVehicles" >> _class >> "HitPoints" >> _x >> "name");
  35.  
  36. if (_dam > 0) then {
  37. _array set [count _array,[_selection,_dam]];
  38. _totaldam = _totaldam + _dam;
  39. };
  40. } count _hitpoints;
  41.  
  42.  
  43. // just set low base dmg - may change later
  44. _damage = 0;
  45.  
  46. // New fuel min max
  47. _fuel = (random(DynamicVehicleFuelHigh-DynamicVehicleFuelLow)+DynamicVehicleFuelLow) / 100;
  48.  
  49. };
  50. };
  51.  
  52. // TODO: check if uid already exists && if so increment by 1 && check again as soon as we find nothing continue.
  53.  
  54. //Send request
  55. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, _damage , _characterID, _worldspace, [], _array, _fuel,_uid];
  56. diag_log ("HIVE: WRITE: "+ str(_key));
  57. _key call server_hiveWrite;
  58.  
  59. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  60.  
  61. // Switched to spawn so we can wait a bit for the ID
  62. [_object,_uid,_fuel,_damage,_array,_characterID,_class] spawn {
  63. private["_object","_uid","_fuel","_damage","_array","_characterID","_done","_retry","_key","_result","_outcome","_oid","_selection","_dam","_class"];
  64.  
  65. _object = _this select 0;
  66. _uid = _this select 1;
  67. _fuel = _this select 2;
  68. _damage = _this select 3;
  69. _array = _this select 4;
  70. _characterID = _this select 5;
  71. _class = _this select 6;
  72.  
  73. _done = false;
  74. _retry = 0;
  75. // TODO: Needs major overhaul
  76. while {_retry < 10} do {
  77.  
  78. sleep 1;
  79. // GET DB ID
  80. _key = format["CHILD:388:%1:",_uid];
  81. diag_log ("HIVE: WRITE: "+ str(_key));
  82. _result = _key call server_hiveReadWrite;
  83. _outcome = _result select 0;
  84. if (_outcome == "PASS") then {
  85. _oid = _result select 1;
  86. _object setVariable ["ObjectID", _oid, true];
  87. diag_log("CUSTOM: Selected " + str(_oid));
  88. _done = true;
  89. _retry = 100;
  90.  
  91. } else {
  92. diag_log("CUSTOM: trying again to get id for: " + str(_uid));
  93. _done = false;
  94. _retry = _retry + 1;
  95. };
  96. };
  97. if(!_done) exitWith { deleteVehicle _object; diag_log("CUSTOM: failed to get id for : " + str(_uid)); };
  98.  
  99. _object setVariable ["lastUpdate",time];
  100. _object setVariable ["CharacterID", _characterID, true];
  101. _object setDamage _damage;
  102.  
  103. // Set Hits after ObjectID is set
  104. {
  105. _selection = _x select 0;
  106. _dam = _x select 1;
  107. if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  108. [_object,_selection,_dam] call object_setFixServer;
  109. } count _array;
  110.  
  111. _object setFuel _fuel;
  112.  
  113. _object setvelocity [0,0,1];
  114.  
  115. _object call fnc_veh_ResetEH;
  116.  
  117. // testing - should make sure everyone has eventhandlers for vehicles was unused...
  118. PVDZE_veh_Init = _object;
  119. publicVariable "PVDZE_veh_Init";
  120.  
  121. diag_log ("PUBLISH: Created " + (_class) + " with ID " + str(_uid));
  122. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement