clean.sqf 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. File: clean.sqf
  3. Author:
  4. Quiksilver
  5. Last modified:
  6. 10/12/2014 ArmA 1.36 by Quiksilver
  7. Description:
  8. Maintain healthy quantity of some mission objects created during scenarios, including some created by the engine.
  9. - Dead bodies
  10. - Dead vehicles
  11. - Craters
  12. - Weapon holders (ground garbage)
  13. - Mines
  14. - Static weapons
  15. - Ruins
  16. - Orphaned MP Triggers http://feedback.arma3.com/view.php?id=19231
  17. - Empty Groups
  18. * Ruins can be excluded by setPos [0,0,0] on them, this script will not touch them in that case. Could be done for JIP/locality reasons, since Ruins can be fiddly with JIP.
  19. * Note: Please do not place any triggers at nullPos [0,0,0]. This script by default removes all triggers at nullPos.
  20. Instructions:
  21. ExecVM from initServer.sqf or init.sqf in your mission directory.
  22. [] execVM "clean.sqf"; // If you put the file in mission directory
  23. [] execVM "scripts\clean.sqf"; // If you put the file in a folder, in this case called "scripts"
  24. _________________________________________________________________________*/
  25. sleep 15;
  26. private ["_isHidden","_checkPlayerCount","_checkFrequencyDefault","_checkFrequencyAccelerated","_playerThreshold","_deadMenLimit","_deadMenDistCheck","_deadMenDist","_deadVehiclesLimit","_deadVehicleDistCheck","_deadVehicleDist","_craterLimit","_craterDistCheck","_craterDist","_ruins","_ruinsLimit","_ruinsDistCheck","_ruinsDist","_weaponHolderLimit","_weaponHolderDistCheck","_weaponHolderDist","_minesLimit","_minesDistCheck","_minesDist","_staticsLimit","_staticsDistCheck","_staticsDist","_orphanedTriggers","_emptyGroups"];
  27. //==================== HIDDEN-FROM-PLAYERS FUNCTION
  28. _isHidden = compileFinal "
  29. private [""_c""];
  30. _c = FALSE;
  31. if (({(((_this select 0) distance _x) < (_this select 1))} count (_this select 2)) isEqualTo 0) then {
  32. _c = TRUE;
  33. };
  34. _c;
  35. ";
  36. //================================================================ CONFIG
  37. deleteManagerPublic = TRUE; // To terminate script via debug console
  38. _checkPlayerCount = TRUE; // dynamic sleep. Set TRUE to have sleep automatically adjust based on # of players.
  39. _checkFrequencyDefault = 180; // sleep default
  40. _checkFrequencyAccelerated = 60; // sleep accelerated
  41. _playerThreshold = 20; // How many players before accelerated cycle kicks in?
  42. _deadMenLimit = 50; // Bodies. Set -1 to disable.
  43. _deadMenDistCheck = TRUE; // TRUE to delete any bodies that are far from players.
  44. _deadMenDist = 2000; // Distance (meters) from players that bodies are not deleted if below max.
  45. _deadVehiclesLimit = 20; // Wrecks. Set -1 to disable.
  46. _deadVehicleDistCheck = TRUE; // TRUE to delete any destroyed vehicles that are far from players.
  47. _deadVehicleDist = 2000; // Distance (meters) from players that destroyed vehicles are not deleted if below max.
  48. _craterLimit = 20; // Craters. Set -1 to disable.
  49. _craterDistCheck = TRUE; // TRUE to delete any craters that are far from players.
  50. _craterDist = 2000; // Distance (meters) from players that craters are not deleted if below max.
  51. _weaponHolderLimit = 50; // Weapon Holders. Set -1 to disable.
  52. _weaponHolderDistCheck = TRUE; // TRUE to delete any weapon holders that are far from players.
  53. _weaponHolderDist = 500; // Distance (meters) from players that ground garbage is not deleted if below max.
  54. _minesLimit = -1; // Land mines. Set -1 to disable.
  55. _minesDistCheck = TRUE; // TRUE to delete any mines that are far from ANY UNIT (not just players).
  56. _minesDist = 3000; // Distance (meters) from players that land mines are not deleted if below max.
  57. _staticsLimit = -1; // Static weapons. Set -1 to disable.
  58. _staticsDistCheck = TRUE; // TRUE to delete any static weapon that is far from ANY UNIT (not just players.
  59. _staticsDist = 3000; // Distance (meters) from players that static weapons are not deleted if below max.
  60. _ruinsLimit = 20; // Ruins. Set -1 to disable.
  61. _ruinsDistCheck = TRUE; // TRUE to delete any ruins that are far from players.
  62. _ruinsDist = 3000; // Distance (meters) from players that ruins are not deleted if below max.
  63. _orphanedTriggers = TRUE; // Clean orphaned triggers in MP.
  64. _emptyGroups = TRUE; // Set FALSE to not delete empty groups.
  65. //================================================================ LOOP
  66. while {deleteManagerPublic} do {
  67. //================================= DEAD MEN
  68. if (!(_deadMenLimit isEqualTo -1)) then {
  69. if ((count allDeadMen) > _deadMenLimit) then {
  70. while {(((count allDeadMen) - _deadMenLimit) > 0)} do {
  71. detach (allDeadMen select 0);
  72. deleteVehicle (allDeadMen select 0);
  73. sleep 0.5;
  74. };
  75. } else {
  76. if (_deadMenDistCheck) then {
  77. {
  78. if ([_x,_deadMenDist,(playableUnits + switchableUnits)] call _isHidden) then {
  79. detach _x;
  80. deleteVehicle _x;
  81. };
  82. } count allDeadMen;
  83. };
  84. };
  85. };
  86. sleep 1;
  87. //================================= VEHICLES
  88. if (!(_deadVehiclesLimit isEqualTo -1)) then {
  89. if ((count (allDead - allDeadMen)) > _deadVehiclesLimit) then {
  90. while {(((count (allDead - allDeadMen)) - _deadVehiclesLimit) > 0)} do {
  91. deleteVehicle ((allDead - allDeadMen) select 0);
  92. sleep 0.5;
  93. };
  94. } else {
  95. if (_deadVehicleDistCheck) then {
  96. {
  97. if ([_x,_deadVehicleDist,(playableUnits + switchableUnits)] call _isHidden) then {
  98. deleteVehicle _x;
  99. };
  100. } count (allDead - allDeadMen);
  101. };
  102. };
  103. };
  104. sleep 1;
  105. //================================= CRATERS
  106. if (!(_craterLimit isEqualTo -1)) then {
  107. if ((count (allMissionObjects "CraterLong")) > _craterLimit) then {
  108. while {(((count (allMissionObjects "CraterLong")) - _craterLimit) > 0)} do {
  109. deleteVehicle ((allMissionObjects "CraterLong") select 0);
  110. sleep 0.5;
  111. };
  112. } else {
  113. if (_craterDistCheck) then {
  114. {
  115. if ([_x,_craterDist,(playableUnits + switchableUnits)] call _isHidden) then {
  116. deleteVehicle _x;
  117. };
  118. } count (allMissionObjects "CraterLong");
  119. };
  120. };
  121. };
  122. sleep 1;
  123. //================================= WEAPON HOLDERS
  124. if (!(_weaponHolderLimit isEqualTo -1)) then {
  125. if ((count (allMissionObjects "WeaponHolder")) > _weaponHolderLimit) then {
  126. while {(((count (allMissionObjects "WeaponHolder")) - _weaponHolderLimit) > 0)} do {
  127. deleteVehicle ((allMissionObjects "WeaponHolder") select 0);
  128. sleep 0.5;
  129. };
  130. } else {
  131. if (_weaponHolderDistCheck) then {
  132. {
  133. if ([_x,_weaponHolderDist,(playableUnits + switchableUnits)] call _isHidden) then {
  134. deleteVehicle _x;
  135. };
  136. } count (allMissionObjects "WeaponHolder");
  137. };
  138. };
  139. };
  140. sleep 1;
  141. //================================= MINES
  142. if (!(_minesLimit isEqualTo -1)) then {
  143. if ((count allMines) > _minesLimit) then {
  144. while {(((count allMines) - _minesLimit) > 0)} do {
  145. deleteVehicle (allMines select 0);
  146. sleep 0.5;
  147. };
  148. } else {
  149. if (_minesDistCheck) then {
  150. {
  151. if ([_x,_minesDist,allUnits] call _isHidden) then {
  152. deleteVehicle _x;
  153. };
  154. } count allMines;
  155. };
  156. };
  157. };
  158. sleep 1;
  159. //================================= STATIC WEAPONS
  160. if (!(_staticsLimit isEqualTo -1)) then {
  161. if ((count (allMissionObjects "StaticWeapon")) > _staticsLimit) then {
  162. while {(((count (allMissionObjects "StaticWeapon")) - _staticsLimit) > 0)} do {
  163. deleteVehicle ((allMissionObjects "StaticWeapon") select 0);
  164. sleep 0.5;
  165. };
  166. } else {
  167. if (_staticsDistCheck) then {
  168. {
  169. if ([_x,_staticsDist,allUnits] call _isHidden) then {
  170. deleteVehicle _x;
  171. };
  172. } count (allMissionObjects "StaticWeapon");
  173. };
  174. };
  175. };
  176. sleep 1;
  177. //================================= RUINS
  178. if (!(_ruinsLimit isEqualTo -1)) then {
  179. _ruins = [];
  180. {
  181. if ((_x distance [0,0,0]) > 100) then {
  182. 0 = _ruins pushBack _x;
  183. sleep 0.1;
  184. };
  185. } count (allMissionObjects "Ruins");
  186. if ((count _ruins) > _ruinsLimit) then {
  187. while {(((count _ruins) - _ruinsLimit) > 0)} do {
  188. _ruins resize (count _ruins - 1);
  189. deleteVehicle (_ruins select 0);
  190. sleep 0.5;
  191. };
  192. } else {
  193. if (_ruinsDistCheck) then {
  194. {
  195. if ([_x,_ruinsDist,(playableUnits + switchableUnits)] call _isHidden) then {
  196. deleteVehicle _x;
  197. };
  198. } count (allMissionObjects "Ruins");
  199. };
  200. };
  201. };
  202. sleep 1;
  203. //================================= ORPHANED MP TRIGGERS.
  204. if (_orphanedTriggers) then {
  205. {
  206. if ((_x distance [0,0,0]) < 1) then {
  207. deleteVehicle _x;
  208. };
  209. } count (allMissionObjects "EmptyDetector");
  210. };
  211. sleep 1;
  212. //================================= EMPTY GROUPS
  213. if (_emptyGroups) then {
  214. {
  215. if ((count units _x) isEqualTo 0) then {
  216. deleteGroup _x;
  217. };
  218. } count allGroups;
  219. };
  220. sleep 1;
  221. //================================= SLEEP
  222. if (_checkPlayerCount) then {
  223. if ((count (playableUnits + switchableUnits)) >= _playerThreshold) then {
  224. sleep _checkFrequencyAccelerated;
  225. } else {
  226. sleep _checkFrequencyDefault;
  227. };
  228. } else {
  229. sleep _checkFrequencyDefault;
  230. };
  231. };