fnc_jammersUpdateServer.sqf 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. params["_jammers"];
  2. if(!isServer) exitWith { diag_log "[RD501 Jammers] Attempted to update from a non server context"; };
  3. //if previous update has happened before
  4. //and if the current update is equivalent to it, skip
  5. private _previousUpdate = localNamespace getVariable["rd501_jammers",-1];
  6. private _shouldSkip = !(_previousUpdate isEqualTo -1);
  7. if(_shouldSkip) then {
  8. if(count _previousUpdate isEqualTo count _jammers) exitWith
  9. {
  10. {
  11. private _previous = _previousUpdate select _foreachIndex;
  12. private _current = _x;
  13. if!(_previous isEqualTo _current) exitWith
  14. {
  15. _shouldSkip = false;
  16. }
  17. }foreach(_jammers);
  18. };
  19. _shouldSkip = false;
  20. };
  21. if(_shouldSkip) exitWith { };
  22. diag_log "[RD501 Jammers] Broadcasting Delta";
  23. localNamespace setVariable["rd501_jammers_previousUpdate", _jammers];
  24. [
  25. "rd501_jammersUpdateLocal",
  26. [_jammers]
  27. ] call CBA_fnc_globalEvent;
  28. // Update the JIP jammer list to match ingame
  29. private _jipId = localNamespace getVariable ["rd501_jammers_jipId", -1];
  30. if(_jipId isEqualTo -1) exitWith {
  31. _jipId = ["rd501_jammersUpdateLocal", [_jammers]] call CBA_fnc_globalEventJIP;
  32. localNamespace setVariable ["rd501_jammers_jipId", _jipId];
  33. diag_log format["[RD501 Jammers] Added JIP with handle '%1' and jammers '%2'", _jipId, _jammers];
  34. };
  35. // Reuse old jip var with new jammers each time updated
  36. ["rd501_jammersUpdateLocal", [_jammers], _jipId] call CBA_fnc_globalEventJIP;
  37. diag_log format["[RD501 Jammers] Updated JIP with handle '%1' and jammers '%2'", _jipId, _jammers];