SHARE
TWEET

server_UpdateObject.sqf

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