Functions_SCFramework.SQF 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. Functions_SCFramework.SQF
  3. External file containing useful functions that can be called from server, any headless client, and any player client
  4. */
  5. // Create group that never returns NULL
  6. Fnc_SCFramework_CreateGroup = {
  7. private ["_Group","_Side","_Variable"];
  8. _Side = _this select 0;
  9. _Variable = "";
  10. if (count _this > 1) then {
  11. _Variable = _this select 1;
  12. };
  13. _RunCreationLoop = true;
  14. _Center = createCenter _Side;
  15. sleep 0.1;
  16. while {_RunCreationLoop} do {
  17. _Group = createGroup [_Side,true];
  18. if (!isNull _Group) then {
  19. _RunCreationLoop = false;
  20. };
  21. sleep 0.1;
  22. };
  23. if (_Variable != "") then {
  24. _Group setVariable [_Variable,true,true];
  25. };
  26. _Group setVariable ["SpawnTime",time,true]; // Config_SCFramework
  27. diag_log format["(SCFramework) Fnc_SCFramework_CreateGroup: Group %1 %2 created.",_Group,_Side];
  28. _Group
  29. };
  30. // Remove specified element from an array - Returns array
  31. Fnc_SCFramework_DeleteArrayElement = {
  32. _Array = _this select 0;
  33. _Element = _this select 1;
  34. _Count = 0;
  35. {
  36. if (_x == _Element) then {
  37. _Array deleteAt _Count;
  38. };
  39. _Count = _Count + 1;
  40. } forEach _Array;
  41. _Array
  42. };
  43. // Remove duplicate elements and sort array alphabetically
  44. Fnc_SCFramework_CleanArray = {
  45. _Array = _this select 0;
  46. _TArray = [];
  47. {
  48. _TArray pushBackUnique _x;
  49. } forEach _Array;
  50. _TArray sort true;
  51. _Arra = _TArray;
  52. _Array
  53. };
  54. // Called from any module that needs to spawn a vehicle within a certain radius of a specified point on a road; will increment radius per 100m until suitable road is found and then will return that position
  55. Fnc_SCFramework_FindRoadPos = {
  56. _SpawnPos = _this select 0;
  57. _Radius = _this select 1;
  58. // Correct if radius is too small
  59. if (_Radius <= 100) then { _Radius = 100; };
  60. _FoundRoad = false;
  61. _RunLoop = true;
  62. _SearchRadius = 0;
  63. while {_RunLoop} do {
  64. // Work in increments of 100
  65. _SearchRadius = _SearchRadius + 100;
  66. _NearRoads = _SpawnPos nearRoads _SearchRadius;
  67. if (count _NearRoads > 0) then {
  68. _Road = _NearRoads call BIS_fnc_SelectRandom;
  69. _FoundRoad = true;
  70. _SpawnPos = getPos _Road;
  71. diag_log format["(SCFramework) Fnc_SCFramework_FindRoadPos: Found suitable spawn position on road at %1",_SpawnPos];
  72. };
  73. if (_FoundRoad) then {
  74. _RunLoop = false;
  75. };
  76. if (_SearchRadius > _Radius) then {
  77. _RunLoop = false;
  78. };
  79. sleep 0.05;
  80. };
  81. if (!_FoundRoad) then {
  82. diag_log format["(SCFramework) Fnc_SCFramework_FindRoadPos: Failed to find road from given position %1 and radius %2. Returning original position.",_SpawnPos,_Radius];
  83. };
  84. _SpawnPos
  85. };
  86. // Completely strip a unit of all of its gear
  87. Fnc_SCFramework_ClearUnit = {
  88. _Unit = _this select 0;
  89. _Unit unlinkItem (goggles player);
  90. removeAllWeapons _Unit;
  91. removeAllItems _Unit;
  92. removeAllItemsWithMagazines _Unit;
  93. removeVest _Unit;
  94. removeHeadgear _Unit;
  95. removeBackpack _Unit;
  96. removeUniform _Unit;
  97. removeGoggles _Unit;
  98. };
  99. // Set fuel on a vehicle EH
  100. "Fnc_SCFramework_SetFuel" addPublicVariableEventHandler {
  101. _Array = _this select 1;
  102. _Vehicle = _Array select 0;
  103. _Fuel = _Array select 1;
  104. if (local _Vehicle && alive _Vehicle) then {
  105. _Vehicle setFuel _Fuel;
  106. diag_log format["(SCFramework) Setting local vehicle %1 %2 fuel to %3.",_Vehicle,typeOf _Vehicle,_Fuel];
  107. };
  108. };
  109. // Set Fuel, Repair, and Reammo Cargo EH
  110. "Fnc_SCFramework_SetCargo" addPublicVariableEventHandler {
  111. _Array = _this select 1;
  112. _Vehicle = _Array select 0;
  113. _CargoType = _Array select 1;
  114. _CargoAmt = _Array select 2;
  115. if (local _Vehicle && alive _Vehicle) then {
  116. // Determine cargo type: Fuel = 1, Repair = 2, Reammo = 3
  117. switch (_CargoType) do {
  118. case 1: {
  119. _Vehicle setFuelCargo _CargoAmt;
  120. diag_log format["(SCFramework) Setting local vehicle %1 %2 fuel cargo to %3.",_Vehicle,typeOf _Vehicle,_CargoAmt];
  121. };
  122. case 2: {
  123. _Vehicle setRepairCargo _CargoAmt;
  124. diag_log format["(SCFramework) Setting local vehicle %1 %2 repair cargo to %3.",_Vehicle,typeOf _Vehicle,_CargoAmt];
  125. };
  126. case 3: {
  127. _Vehicle setAmmoCargo _CargoAmt;
  128. diag_log format["(SCFramework) Setting local vehicle %1 %2 ammo cargo to %3.",_Vehicle,typeOf _Vehicle,_CargoAmt];
  129. };
  130. };
  131. };
  132. };
  133. diag_log format["Functions_SCFramework.SQF: Functions loaded."];