Advertisement
Guest User

Untitled

a guest
Dec 8th, 2015
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.86 KB | None | 0 0
  1. private [
  2. "_cfgClass","_class","_worldspace","_objSlot","_newObj","_playerOffset","_bbr","_p1","_p2","_maxWidth","_maxLength","_maxHeight","_pos2","_vel2","_dir2","_up2","_pos1","_vel1","_dir1","_up1","_interval","_velocityTransformation","_object","_status","_return","_oemType","_config","_currentTarget"];
  3. if !(isNil "EPOCH_simulSwap_Lock") exitWith{};
  4.  
  5. _object = _this select 0;
  6. if (isNull _object) exitWith{ EPOCH_target = objNull; };
  7.  
  8. _objType = typeOf _object;
  9.  
  10. _isSnap = false;
  11.  
  12. if (EPOCH_playerEnergy <= 0) exitWith {
  13. _dt = ["<t size = '0.8' shadow = '0' color = '#99ffffff'>Need Energy</t>", 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;
  14. };
  15.  
  16. // He_Man
  17. // if !(_objType call EPOCH_isBuildAllowed) exitWith{};
  18. // He_Man
  19.  
  20. EPOCH_simulSwap_Lock = true;
  21. _return = _object;
  22. _velocityTransformation = [];
  23. _prevSnapDistance = 0;
  24. _distanceMod = 0;
  25. _oemType = (typeOf _object);
  26. _config = (configFile >> "CfgVehicles" >> _oemType >> "simulClass");
  27. if (isText(_config)) then {
  28. _class = getText(_config);
  29. _create = true;
  30. _allowedSnapPoints = getArray(configfile >> "cfgVehicles" >> _class >> "allowedSnapPoints");
  31. _allowedSnapObjects = ["Constructions_static_F"];
  32. _snapObjects = configfile >> "cfgVehicles" >> _class >> "allowedSnapObjects";
  33. _energyCost = getNumber(configfile >> "cfgVehicles" >> _class >> "energyCost");
  34. if (_energyCost == 0) then {
  35. _energyCost = 0.1;
  36. };
  37. if (isArray(_snapObjects)) then {
  38. _allowedSnapObjects = getArray(_snapObjects);
  39. };
  40. // diag_log format["DEBUG ALLOWED SNAP OBJECTS: %1", _allowedSnapObjects];
  41. _newObj = _object;
  42. if (_create) then {
  43. _worldspace = [(getposATL _object),(vectordir _object),(vectorup _object)];
  44. _objSlot = _object getVariable["BUILD_SLOT", -1];
  45. _textureSlot = _object getVariable["TEXTURE_SLOT", 0];
  46. deleteVehicle _object;
  47. waitUntil {sleep 0.01; isNull _object};
  48. _newObj = createVehicle [_class, (_worldspace select 0), [], 0, "CAN_COLLIDE"];
  49. if (_objSlot != -1) then {
  50. _newObj setVariable ["BUILD_SLOT",_objSlot,true];
  51. };
  52. _newObj setVectorDirAndUp [_worldspace select 1,_worldspace select 2];
  53. _newObj setposATL (_worldspace select 0);
  54.  
  55. if (_textureSlot != 0) then {
  56. EPOCH_PAINTBUILD = [_newObj, _textureSlot, player, Epoch_personalToken];
  57. publicVariableServer "EPOCH_PAINTBUILD";
  58. };
  59. };
  60. EP_velocityTransformation = [];
  61. EPOCH_oldTarget = EPOCH_target;
  62. EPOCH_target = _newObj;
  63. _currentTarget = EPOCH_target;
  64. EPOCH_velTransform = true;
  65. EPOCH_objHold = 0;
  66. _onContactEH = _currentTarget addEventHandler["EpeContactStart", { if ((_this select 1) isKindOf "LandVehicle" || (_this select 1) isKindOf "Air" || (_this select 1) isKindOf "Ship" || (_this select 1) isKindOf "Tank") then{ EPOCH_target = objNull }; }];
  67. EP_snap = objNull;
  68. _previousDistanceNear = 0;
  69. _offset = player worldToModel (getposATL _currentTarget);
  70. EPOCH_X_OFFSET = _offset select 0;
  71. EPOCH_Y_OFFSET = _offset select 1;
  72. EPOCH_Z_OFFSET = _offset select 2;
  73. _lastCheckTime = diag_tickTime;
  74. while {EPOCH_target == _currentTarget} do {
  75. if (EPOCH_playerEnergy <= 0) exitWith { EPOCH_target = objNull; };
  76. _rejectMove = false;
  77. if ((diag_tickTime - _lastCheckTime) > 10) then {
  78. _lastCheckTime = diag_tickTime;
  79. _rejectMove = !(_objType call EPOCH_isBuildAllowed);
  80. };
  81. if (_rejectMove) exitWith{
  82. EPOCH_target = objNull;
  83. };
  84. _plyrdistance = player distance EPOCH_target;
  85. if (_plyrdistance < 10) then {
  86. _isSnap = false;
  87. _snapPosition = [0,0,0];
  88. _snapType = "para";
  89. _nearestObject = objNull;
  90.  
  91. // see if this can prevent riding on object
  92. if (EPOCH_Y_OFFSET < 3.6) then {
  93. EPOCH_Y_OFFSET = EPOCH_Y_OFFSET + 0.1;
  94. };
  95.  
  96. _pos2 = player modelToWorld[EPOCH_X_OFFSET, EPOCH_Y_OFFSET, EPOCH_Z_OFFSET];
  97. _distance = _pos2 distance EPOCH_target;
  98. if (EPOCH_buildMode == 1) then {
  99. if (isNull _nearestObject) then {
  100. {
  101. _nearestObjectRaw = nearestObject [EPOCH_target,_x];
  102. _distanceNear = EPOCH_target distance _nearestObjectRaw;
  103. if (_distanceNear < _previousDistanceNear) then {
  104. _nearestObject = _nearestObjectRaw;
  105. };
  106. _previousDistanceNear = _distanceNear;
  107. } forEach _allowedSnapObjects;
  108. };
  109. if (!isNull _nearestObject) then {
  110. _snapPointsPara = [] + getArray(configfile >> "cfgVehicles" >> (typeOf _nearestObject) >> "snapPointsPara");
  111. _snapPointsPerp = [] + getArray(configfile >> "cfgVehicles" >> (typeOf _nearestObject) >> "snapPointsPerp");
  112. _snapArrayPara = [];
  113. {
  114. if (_x in _allowedSnapPoints) then {
  115. _pOffset = _nearestObject selectionPosition _x;
  116. _snapPos = _nearestObject modelToWorld _pOffset;
  117. if ((_pos2 distance _snapPos) < 3) then {
  118. _snapArrayPara pushBack _snapPos;
  119. };
  120. };
  121. } forEach _snapPointsPara;
  122. _snapArrayPerp = [];
  123. {
  124. if (_x in _allowedSnapPoints) then {
  125. _pOffset = _nearestObject selectionPosition _x;
  126. _snapPos = _nearestObject modelToWorld _pOffset;
  127. if ((_pos2 distance _snapPos) < 3) then {
  128. _snapArrayPerp pushBack _snapPos;
  129. };
  130. };
  131. } forEach _snapPointsPerp;
  132. {
  133. _snapDistance = _pos2 distance _x;
  134. if (_snapDistance < 1 && (_snapDistance < _prevSnapDistance)) exitWith {
  135. _isSnap = true;
  136. _snapPosition = _x;
  137. _snapType = "para";
  138. };
  139. _prevSnapDistance = _snapDistance;
  140. } forEach _snapArrayPara;
  141. {
  142. _snapDistance = _pos2 distance _x;
  143. if (_snapDistance < 1 && (_snapDistance < _prevSnapDistance)) exitWith {
  144. _isSnap = true;
  145. _snapPosition = _x;
  146. _snapType = "perp";
  147. };
  148. _prevSnapDistance = _snapDistance;
  149. } forEach _snapArrayPerp;
  150. };
  151. if (_isSnap && _distance < 5) then {
  152. _pos2 = _snapPosition;
  153. if (!surfaceIsWater _pos2) then {
  154. _pos2 = ATLtoASL _pos2;
  155. };
  156. _vel2 = (velocity _nearestObject);
  157. _direction = getDir _nearestObject;
  158. if (_snapType == "perp") then {
  159. _direction = _direction - ([_snapPosition,_nearestObject] call BIS_fnc_dirTo);
  160. } else {
  161. _direction = 0;
  162. };
  163. if (EPOCH_snapDirection > 0) then {
  164. if (EPOCH_snapDirection == 1) then {
  165. _direction = _direction + 90;
  166. };
  167. if (EPOCH_snapDirection == 2) then {
  168. _direction = _direction + 180;
  169. };
  170. if (EPOCH_snapDirection == 3) then {
  171. _direction = _direction + 270;
  172. };
  173. };
  174. if (_direction > 360) then {
  175. _direction = _direction - 360;
  176. };
  177. if (_direction < 0) then {
  178. _direction = 360 + _direction;
  179. };
  180. _dir2 = [vectorDir _nearestObject, _direction] call EPOCH_returnVector;
  181. _up2 = (vectorUp _nearestObject);
  182. EP_velocityTransformation = [_pos2,_vel2,_dir2,_up2];
  183. };
  184. };
  185. if (!_isSnap) then {
  186. if !(surfaceIsWater _pos2) then {
  187. _pos2 = ATLtoASL _pos2;
  188. };
  189. if (EPOCH_space) then {
  190. _vel2 = (velocity player);
  191. _dir2 = [vectorDir player, EPOCH_buildDirection] call EPOCH_returnVector;
  192. _up2 = (vectorUp player);
  193. EPOCH_space = false;
  194. EP_velocityTransformation = [_pos2,_vel2,_dir2,_up2];
  195. } else {
  196. EP_velocityTransformation = [];
  197. };
  198. };
  199. };
  200. EPOCH_playerEnergy = (EPOCH_playerEnergy - _energyCost) max 0;
  201. uiSleep 0.1;
  202. };
  203. _currentTarget removeEventHandler["EpeContactStart", _onContactEH];
  204. EPOCH_velTransform = false;
  205. _disallowed = ["Tarp_SIM_EPOCH", "Freezer_SIM_EPOCH", "Fridge_SIM_EPOCH", "Shelf_SIM_EPOCH", "Pelican_SIM_EPOCH", "Wardrobe_SIM_EPOCH", "Bed_SIM_EPOCH", "Couch_SIM_EPOCH", "Cooker_SIM_EPOCH", "Chair_SIM_EPOCH", "Filing_SIM_EPOCH", "Table_SIM_EPOCH", "Locker_SIM_EPOCH", "ToolRack_SIM_EPOCH", "Shoebox_SIM_EPOCH", "Bunk_SIM_EPOCH", "Jack_SIM_EPOCH"];
  206. if !(_class in _disallowed) then {
  207. _currentTarget spawn EPOCH_countdown;
  208. };
  209. _currentTarget setVelocity [0,0,-0.01];
  210. };
  211. [] spawn{
  212. uiSleep 2;
  213. EPOCH_simulSwap_Lock = nil;
  214. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement