Advertisement
Guest User

Untitled

a guest
Jun 27th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. private ["_object","_type","_objectID","_uid","_lastUpdate","_needUpdate","_object_position","_object_inventory","_object_damage","_isNotOk","_parachuteWest","_firstTime","_object_killed","_object_repair","_isbuildable"];
  2.  
  3. _object = _this select 0;
  4.  
  5. if(isNull(_object)) exitWith {
  6. diag_log format["Skipping Null Object: %1", _object];
  7. };
  8.  
  9. _type = _this select 1;
  10. _parachuteWest = ((typeOf _object == "ParachuteWest") || (typeOf _object == "ParachuteC"));
  11. _isbuildable = (typeOf _object) in dayz_allowedObjects;
  12. _isNotOk = false;
  13. _firstTime = false;
  14. _objectID = _object getVariable ["ObjectID","0"];
  15. _uid = _object getVariable ["ObjectUID","0"];
  16.  
  17. if ((typeName _objectID != "string") || (typeName _uid != "string")) then
  18. {
  19. diag_log(format["Non-string Object: ID %1 UID %2", _objectID, _uid]);
  20. _objectID = "0";
  21. _uid = "0";
  22. };
  23.  
  24. if (!_parachuteWest && !(locked _object)) then {
  25. if (_objectID == "0" && _uid == "0") then
  26. {
  27. _object_position = getPosATL _object;
  28. _isNotOk = true;
  29. };
  30. };
  31.  
  32. if (_isNotOk && _isbuildable) exitWith { };
  33.  
  34. 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]); };
  35.  
  36. _lastUpdate = _object getVariable ["lastUpdate",time];
  37. _needUpdate = _object in needUpdate_objects;
  38.  
  39. _object_position = {
  40. private["_position","_worldspace","_fuel","_key"];
  41. _position = getPosATL _object;
  42. _worldspace = [
  43. (getDir _object) call KK_fnc_floatToString,
  44. _position call KK_fnc_positionToString
  45. ];
  46. _fuel = 0;
  47. if (_object isKindOf "AllVehicles") then {
  48. _fuel = fuel _object;
  49. };
  50. _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel];
  51. //diag_log ("HIVE: WRITE: "+ str(_key));
  52. _key call server_hiveWrite;
  53. };
  54.  
  55. _object_inventory = {
  56. private["_inventory","_previous","_key"];
  57. if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then{
  58. _inventory = _object getVariable ["plotfriends", []]; //We're replacing the inventory with UIDs for this item
  59. } else {
  60. _inventory = [
  61. getWeaponCargo _object,
  62. getMagazineCargo _object,
  63. getBackpackCargo _object
  64. ];
  65. };
  66. _previous = str(_object getVariable["lastInventory",[]]);
  67. if (str(_inventory) != _previous) then {
  68. _object setVariable["lastInventory",_inventory];
  69. if (_objectID == "0") then {
  70. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  71. } else {
  72. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  73. };
  74. _key call server_hiveWrite;
  75. };
  76. };
  77.  
  78. _object_damage = {
  79. private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  80. _hitpoints = _object call vehicle_getHitpoints;
  81. _damage = damage _object;
  82. _array = [];
  83. {
  84. _hit = [_object,_x] call object_getHit;
  85. _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  86. if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  87. _object setHit ["_selection", _hit];
  88. } count _hitpoints;
  89. _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  90. _key call server_hiveWrite;
  91. _object setVariable ["needUpdate",false,true];
  92. };
  93.  
  94. _object_killed = {
  95. private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  96. _hitpoints = _object call vehicle_getHitpoints;
  97. _damage = 1;
  98. _array = [];
  99. {
  100. _hit = [_object,_x] call object_getHit;
  101. _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  102. if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  103. _hit = 1;
  104. _object setHit ["_selection", _hit];
  105. } count _hitpoints;
  106. if (_objectID == "0") then {
  107. _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage];
  108. } else {
  109. _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  110. };
  111. _key call server_hiveWrite;
  112. _object setVariable ["needUpdate",false,true];
  113. if ((count _this) > 2) then {
  114. _killer = _this select 2;
  115. _charID = _object getVariable ['CharacterID','0'];
  116. _objID = _object getVariable['ObjectID','0'];
  117. _objUID = _object getVariable['ObjectUID','0'];
  118. _worldSpace = getPosATL _object;
  119. if (getPlayerUID _killer != "") then {
  120. _name = if (alive _killer) then { name _killer; } else { format["OBJECT %1", _killer]; };
  121. diag_log format["Vehicle killed: Vehicle %1 (TYPE: %2), CharacterID: %3, ObjectID: %4, ObjectUID: %5, Position: %6, Killer: %7 (UID: %8)", _object, (typeOf _object), _charID, _objID, _objUID, _worldSpace, _name, (getPlayerUID _killer)];
  122. } else {
  123. diag_log format["Vehicle killed: Vehicle %1 (TYPE: %2), CharacterID: %3, ObjectID: %4, ObjectUID: %5, Position: %6", _object, (typeOf _object), _charID, _objID, _objUID, _worldSpace];
  124. };
  125. };
  126. };
  127.  
  128. _object_repair = {
  129. private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  130. _hitpoints = _object call vehicle_getHitpoints;
  131. _damage = damage _object;
  132. _array = [];
  133. {
  134. _hit = [_object,_x] call object_getHit;
  135. _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  136. if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  137. _object setHit ["_selection", _hit];
  138. } count _hitpoints;
  139.  
  140. _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  141. _key call server_hiveWrite;
  142. _object setVariable ["needUpdate",false,true];
  143. };
  144.  
  145. _object setVariable ["lastUpdate",time,true];
  146.  
  147. switch (_type) do {
  148. case "all": {
  149. call _object_position;
  150. call _object_inventory;
  151. call _object_damage;
  152. };
  153. case "position": {
  154. if (!(_object in needUpdate_objects)) then {
  155. needUpdate_objects set [count needUpdate_objects, _object];
  156. };
  157. };
  158. case "gear": {
  159. call _object_inventory;
  160. };
  161. case "damage": {
  162. if ( (time - _lastUpdate) > 5) then {
  163. call _object_damage;
  164. } else {
  165. if (!(_object in needUpdate_objects)) then {
  166. needUpdate_objects set [count needUpdate_objects, _object];
  167. };
  168. };
  169. };
  170. case "killed": {
  171. call _object_killed;
  172. };
  173. case "repair": {
  174. call _object_damage;
  175. };
  176. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement