Guest User

Untitled

a guest
Oct 7th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. /*
  2. [_object,_type] spawn server_updateObject;
  3. */
  4. private ["_object","_type","_objectID","_uid","_lastUpdate","_needUpdate","_object_position","_object_inventory","_object_damage","_isNotOk"];
  5.  
  6. #include "\z\addons\dayz_server\compile\server_toggle_debug.hpp"
  7.  
  8. _object = _this select 0;
  9. _type = _this select 1;
  10. _forced = false;
  11. if (count _this > 2) then {
  12. _forced = _this select 2;
  13. };
  14. _parachuteWest = typeOf _object == "ParachuteWest";
  15. _isNotOk = false;
  16.  
  17. _objectID = "0";
  18. _uid = "0";
  19.  
  20. if (!((isNil "_object") OR {(isNull _object)})) then {
  21. _objectID = _object getVariable ["ObjectID","0"];
  22. _uid = _object getVariable ["ObjectUID","0"];
  23. };
  24.  
  25. if ((typeName _objectID != "string") || (typeName _uid != "string")) then
  26. {
  27. #ifdef OBJECT_DEBUG
  28. diag_log(format["Non-string Object: ID %1 UID %2", _objectID, _uid]);
  29. #endif
  30. //force fail
  31. _objectID = "0";
  32. _uid = "0";
  33. };
  34.  
  35. if (!_parachuteWest) then {
  36. if (_objectID == “0? && _uid == “0? && (vehicle _object getVariable ["Sarge",0] != 1)) then {
  37. {
  38. _object_position = getPosATL _object;
  39. #ifdef OBJECT_DEBUG
  40. diag_log format ["DEBUG: Deleting object %1 with invalid ID at [%2,%3,%4]“, typeOf _object, _object_position select 0, _object_position select 1,
  41. typeOf _object,
  42. _object_position select 0,
  43. _object_position select 1,
  44. _object_position select 2]);
  45. #endif
  46. _isNotOk = true;
  47. };
  48. };
  49. };
  50.  
  51. if (_isNotOk) exitWith { deleteVehicle _object; };
  52.  
  53. _lastUpdate = _object getVariable ["lastUpdate",diag_tickTime];
  54. _needUpdate = _object in needUpdate_objects;
  55.  
  56. // TODO ----------------------
  57. _object_position = {
  58. private["_position","_worldspace","_fuel","_key"];
  59. _position = getPosATL _object;
  60. _worldspace = [
  61. round(direction _object),
  62. _position
  63. ];
  64. _fuel = 0;
  65. if (_object isKindOf "AllVehicles") then {
  66. _fuel = fuel _object;
  67. };
  68. _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel];
  69. #ifdef OBJECT_DEBUG
  70. diag_log ("HIVE: WRITE: "+ str(_key));
  71. #endif
  72.  
  73. _key call server_hiveWrite;
  74. };
  75.  
  76. // ###COPY START
  77. _object_inventory = {
  78. // ### BASE BUILDING 1.2 ### START
  79. //This forces object to write to database changing the inventory of the object twice
  80. // so it updates the object from operate_gates.sqf
  81.  
  82. private["_inventory","_previous","_key"];
  83. // This writes to database if object is buildable
  84. if (typeOf(_object) in allbuildables_class) then {
  85. //First lets make inventory [[[],[]],[[],[]],[[],[]]] so it updates object in DB
  86. _inventory = [[[],[]],[[],[]],[[],[]]];
  87. if (_objectID == "0") then {
  88. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  89. } else {
  90. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  91. };
  92. diag_log ("HIVE: Buildable: "+ str(_key));
  93. _key call server_hiveWrite;
  94. //Since we cant actually read from DB, lets make inventory this [], than write it again, to insure its updated to DB
  95. _inventory = [];
  96. if (_objectID == "0") then {
  97. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  98. } else {
  99. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  100. };
  101. diag_log ("HIVE: Buildable: "+ str(_key));
  102. _key call server_hiveWrite;
  103. // DO DEFAULT server_updateObject if not a buildable
  104. } else {
  105. _inventory = [
  106. getWeaponCargo _object,
  107. getMagazineCargo _object,
  108. getBackpackCargo _object
  109. ];
  110.  
  111.  
  112. _previous = str(_object getVariable["lastInventory",[]]);
  113. if (str(_inventory) != _previous) then {
  114. _object setVariable["lastInventory",_inventory];
  115. if (_objectID == "0") then {
  116. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  117. } else {
  118. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  119. };
  120. diag_log ("HIVE: WRITE: "+ str(_key));
  121. _key call server_hiveWrite;
  122. };
  123. };
  124. };
  125. // ### BASE BUILDING 1.2 ### END
  126. // ###COPY END
  127.  
  128. _object_damage = {
  129. //Allow dmg process
  130. private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  131. _hitpoints = _object call vehicle_getHitpoints;
  132. _damage = damage _object;
  133. _array = [];
  134. {
  135. _hit = [_object,_x] call object_getHit;
  136. _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  137. if (_hit > 0) then {
  138. _array set [count _array,[_selection,_hit]];
  139. //diag_log format ["Section Part: %1, Dmg: %2",_selection,_hit];
  140. } else {
  141. _array set [count _array,[_selection,0]];
  142. };
  143. } forEach _hitpoints;
  144.  
  145. if (_forced) then {
  146. if (_object in needUpdate_objects) then {
  147. needUpdate_objects = needUpdate_objects - [_object];
  148. };
  149.  
  150. if (_objectID == "0") then {
  151. _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage];
  152. } else {
  153. _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  154. };
  155. diag_log ("HIVE: WRITE: "+ str(_key));
  156. _key call server_hiveWrite;
  157.  
  158. } else {
  159. if (!(_object in needUpdate_objects)) then {
  160. //#ifdef OBJECT_DEBUG
  161. diag_log format["DEBUG: Monitoring: %1",_object];
  162. //#endif
  163. needUpdate_objects set [count needUpdate_objects, _object];
  164. };
  165. };
  166. };
  167.  
  168. _object_killed = {
  169. [_ObjectID,_UID] call server_deleteObj;
  170. };
  171.  
  172.  
  173. _object setVariable ["lastUpdate",time,true];
  174. switch (_type) do {
  175. case "all": {
  176. call _object_position;
  177. call _object_inventory;
  178. call _object_damage;
  179. };
  180. case "position": {
  181. call _object_position;
  182. };
  183. case "gear": {
  184. call _object_inventory;
  185. };
  186. case "damage"; case "repair" : {
  187. call _object_damage;
  188. };
  189. case "killed": {
  190. call _object_killed;
  191. };
  192. };
Advertisement
Add Comment
Please, Sign In to add comment