Browse Source

Fix server side jammer cleanup

m3ales 4 years ago
parent
commit
c4fafb4679

+ 6 - 0
addons - Copy/RD501_Main/XEH_postinit.sqf

@@ -73,4 +73,10 @@ call macro_fnc_name(stun);
 // Jammers
 ["rd501_addJammerLocal", {
 	_this call rd501_fnc_addJammerLocal
+}] call CBA_fnc_addEventHandler;
+
+["rd501_jammerServerPFH", {
+	[{
+		_this call rd501_fnc_jammersServerPFH
+	}, 1] call CBA_fnc_addPerFrameHandler;
 }] call CBA_fnc_addEventHandler;

+ 3 - 3
addons - Copy/RD501_Main/functions/jammer/fnc_addJammer.sqf

@@ -1,11 +1,11 @@
 params["_jammer", ["_radius", 300], ["_strength", 400]];
 
 _jammers = missionNamespace getVariable ["rd501_jammers",[]];
+
 _jammers pushBack [_jammer, _radius, _strength];
+
 missionNamespace setVariable ["rd501_jammers",_jammers, true];
 
-params["_jammer", "_radius", "_strength"];
 _jipId = ["rd501_addJammerLocal", [_jammer, _radius, _strength]] call CBA_fnc_globalEventJIP;
 _jammer setVariable ["rd501_jammer_jipId", _jipId, true];
-
-[{ _this call rd501_jammersServerPFH }, 1, [_jammer, _radius, _strength]] call CBA_fnc_addPerFrameHandler;
+["rd501_jammerServerPFH", []] call CBA_fnc_serverEvent;

+ 1 - 2
addons - Copy/RD501_Main/functions/jammer/fnc_addJammerLocal.sqf

@@ -1,6 +1,5 @@
 params["_jammer", "_radius", "_strength"];
-if(isDedicated || !hasInterface) exitWith {
-};
+if(isDedicated || !hasInterface) exitWith { };
 systemChat "Adding Jammer Local";
 if(player getVariable ["rd501_jammers_pfh", -1] == -1) exitWith {
 	systemChat "Adding Client Per Frame Handler";

+ 0 - 1
addons - Copy/RD501_Main/functions/jammer/fnc_jammersPFH.sqf

@@ -6,7 +6,6 @@ _args params["_player"];
 *		["bis_o1", 1000, 400]
 *	];
 */
-systemChat "Server PFH";
 if(!alive _player) exitWith { systemChat format["Player dead for %1", _handle] };
 
 _jammers = missionNamespace getVariable ["rd501_jammers",[]];

+ 16 - 14
addons - Copy/RD501_Main/functions/jammer/fnc_jammersServerPFH.sqf

@@ -4,25 +4,27 @@ if(!isServer) exitWith {
 	[_handle] call CBA_fnc_removePerFrameHandler;
 };
 
-private _jammers = missionNamespace getVariable ["rd501_jammers",[]]; 
+diag_log "Server PFH";
+private _jammers = missionNamespace getVariable ["rd501_jammers",[]];
  
-private _toRemove = []; 
-{ 
-	_x params["_jammer", "_radius", "_strength"]; 
-	systemChat format["%1 -- %2", _jammer, _radius];
-	_jipId = _jammer getVariable ["rd501_jammer_jipId", -1]; 
-	if(_jammer == objNull || !(alive _jammer)) then { 
-	 	_toRemove pushBack _x;
-		 if(_jipId != 1) then {
+{
+	_x params["_jammer", "_radius", "_strength"];
+	diag_log format["Reading %1",_x];
+	if(_jammer isEqualTo objNull || !(alive _jammer)) then {
+		diag_log format["Removing Jammer %1",_jammer];
+		_jipId = _jammer getVariable ["rd501_jammer_jipId", -1];
+	 	_jammers set [_foreachIndex, []];
+		 if(_jipId != -1) then {
  			[_jipId] call CBA_fnc_removeGlobalEventJIP;
 		};
-	}; 
-} forEach _jammers; 
+	};
+} forEach _jammers;
 
-_jammers = _jammers - _toRemove;
-missionNamespace setVariable ["rd501_jammers", _jammers, true]; 
+_jammers = _jammers - [[]];
+
+missionNamespace setVariable ["rd501_jammers", _jammers, true];
 
 if(count _jammers == 0) exitWith {
-	systemChat "Exiting Server PFH";
+	diag_log "Exiting Server PFH";
 	[_handle] call CBA_fnc_removePerFrameHandler;
 };