Advertisement
Guest User

server_updateObject.sqf

a guest
Aug 1st, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 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.  
  36. if (!_parachuteWest) then {
  37. if ((typeOf _object) in SafeObjects) then {
  38.  
  39. } else {
  40. if (_objectID == "0" && _uid == "0") then
  41. {
  42. _object_position = getPosATL _object;
  43. #ifdef OBJECT_DEBUG
  44. diag_log(format["Deleting object %1 with invalid ID at pos [%2,%3,%4]",
  45. typeOf _object,
  46. _object_position select 0,
  47. _object_position select 1,
  48. _object_position select 2]);
  49. #endif
  50. _isNotOk = true;
  51. };
  52. };
  53. };
  54.  
  55.  
  56. if (_isNotOk) exitWith { deleteVehicle _object; };
  57.  
  58. _lastUpdate = _object getVariable ["lastUpdate",diag_tickTime];
  59. _needUpdate = _object in needUpdate_objects;
  60.  
  61. // TODO ----------------------
  62. _object_position = {
  63. private["_position","_worldspace","_fuel","_key"];
  64. _position = getPosATL _object;
  65. _worldspace = [
  66. round(direction _object),
  67. _position
  68. ];
  69. _fuel = 0;
  70. if (_object isKindOf "AllVehicles") then {
  71. _fuel = fuel _object;
  72. };
  73. _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel];
  74. #ifdef OBJECT_DEBUG
  75. diag_log ("HIVE: WRITE: "+ str(_key));
  76. #endif
  77.  
  78. _key call server_hiveWrite;
  79. };
  80.  
  81. _object_inventory = {
  82. private["_inventory","_previous","_key"];
  83. if (_object isKindOf "TrapItems") then {
  84. _inventory = [_object getVariable ["armed", false]];
  85. } else {
  86. _inventory = [
  87. getWeaponCargo _object,
  88. getMagazineCargo _object,
  89. getBackpackCargo _object
  90. ];
  91. };
  92. _previous = str(_object getVariable["lastInventory",[]]);
  93. if (str(_inventory) != _previous) then {
  94. _object setVariable["lastInventory",_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. #ifdef OBJECT_DEBUG
  101. diag_log ("HIVE: WRITE: "+ str(_key));
  102. #endif
  103. _key call server_hiveWrite;
  104. };
  105. };
  106.  
  107. _object_damage = {
  108. //Allow dmg process
  109. private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  110. _hitpoints = _object call vehicle_getHitpoints;
  111. _damage = damage _object;
  112. _array = [];
  113. {
  114. _hit = [_object,_x] call object_getHit;
  115. _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  116. if (_hit > 0) then {
  117. _array set [count _array,[_selection,_hit]];
  118. //diag_log format ["Section Part: %1, Dmg: %2",_selection,_hit];
  119. } else {
  120. _array set [count _array,[_selection,0]];
  121. };
  122. } forEach _hitpoints;
  123.  
  124. if (_forced) then {
  125. if (_object in needUpdate_objects) then {
  126. needUpdate_objects = needUpdate_objects - [_object];
  127. };
  128.  
  129. if (_objectID == "0") then {
  130. _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage];
  131. } else {
  132. _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  133. };
  134. diag_log ("HIVE: WRITE: "+ str(_key));
  135. _key call server_hiveWrite;
  136.  
  137. } else {
  138. if (!(_object in needUpdate_objects)) then {
  139. //#ifdef OBJECT_DEBUG
  140. diag_log format["DEBUG: Monitoring: %1",_object];
  141. //#endif
  142. needUpdate_objects set [count needUpdate_objects, _object];
  143. };
  144. };
  145. };
  146.  
  147. _object_killed = {
  148. [_ObjectID,_UID] call server_deleteObj;
  149. };
  150.  
  151.  
  152. _object setVariable ["lastUpdate",time,true];
  153. switch (_type) do {
  154. case "all": {
  155. call _object_position;
  156. call _object_inventory;
  157. call _object_damage;
  158. };
  159. case "position": {
  160. call _object_position;
  161. };
  162. case "gear": {
  163. call _object_inventory;
  164. };
  165. case "damage"; case "repair" : {
  166. call _object_damage;
  167. };
  168. case "killed": {
  169. call _object_killed;
  170. };
  171. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement