fnc_jammersUpdateServer.sqf 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. localNamespace setVariable["rd501_jammers_previousUpdate", _jammers];
  23. diag_log format["[RD501 Jammers][Server Update] Updated jammers to '%1'", _jammers];
  24. diag_log "[RD501 Jammers][Server Update] Broadcasting Delta";
  25. [
  26. "rd501_jammersUpdateLocal",
  27. [_jammers]
  28. ] call CBA_fnc_globalEvent;
  29. // Update the JIP jammer list to match ingame
  30. private _jipId = localNamespace getVariable ["rd501_jammers_jipId", -1];
  31. if(_jipId isEqualTo -1) exitWith {
  32. _jipId = ["rd501_jammersUpdateLocal", [_jammers]] call CBA_fnc_globalEventJIP;
  33. localNamespace setVariable ["rd501_jammers_jipId", _jipId];
  34. diag_log format["[RD501 Jammers][Server Update] Added JIP with id '%1' and jammers '%2'", _jipId, _jammers];
  35. };
  36. // Reuse old jip var with new jammers each time updated
  37. ["rd501_jammersUpdateLocal", [_jammers], _jipId] call CBA_fnc_globalEventJIP;
  38. diag_log format["[RD501 Jammers][Server Update] Updated JIP with id '%1' and jammers '%2'", _jipId, _jammers];