Advertisement
Guest User

Untitled

a guest
Jul 10th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 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") then
  37. {
  38. _object_position = getPosATL _object;
  39. #ifdef OBJECT_DEBUG
  40. diag_log(format["Deleting object %1 with invalid ID at pos [%2,%3,%4]",
  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. if (_isNotOk) exitWith { deleteVehicle _object; };
  51.  
  52. _lastUpdate = _object getVariable ["lastUpdate",time];
  53. _needUpdate = _object in needUpdate_objects;
  54.  
  55. // TODO ----------------------
  56. _object_position = {
  57. private["_position","_worldspace","_fuel","_key"];
  58. _position = getPosATL _object;
  59. _worldspace = [
  60. round(direction _object),
  61. _position
  62. ];
  63. _fuel = 0;
  64. if (_object isKindOf "AllVehicles") then {
  65. _fuel = fuel _object;
  66. };
  67. _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel];
  68. #ifdef OBJECT_DEBUG
  69. diag_log ("HIVE: WRITE: "+ str(_key));
  70. #endif
  71.  
  72. _key call server_hiveWrite;
  73. };
  74.  
  75. // ###COPY START
  76. _object_inventory = {
  77. // ### BASE BUILDING 1.2 ### START
  78. //This forces object to write to database changing the inventory of the object twice
  79. // so it updates the object from operate_gates.sqf
  80.  
  81. private["_inventory","_previous","_key"];
  82. // This writes to database if object is buildable
  83. if (typeOf(_object) in allbuildables_class) then {
  84. //First lets make inventory [[[],[]],[[],[]],[[],[]]] so it updates object in DB
  85. _inventory = [[[],[]],[[],[]],[[],[]]];
  86. if (_objectID == "0") then {
  87. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  88. } else {
  89. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  90. };
  91. diag_log ("HIVE: Buildable: "+ str(_key));
  92. _key call server_hiveWrite;
  93. //Since we cant actually read from DB, lets make inventory this [], than write it again, to insure its updated to DB
  94. _inventory = [];
  95. if (_objectID == "0") then {
  96. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  97. } else {
  98. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  99. };
  100. diag_log ("HIVE: Buildable: "+ str(_key));
  101. _key call server_hiveWrite;
  102. // DO DEFAULT server_updateObject if not a buildable
  103. } else {
  104. _inventory = [
  105. getWeaponCargo _object,
  106. getMagazineCargo _object,
  107. getBackpackCargo _object
  108. ];
  109.  
  110.  
  111. _previous = str(_object getVariable["lastInventory",[]]);
  112. if (str(_inventory) != _previous) then {
  113. _object setVariable["lastInventory",_inventory];
  114. if (_objectID == "0") then {
  115. _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  116. } else {
  117. _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  118. };
  119. diag_log ("HIVE: WRITE: "+ str(_key));
  120. _key call server_hiveWrite;
  121. };
  122. };
  123. };
  124. // ### BASE BUILDING 1.2 ### END
  125. // ###COPY END
  126. _object_damage = {
  127. //Allow dmg process
  128. private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  129. _hitpoints = _object call vehicle_getHitpoints;
  130. _damage = damage _object;
  131. _array = [];
  132. {
  133. _hit = [_object,_x] call object_getHit;
  134. _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  135. if (_hit > 0) then {
  136. _array set [count _array,[_selection,_hit]];
  137. //cutText [format["Section Part: %1, Dmg: %2",_selection,_hit], "PLAIN DOWN"];
  138. } else {
  139. _array set [count _array,[_selection,0]];
  140. };
  141. } forEach _hitpoints;
  142.  
  143. if (_forced) then {
  144. if (_object in needUpdate_objects) then {
  145. needUpdate_objects = needUpdate_objects - [_object];
  146. };
  147.  
  148. if (_objectID == "0") then {
  149. _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage];
  150. } else {
  151. _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  152. };
  153. #ifdef OBJECT_DEBUG
  154. diag_log ("HIVE: WRITE: "+ str(_key));
  155. #endif
  156. _key call server_hiveWrite;
  157.  
  158. } else {
  159. if (_object in needUpdate_objects) then {
  160. needUpdate_objects = needUpdate_objects - [_object];
  161. };
  162. #ifdef OBJECT_DEBUG
  163. diag_log format["DEBUG: Monitoring: %1",_object];
  164. #endif
  165. needUpdate_objects set [count needUpdate_objects, _object];
  166. };
  167. };
  168.  
  169. _object_killed = {
  170. _object setDamage 1;
  171. call _object_damage;
  172. };
  173.  
  174.  
  175. _object setVariable ["lastUpdate",time,true];
  176. switch (_type) do {
  177. case "all": {
  178. call _object_position;
  179. call _object_inventory;
  180. call _object_damage;
  181. };
  182. case "position": {
  183. call _object_position;
  184. };
  185. case "gear": {
  186. call _object_inventory;
  187. };
  188. case "damage"; case "repair" : {
  189. call _object_damage;
  190. };
  191. case "killed": {
  192. call _object_killed;
  193. };
  194. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement