Advertisement
Guest User

for zupas

a guest
Nov 19th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.06 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.             round(direction _object),
  44.             _position
  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.         _key call server_hiveWrite;
  52. };
  53.  
  54. _isNormal = true;
  55. if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then{
  56.     _isNormal = false;
  57.     _inventory = _object getVariable ["plotfriends", []]; //We're replacing the inventory with UIDs for this item
  58. };
  59. if (typeOf (_object)in DZE_DoorsLocked) then{
  60.     _isNormal = false;
  61.     _inventory = _object getVariable ["doorfriends", []]; //We're replacing the inventory with UIDs for this item
  62. };
  63.  
  64. if(_isNormal)then {
  65.         _inventory = [
  66.             getWeaponCargo _object,
  67.             getMagazineCargo _object,
  68.             getBackpackCargo _object
  69.         ];
  70.         _previous = str(_object getVariable["lastInventory",[]]);
  71.         if (str(_inventory) != _previous) then {
  72.             _object setVariable["lastInventory",_inventory];
  73.             if (_objectID == "0") then {
  74.                 _key = format["CHILD:309:%1:%2:",_uid,_inventory];
  75.             } else {
  76.                 _key = format["CHILD:303:%1:%2:",_objectID,_inventory];
  77.             };
  78.             _key call server_hiveWrite;
  79.         };
  80. };
  81.  
  82. _object_damage = {
  83.     private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  84.         _hitpoints = _object call vehicle_getHitpoints;
  85.         _damage = damage _object;
  86.         _array = [];
  87.         {
  88.             _hit = [_object,_x] call object_getHit;
  89.             _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  90.             if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  91.             _object setHit ["_selection", _hit];
  92.         } count _hitpoints;
  93.         _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  94.         _key call server_hiveWrite;
  95.     _object setVariable ["needUpdate",false,true];
  96.     };
  97.  
  98. _object_killed = {
  99.     private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  100.     _hitpoints = _object call vehicle_getHitpoints;
  101.     _damage = 1;
  102.     _array = [];
  103.     {
  104.         _hit = [_object,_x] call object_getHit;
  105.         _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  106.         if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  107.         _hit = 1;
  108.         _object setHit ["_selection", _hit];
  109.     } count _hitpoints;
  110.     if (_objectID == "0") then {
  111.         _key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage];
  112.     } else {
  113.         _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  114.     };
  115.     _key call server_hiveWrite;
  116.     _object setVariable ["needUpdate",false,true];
  117.     if ((count _this) > 2) then {
  118.         _killer = _this select 2;
  119.         _charID = _object getVariable ['CharacterID','0'];
  120.         _objID = _object getVariable['ObjectID','0'];
  121.         _objUID = _object getVariable['ObjectUID','0'];
  122.         _worldSpace = getPosATL _object;
  123.         if (getPlayerUID _killer != "") then {
  124.             _name = if (alive _killer) then { name _killer; } else { format["OBJECT %1", _killer]; };
  125.             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)];
  126.         } else {
  127.             diag_log format["Vehicle killed: Vehicle %1 (TYPE: %2), CharacterID: %3, ObjectID: %4, ObjectUID: %5, Position: %6", _object, (typeOf _object), _charID, _objID, _objUID, _worldSpace];
  128.         };
  129.     };
  130. };
  131.  
  132. _object_repair = {
  133.     private["_hitpoints","_array","_hit","_selection","_key","_damage"];
  134.     _hitpoints = _object call vehicle_getHitpoints;
  135.     _damage = damage _object;
  136.     _array = [];
  137.     {
  138.         _hit = [_object,_x] call object_getHit;
  139.         _selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
  140.         if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
  141.         _object setHit ["_selection", _hit];
  142.     } count _hitpoints;
  143.    
  144.     _key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
  145.     _key call server_hiveWrite;
  146.     _object setVariable ["needUpdate",false,true];
  147. };
  148.  
  149. _object setVariable ["lastUpdate",time,true];
  150.  
  151. switch (_type) do {
  152.     case "all": {
  153.         call _object_position;
  154.         call _object_inventory;
  155.         call _object_damage;
  156.         };
  157.     case "position": {
  158.         if (!(_object in needUpdate_objects)) then {
  159.             needUpdate_objects set [count needUpdate_objects, _object];
  160.         };
  161.     };
  162.     case "gear": {
  163.         call _object_inventory;
  164.             };
  165.     case "damage": {
  166.         if ( (time - _lastUpdate) > 5) then {
  167.             call _object_damage;
  168.         } else {
  169.             if (!(_object in needUpdate_objects)) then {
  170.                 needUpdate_objects set [count needUpdate_objects, _object];
  171.             };
  172.         };
  173.     };
  174.     case "killed": {
  175.         call _object_killed;
  176.     };
  177.     case "repair": {
  178.         call _object_damage;
  179.     };
  180. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement