Advertisement
Guest User

ArmaScript

a guest
May 3rd, 2025
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. disableSerialization;
  2. showCinemaBorder false;
  3.  
  4. private _vehicleCount = 10;
  5.  
  6. private _vehicleList = [
  7. "CUP_O_T72_SLA",
  8. "CUP_O_T90_RU",
  9. "CUP_O_ZSU23_SLA",
  10. "CUP_O_BRDM2_CHDKZ",
  11. "CUP_O_BTR40_MG_TKM",
  12. "CUP_O_BTR80A_GREEN_RU",
  13. "CUP_O_UAZ_AA_RU",
  14. "CUP_O_Ural_ZU23_RU"
  15. ];
  16.  
  17. // === WEATHER FUNCTION ===
  18. fnc_changeWeatherAndTime = {
  19. private _hour = floor (random 24);
  20. private _minute = floor (random 60);
  21. private _overcast = random 1;
  22. private _rain = random 0.5;
  23. private _fog = random 0.3;
  24. private _windX = random 8;
  25. private _windY = random 8;
  26.  
  27. setDate [2035, 6, 20, _hour, _minute];
  28. 0 setOvercast _overcast;
  29. 0 setRain _rain;
  30. 0 setFog _fog;
  31. setWind [_windX, _windY, true];
  32. forceWeatherChange;
  33.  
  34. private _msg = format [
  35. "[ENV]\nTime: %1:%2\nOvercast: %3\nRain: %4\nFog: %5\nWind: [%6, %7]",
  36. _hour,
  37. if (_minute < 10) then {"0" + str _minute} else {str _minute},
  38. _overcast toFixed 2,
  39. _rain toFixed 2,
  40. _fog toFixed 2,
  41. _windX toFixed 1,
  42. _windY toFixed 1
  43. ];
  44.  
  45. hint _msg;
  46. diag_log _msg;
  47. };
  48.  
  49. // === CAMERA TARGET FIX ===
  50. fnc_getModelCenterTarget = {
  51. params ["_vehicle"];
  52. private _bbox = boundingBoxReal _vehicle;
  53. private _min = _bbox select 0;
  54. private _max = _bbox select 1;
  55. private _centerModel = [
  56. ((_min select 0) + (_max select 0)) / 2,
  57. ((_min select 1) + (_max select 1)) / 2,
  58. ((_min select 2) + (_max select 2)) / 2
  59. ];
  60. _vehicle modelToWorldVisual _centerModel
  61. };
  62.  
  63. // === BOUNDING BOX FUNCTION ===
  64. fnc_getBoundingBoxWireframe = {
  65. params ["_vehicle"];
  66.  
  67. if (isNull _vehicle) exitWith { diag_log "[BBOX_FAIL] Vehicle is null"; [] };
  68.  
  69. private _bbox = boundingBoxReal _vehicle;
  70. if ((count _bbox) < 2) exitWith { diag_log "[BBOX_FAIL] Invalid bounding box"; [] };
  71.  
  72. private _min = _bbox select 0;
  73. private _max = _bbox select 1;
  74.  
  75.  
  76.  
  77. // Shrink factor for the bounding box (set to 0.5 to shrink by half)
  78. private _shrink = 0.5; // Shrinking the bounding box by half
  79.  
  80. private _center = [
  81. ((_min select 0) + (_max select 0)) / 2,
  82. ((_min select 1) + (_max select 1)) / 2
  83. ];
  84.  
  85. private _scaleCorner = {
  86. params ["_x", "_y", "_z", "_center", "_shrink"];
  87. private _cx = _center select 0;
  88. private _cy = _center select 1;
  89. private _scaledX = _cx + ((_x - _cx) * _shrink);
  90. private _scaledY = _cy + ((_y - _cy) * _shrink);
  91. [_scaledX, _scaledY, _z]
  92. };
  93.  
  94. private _cornersModel = [
  95. [_min select 0, _min select 1, _min select 2],
  96. [_max select 0, _min select 1, _min select 2],
  97. [_max select 0, _max select 1, _min select 2],
  98. [_min select 0, _max select 1, _min select 2],
  99. [_min select 0, _min select 1, _max select 2],
  100. [_max select 0, _min select 1, _max select 2],
  101. [_max select 0, _max select 1, _max select 2],
  102. [_min select 0, _max select 1, _max select 2]
  103. ];
  104.  
  105. private _corners2D = [];
  106. private _abort = false;
  107.  
  108. {
  109. private _scaled = [_x select 0, _x select 1, _x select 2, _center, _shrink] call _scaleCorner;
  110. private _world = _vehicle modelToWorldVisual _scaled;
  111. private _screen = worldToScreen _world;
  112. if (!isNil "_screen" && {count _screen == 2}) then {
  113. _corners2D pushBack _screen;
  114. } else {
  115. _abort = true;
  116. };
  117. } forEach _cornersModel;
  118.  
  119. if (_abort || (count _corners2D != 8)) exitWith {
  120. diag_log "[BBOX_FAIL] Screen projection failed.";
  121. []
  122. };
  123.  
  124. diag_log format ["[BBOX3D] %1 | %2", typeOf _vehicle, _corners2D];
  125. _corners2D
  126. };
  127.  
  128. // === SPAWN VEHICLE FUNCTION ===
  129. _spawnVehicle = {
  130. private ["_vehicleType", "_spawnPos", "_vehicle"];
  131. _vehicleType = _this select 0;
  132. _spawnPos = getPos player;
  133.  
  134. _randomDistance = 500 + random 500;
  135. _randomAngle = random 360;
  136.  
  137. // Adjust spawn position using the offset
  138. _spawnPos set [0, (_spawnPos select 0) + (_randomDistance * cos _randomAngle)];
  139. _spawnPos set [1, (_spawnPos select 1) + (_randomDistance * sin _randomAngle)];
  140.  
  141. // Ensure vehicle spawns at a valid height above the terrain (avoiding water)
  142. private _z = getTerrainHeightASL [_spawnPos select 0, _spawnPos select 1];
  143. _spawnPos set [2, _z + 2]; // Ensure the vehicle spawns slightly above the terrain (increase +2 for higher positioning)
  144.  
  145. // If the Z position is too low (e.g., in water), set a minimum safe height
  146. if (_spawnPos select 2 < 2) then {
  147. _spawnPos set [2, 2]; // Ensure vehicle spawns at least 2 meters above sea level
  148. };
  149.  
  150. _vehicle = _vehicleType createVehicle _spawnPos;
  151.  
  152. if (isNull _vehicle) then {
  153. hint "Fehler beim Spawnen des Fahrzeugs!";
  154. } else {
  155. hint format ["Fahrzeug gespawnt: %1", _vehicleType];
  156. };
  157.  
  158. _vehicle
  159. };
  160.  
  161. // === MAIN LOOP ===
  162. while {true} do {
  163. sleep 1;
  164. call fnc_changeWeatherAndTime;
  165. hint "Waiting 15 seconds to adapt brightness...";
  166. sleep 3;
  167.  
  168. hint format ["Spawning %1 vehicles...", _vehicleCount];
  169.  
  170. for "_i" from 1 to _vehicleCount do {
  171. private _vehicleType = selectRandom _vehicleList;
  172. hint format ["Spawning vehicle %1/%2: %3", _i, _vehicleCount, _vehicleType];
  173.  
  174. private _playerPos = getPosATL player;
  175. private _angle = random 360;
  176. private _distance = 300 + random 300;
  177. private _x = (_playerPos select 0) + (_distance * cos _angle);
  178. private _y = (_playerPos select 1) + (_distance * sin _angle);
  179. private _z = getTerrainHeightASL [_x, _y];
  180.  
  181. private _spawnPos = [_x, _y, _z + 0.5];
  182. private _vehicle = createVehicle [_vehicleType, _spawnPos, [], 0, "NONE"];
  183. _vehicle setDir (random 360);
  184. _vehicle setPosASL _spawnPos;
  185. _vehicle allowDamage false;
  186. _vehicle enableSimulation true;
  187.  
  188. sleep 1;
  189. diag_log format ["[SPAWNED] %1 at [%2,%3,%4]", _vehicleType, _x, _y, _z];
  190.  
  191. private _vehiclePos = getPosATL _vehicle;
  192. private _camAngle = random 360;
  193. private _camDist = 30 + random 40;
  194. private _camHeight = 10 + random 20;
  195.  
  196. private _camX = (_vehiclePos select 0) + (_camDist * cos _camAngle);
  197. private _camY = (_vehiclePos select 1) + (_camDist * sin _camAngle);
  198. private _camZ = (_vehiclePos select 2) + _camHeight;
  199.  
  200. private _camera = "camera" camCreate [_camX, _camY, _camZ];
  201. private _lookAt = [_vehicle] call fnc_getModelCenterTarget;
  202.  
  203. _camera camSetTarget _lookAt;
  204. _camera camSetFov (0.7 + random 0.3);
  205. _camera camCommit 0;
  206. _camera cameraEffect ["INTERNAL", "BACK"];
  207.  
  208. diag_log format ["[CAMERA] %1 | Pos: [%2,%3,%4] → Target: %5", _vehicleType, _camX, _camY, _camZ, _lookAt];
  209.  
  210. sleep 2;
  211.  
  212. private _bbox = [_vehicle] call fnc_getBoundingBoxWireframe;
  213.  
  214. sleep 3;
  215.  
  216. if (!isNull _camera) then {
  217. _camera cameraEffect ["TERMINATE", "BACK"];
  218. camDestroy _camera;
  219. };
  220. if (!isNull _vehicle) then {
  221. deleteVehicle _vehicle;
  222. };
  223.  
  224. sleep 1;
  225. };
  226.  
  227. titleText ["", "BLACK IN", 1];
  228. hint "Cycle complete. Restarting...";
  229. sleep 3;
  230. };
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement