Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. // [Group, Side] call NEKY_AI_ShareInfo;
  2. //
  3. // 1. Group
  4. // a) If you enter a group, that group will be applied the "Share Info" function. It will share info with other AI of the same side.
  5. // b) If you enter TRUE this function will apply this function to all AI units currently in the mission (After a 10sec delay). This is usually for mission start to add all editor placed units.
  6. // c) If you enter FALSE this function will remove the function from AI present in the mission.
  7. // d) Defaults to GrpNull, aka does nothing.
  8. // 2. Side
  9. // a) This parameter selects what sides you want to effect.
  10. // b) True = BLUFOR, OPFOR and INDEPENDENT sides.
  11. // c) Specific side selected by typing BLUFOR, OPFOR or INDEPENDENT.
  12. // d) Does nothing if a Param 1 is a group.
  13. //
  14. // This function makes AI share information between other squads to make AI feel more responsive and less derpy.
  15. //
  16. // Made by NeKo-ArroW
  17. // Version 0.91
  18.  
  19. if (!isServer && HasInterface) exitWith {}; // Exit everyone but HC and Server.
  20.  
  21. Private ["_Code","_Groups"];
  22.  
  23. Params
  24. [
  25. ["_Group", GrpNull, [GrpNull, True]],
  26. ["_Side", False, [True, SideUnknown]]
  27. ];
  28.  
  29. // Exits
  30. if (_Group isEqualTo GrpNull) exitWith {SystemChat "ERROR: NEKY_CombatExperience_AI_ShareInfo - No group selected."};
  31.  
  32. if (Time < 10) then {Sleep 10};
  33.  
  34. #include "..\Settings.sqf";
  35.  
  36. // Select Groups
  37. if (TypeName _Group == "BOOL") then
  38. {
  39. if (_Group) then // Add EH to all units
  40. {
  41. _Sides = [[_Side], [BLUFOR, OPFOR, RESISTANCE]] select (TypeName _Side == "BOOL");
  42. _Groups = AllGroups select { ((Side _x) in _Sides) && ({ isPlayer _x } Count (Units _x) == 0) && ((Units _x#0) isKindOf "CAMANBase") && !(_x getVariable ["NEKY_AI_ShareInfo_Added",False]) };
  43. } else { // Remove EH from all units of specific side.
  44. _Sides = [[_Side], [BLUFOR, OPFOR, RESISTANCE]] select (TypeName _Side == "BOOL");
  45. _Groups = AllGroups select { ((Side _x) in _Sides) && ({ isPlayer _x } count (Units _x) == 0) && ((Units _x#0) isKindOf "CAMANBase") && (_x getVariable ["NEKY_AI_ShareInfo_Added",False]) };
  46. _Code =
  47. {
  48. _This#0 setVariable ["NEKY_AI_ShareInfo_Added",False,True];
  49. _EH = _This#0 getVariable ["NEKY_AI_ShareInfo_EH",True];
  50. if (TypeName _EH == "NUMBER") then { _This#0 removeEventHandler ["FiredMan",_EH] };
  51. _This#0 setVariable ["NEKY_AI_ShareInfo_EH",nil,True];
  52. };
  53. };
  54. } else { _Groups = [_Group] };
  55.  
  56. if (isNil "_Code") then
  57. {
  58. _Code =
  59. {
  60. _EH = _This#0 addEventHandler ["FiredMan",
  61. {
  62. Params ["_Unit"];
  63. _Group = Group _Unit;
  64.  
  65. // Exit
  66. if (_Group getVariable ["NEKY_AI_ShareInfo_Reported",false]) exitWith {};
  67.  
  68. // Set variables
  69. _Group setVariable ["NEKY_AI_ShareInfo_Reported",true,true];
  70. [_Group] spawn {Sleep (30+ (random 10)); _This#0 setVariable ["NEKY_AI_ShareInfo_Reported",false,true]};
  71.  
  72. // Delay for unit to report in, unreal for unit to instantly send info.
  73. [_Group,_Unit] Spawn
  74. {
  75. Params ["_Group","_Unit"];
  76. Sleep (4 + (Random 4));
  77.  
  78. if !(Alive _Unit) exitWith { _Group setVariable ["NEKY_AI_ShareInfo_Reported",False,true] };
  79.  
  80. // Define variables
  81. _Side = Side _Group;
  82. _Sides = [WEST,EAST,RESISTANCE] - [_Side];
  83. _FriendlySides = [_Side];
  84. { if ((_Side getFriend _x) >= 0.6) then {_FriendlySides pushBack _x} } forEach _Sides;
  85. _Near = _Unit nearEntities [["Man","LandVehicle"],NEKY_AI_ShareRange];
  86. _NearFriendlies = (_Near select { (Side _x) in _FriendlySides });
  87. if (Count _NearFriendlies == 0) exitWith { };
  88.  
  89. _NearFriendliesGroups = [];
  90. { _NearFriendliesGroups pushBackUnique (Group _x) } forEach _NearFriendlies;
  91.  
  92. _NearEnemies = (_Near - _NearFriendlies) select {(_Group knowsAbout _x) != 0};
  93. if (Count _NearEnemies == 0) exitWith { };
  94.  
  95. _NearEnemies = _NearEnemies Apply { [_x, _Group knowsAbout _x] };
  96.  
  97. // Report all known enemies to friendlies.
  98. {
  99. _FriendlyGroup = _x;
  100. {
  101. _Quality = LinearConversion [0, 1500, ((Units _FriendlyGroup#0) distance2D _Unit), (_x#1 * NEKY_AI_ShareQuality#1), NEKY_AI_ShareQuality#0, false];
  102. _FriendlyGroup Reveal [_x#0, _Quality];
  103. } forEach _NearEnemies; // _x == ["_Enemy","_Knowledge"] No need for if, can't downrate knowledge, it only takes more perf to if (knowsmore) then... than to just do it.
  104. } forEach _NearFriendliesGroups;
  105. };
  106. }];
  107. _This#0 setVariable ["NEKY_AI_ShareInfo_EH",_EH,true];
  108. };
  109. };
  110.  
  111. // Set Variables, add EH
  112. {
  113. _Group = _x;
  114. _Group setVariable ["NEKY_AI_ShareInfo_Added",True,True];
  115. _Units = Units _x;
  116. {
  117. [[_x],_Code] remoteExec ["BIS_FNC_CALL",_x];
  118. } forEach _Units;
  119. } forEach _Groups;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement