From a34071bf86bc6b0b1f53b104dacff280c486c4e8 Mon Sep 17 00:00:00 2001
From: Chris Cardozo <cardocp@hotmail.com>
Date: Tue, 4 Dec 2018 05:45:15 -0500
Subject: [PATCH] Build 169

Fixed: Vehicles were being deleted at missions too quickly after crew were killed.
---
 .../Compiles/Functions/GMS_fnc_mainThread.sqf |   4 +
 .../Compiles/HC/GMS_fnc_HC_XferGroup.sqf      |   2 +-
 .../Compiles/HC/GMS_fnc_HC_XferVehicle.sqf    |   6 -
 .../Compiles/HC/GMS_fnc_HC_groupsAssigned.sqf |  19 ---
 ...fnc_HC_returnVehicleMonitoringToServer.sqf |  15 ---
 .../Compiles/HC/GMS_fnc_HC_vehicleMonitor.sqf | 108 ------------------
 .../Compiles/HC/GMS_fnc_HCmonitor.sqf         |  25 ----
 .../HC/GMS_fnc_onPlayerDisconnected.sqf       |  61 ----------
 .../Compiles/HC/GMS_fnc_passToHCs.sqf         |   4 +-
 .../Compiles/Missions/GMS_fnc_fillBoxes.sqf   |   4 +-
 .../Missions/GMS_fnc_loadMissionCrate.sqf     |   6 -
 .../Compiles/Units/GMS_fnc_cleanupAliveAI.sqf |   4 -
 .../GMS_fnc_placeCharacterInBuilding.sqf      |   2 +-
 .../GMS_fnc_releaseVehicleToPlayers.sqf       |  12 +-
 .../Vehicles/GMS_fnc_vehicleMonitor.sqf       | 103 ++++++++---------
 .../custom_server/Compiles/blck_functions.sqf |   5 +
 16 files changed, 68 insertions(+), 312 deletions(-)
 delete mode 100644 @GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferVehicle.sqf
 delete mode 100644 @GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_groupsAssigned.sqf
 delete mode 100644 @GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_returnVehicleMonitoringToServer.sqf
 delete mode 100644 @GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_vehicleMonitor.sqf
 delete mode 100644 @GMS/addons/custom_server/Compiles/HC/GMS_fnc_HCmonitor.sqf
 delete mode 100644 @GMS/addons/custom_server/Compiles/HC/GMS_fnc_onPlayerDisconnected.sqf

diff --git a/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_mainThread.sqf b/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_mainThread.sqf
index 7829f82..ce9de82 100644
--- a/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_mainThread.sqf
+++ b/@GMS/addons/custom_server/Compiles/Functions/GMS_fnc_mainThread.sqf
@@ -24,6 +24,10 @@ while {true} do
 	uiSleep 1;
 	if (diag_tickTime > _timer1sec) then 
 	{
+		[] call blck_fnc_vehicleMonitor;
+		#ifdef GRGserver
+		[] call blck_fnc_broadcastServerFPS;
+		#endif
 		_timer1sec = diag_tickTime + 1;
 	};
 	if (diag_tickTime > _timer5sec) then
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferGroup.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferGroup.sqf
index fa2cb7f..9d07f48 100644
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferGroup.sqf
+++ b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferGroup.sqf
@@ -16,4 +16,4 @@ _group = _this select 0;
 	_unit = _x;
 	_tempEH = _unit addEventHandler ["Reloaded", {_this call blck_EH_unitWeaponReloaded;}];
 }forEach (units _group);
-//diag_log format["blckHC:: group %1 transferred to HC %1",_group,_client];
\ No newline at end of file
+//diag_log format["blckHC:: group %1 transferred to HC %1",_group,clientOwner];
\ No newline at end of file
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferVehicle.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferVehicle.sqf
deleted file mode 100644
index d537858..0000000
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_XferVehicle.sqf
+++ /dev/null
@@ -1,6 +0,0 @@
-diag_log format["_fnc_HC_XferVehicle:: _this = %1",_this];
-private["_veh","_tempEH","_localEH"];
-_veh = _this select 0;
-_tempEH = ["HandleDamage",_veh addMPEventHandler["HandleDamage",{ [_this] call compile preprocessFileLineNumbers blck_EH_AIVehicle_HandleDamage}]];
-_localEH = [_tempEH];
-_veh setVariable["localEH",_tempEH,true];
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_groupsAssigned.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_groupsAssigned.sqf
deleted file mode 100644
index 0d1b3a2..0000000
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_groupsAssigned.sqf
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
-	Killed handler for _units
-	By Ghostrider-GRG-
-
-	--------------------------
-	License
-	--------------------------
-	All the code and information provided here is provided under an Attribution Non-Commercial ShareAlike 4.0 Commons License.
-
-	http://creativecommons.org/licenses/by-nc-sa/4.0/
-*/
-//#include "\q\addons\custom_server\Configs\blck_defines.hpp";
-
-private _clientId = clientOwner;
-private _groupsOwned = {groupOwner _x isEqualTo _clientId)} count allGroups;
-//diag_log format["_fnc_HC_groupsAssigned:: %1 groups running on client %2",_groupsOwned,_clientId];
-_groupsOwned
-//[_clientId,_groupsOwned] remoteExec ["blck_fnc_updateClientGroupCounts",2];
-
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_returnVehicleMonitoringToServer.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_returnVehicleMonitoringToServer.sqf
deleted file mode 100644
index ea97113..0000000
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_returnVehicleMonitoringToServer.sqf
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
-	By Ghostrider [GRG]
-	Copyright 2016
-	--------------------------
-	License
-	--------------------------
-	All the code and information provided here is provided under an Attribution Non-Commercial ShareAlike 4.0 Commons License.
-
-	http://creativecommons.org/licenses/by-nc-sa/4.0/
-*/
-#include "\q\addons\custom_server\Configs\blck_defines.hpp";
-
-params["_vehicle"];
-
-[_vehicle] remoteExec ["blck_fnc_monitorVehicleStatus",2];
\ No newline at end of file
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_vehicleMonitor.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_vehicleMonitor.sqf
deleted file mode 100644
index a3a9fd9..0000000
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HC_vehicleMonitor.sqf
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
-	By Ghostrider [GRG]
-	Copyright 2016
-	--------------------------
-	License
-	--------------------------
-	All the code and information provided here is provided under an Attribution Non-Commercial ShareAlike 4.0 Commons License.
-
-	http://creativecommons.org/licenses/by-nc-sa/4.0/
-*/
-#include "\q\addons\custom_server\Configs\blck_defines.hpp";
-
-//diag_log format["_fnc_vehicleMonitor: starting function at diag_tickTime = %1",diag_tickTime];
-
-#ifdef blck_debugMode
-	//diag_log format["_fnc_vehicleMonitor:: blck_debugMode defined"];
-#endif
-
-private ["_vehList","_veh","_isEmplaced","_ownerIsPlayer","_allCrewDead","_deleteNow","_missionCompleted","_evaluate","_cleanupTimer"];
-_vehList = +blck_HC_monitoredVehicles;
-
-#ifdef blck_debugMode
-if (blck_debugLevel > 2) then {diag_log format["_fnc_vehicleMonitor:: function called at %1 with _vehList %2 and blck_HC_monitoredVehicles %3",diag_tickTime,_vehList,blck_HC_monitoredVehicles];};
-#endif
-//diag_log format["_fnc_vehicleMonitor:: function called at %1 with _vehList %2 and blck_HC_monitoredVehicles %3",diag_tickTime,_vehList,blck_HC_monitoredVehicles];
-  //blck_fnc_releaseVehicleToPlayers
-{
-	/*
-		Determine state of vehicle
-		_isEmplaced
-		_ownerIsPlayer
-		_allCrewDead
-		_deleteNow
-	*/
-	//diag_log format["_fnc_vehicleMonitor: evaluating vehicle %1",_x];
-	_veh = _x; // (purely for clarity at this point, _x could be used just as well)
-	_isEmplaced = _veh getVariable["GRG_vehType","none"] isEqualTo "emplaced";
-	_ownerIsPlayer = if (owner _veh > 2 && !(owner _veh in blck_connectedHCs)) then {true} else {false};
-	{
-		//diag_log format["_fnc_vehicleMonitor: vehicle %1 crew %2 alive = %3",_veh,_x, alive _x];
-	}forEach (crew _veh);
-	_allCrewDead = if (({alive _x} count (crew _veh)) == 0) then {true} else {false};
-	//diag_log format["_fnc_vehicleMonitor: _allCrewDead = %1",_allCrewDead];
-	_deletenow = false;
-	if ( (_veh getVariable["blck_DeleteAt",0] > 0) && (diag_tickTime > (_veh getVariable "blck_DeleteAt"))) then {_deleteNow = true};
-	_missionCompleted = if (_veh getVariable["missionCompleted",0] != 0) then {true} else {false};
-	_evaluate = true;
-
-	if (_ownerIsPlayer) then
-	{
-		// disable further monitoring and mark to never be deleted.
-		_evaluate = false;
-		_veh setVariable["blck_DeleteAt",0];
-		blck_HC_monitoredVehicles = blck_HC_monitoredVehicles - [_veh];
-		//diag_log format["_fnc_vehicleMonitor: vehicle %1 now owned by player %2",_veh, owner _veh];	
-	};
-	
-	if (_allCrewDead && _evaluate) then
-	{
-		if (_isEmplaced) then
-		{
-			if (blck_killEmptyStaticWeapons) then
-			{
-				#ifdef blck_debugMode
-				if (blck_debugLevel > 2) then {diag_log format["_fnc_vehicleMonitor:: case of destroyed where vehicle = %1",_veh];};
-				#endif
-				_veh setDamage 1;
-				_veh setVariable["blck_DeleteAt",diag_tickTime + 60];
-			}else {
-				[_veh] call blck_fnc_releaseVehicleToPlayers;
-			};
-			_evaluate = false;		
-		} else {
-			if (blck_killEmptyAIVehicles) then
-			{
-				_veh setDamage 0.7;
-				_veh setVariable["blck_DeleteAt",diag_tickTime + 60];
-			} else {
-				//diag_log format["_fnc_vehicleMonitor:: case of RELEASE where vehicle = %1 and Vehicle is typeOf %2",_veh, typeOf _veh];
-				[_veh] call blck_fnc_releaseVehicleToPlayers;
-			};
-			_evaluate = false;		
-		};
-	};
-	
-	if (_missionCompleted && !(_allCrewDead)) then
-	{
-		//diag_log format["_fnc_vehicleMonitor:: case of mission vehicle with AI alive at mission end: schedule destruction with _veh = %1 and typeOf _veh = %2",_veh, typeOf _veh];
-		_cleanupTimer = _veh getVariable["blck_DeleteAt",0];  // The time delete to deleting any alive AI units
-		if (_cleanupTimer == 0) then {_veh setVariable["blck_DeleteAt",diag_tickTime + blck_vehicleDeleteTimer]};
-		_evaluate = false;
-	};
-	
-	if (_evaluate) then
-	{
-		[_veh] call blck_fnc_reloadVehicleAmmo;
-	};	
-	
-	if (_deleteNow) then
-	{
-		[_veh] call blck_fnc_destroyVehicleAndCrew;
-		_evaluate = false;	
-	};
-	
-}forEach _vehList;
-
-
-
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HCmonitor.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HCmonitor.sqf
deleted file mode 100644
index f21ef65..0000000
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_HCmonitor.sqf
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-	Killed handler for _units
-	By Ghostrider-GRG-
-
-	--------------------------
-	License
-	--------------------------
-	All the code and information provided here is provided under an Attribution Non-Commercial ShareAlike 4.0 Commons License.
-
-	http://creativecommons.org/licenses/by-nc-sa/4.0/
-*/
-//#include "\q\addons\custom_server\Configs\blck_defines.hpp";
-
-diag_log "_fnc_HC_monitor.sqf <RUNNING>";
- _blckGroups = 0;
- _otherGroups = 0;
- _totalGroups = 0;
- _timerOneSec =0;
- _timerSixtySec = 0;
- _timer3min = 0;
- while {true} do
- {
-
-	uiSleep 1;
- };
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_onPlayerDisconnected.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_onPlayerDisconnected.sqf
deleted file mode 100644
index 7414b90..0000000
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_onPlayerDisconnected.sqf
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-	Killed handler for _units
-	By Ghostrider-GRG-
-
-	--------------------------
-	License
-	--------------------------
-	All the code and information provided here is provided under an Attribution Non-Commercial ShareAlike 4.0 Commons License.
-
-	http://creativecommons.org/licenses/by-nc-sa/4.0/
-*/
-//#include "\q\addons\custom_server\Configs\blck_defines.hpp";
-
-params["_name","_owner"];
-//diag_log format["_fnc_onPlayerDisconnected triggered with _name = %1 and _owner = %2",_name,_owner];
-private["_HCownerids","_groupLocalEH","_vehicleLocalEH"];
-// Remove the name of the HC from the list of active, connected HCs
-if (toLower(_name) isEqualTo "headlessclient") then
-{
-	//diag_log "_fnc_onPlayerDisconnected: a headless client disconnected, time to deal with the damage";
-	_entities = entities "Headlessclient_F";
-	_blck_connectedHCs = +blck_connectedHCs;
-	_HCownerids = [];
-	{
-		if !(_x in _entities) then
-		{
-			// If the HC is not in the list of connected SC then delete it from the list maintained separately by blckeagls.
-			blck_connectedHCs = blck_connectedHCs - [_x];
-		} else {
-			// Grab the owner ids for currently connected HCs.
-			_HCownerids pushBack (owner _x);
-		};
-	}forEach _blck_connectedHCs;
-
-	// Check whether there are any groups assigned to an owner that is not connected and deal with it
-	{
-		if !(_x getVariable["owner",0] in _HCownerids) then
-		{
-			//diag_log format["_fnc_onPlayerDisconnected:: reseting eventHandlers for group %1",_x];
-			// do any cleanup; at present this is simply removing locally added event handlers
-			_groupLocalEH = _x getVariable["localEH",[]];
-			private _group = _x;
-			{
-				_group removeEventHandler (_x getVariable["localEH","Reloaded"]);
-			}forEach _groupLocalEH;
-			_x setVariable["localEH",nil,true];
-		};
-	}forEach allGroups;
-	{
-		if !(_x getVariable["owner",0] in _HCownerids) then
-		{
-			//diag_log format["_fnc_onPlayerDisconnected:: reseting eventHandlers for vehicle %1",_x];
-			// do any cleanup; at present this is simply removing locally added event handlers
-			_vehicleLocalEH = _x getVariable["localEH",[]];
-			{
-				_x removeEventHandler _x;
-			}forEach _vehicleLocalEH;	
-			_x setVariable["localEH",nil,true];			
-		};
-	}forEach blck_monitoredVehicles;	
-};
\ No newline at end of file
diff --git a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_passToHCs.sqf b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_passToHCs.sqf
index 45284f9..32d628e 100644
--- a/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_passToHCs.sqf
+++ b/@GMS/addons/custom_server/Compiles/HC/GMS_fnc_passToHCs.sqf
@@ -20,7 +20,7 @@ blck_fnc_countGroupsAssigned = {
 };
 
 private["_numTransfered","_clientId","_allGroups","_groupsOwned","_idHC","_id","_swap","_rc"];
-//_numTransfered = 0;
+_numTransfered = 0;
 _idHC = -2;
 blck_connectedHCs = entities "HeadlessClient_F";  
 //diag_log format["_fnc_passToHCs:: blck_connectedHCs = %1 | count _HCs = %2 | server FPS = %3",blck_connectedHCs,count blck_connectedHCs,diag_fps];
@@ -36,7 +36,7 @@ if !(blck_connectedHCs isEqualTo []) then
 				if (_sgor) then
 				{
 					[_x] remoteExec["blck_fnc_HC_XferGroup",_idHC];
-					//_numTransfered = _numTransfered + 1;
+					_numTransfered = _numTransfered + 1;
 				};
 			};
 		};
diff --git a/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_fillBoxes.sqf b/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_fillBoxes.sqf
index a68aa50..6b1cea3 100644
--- a/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_fillBoxes.sqf
+++ b/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_fillBoxes.sqf
@@ -1,9 +1,7 @@
 
 /*
-	for ghostridergaming
 	By Ghostrider [GRG]
-	Fill a crate with items
-	
+
 	--------------------------
 	License
 	--------------------------
diff --git a/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_loadMissionCrate.sqf b/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_loadMissionCrate.sqf
index 2a32c4e..e96b37e 100644
--- a/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_loadMissionCrate.sqf
+++ b/@GMS/addons/custom_server/Compiles/Missions/GMS_fnc_loadMissionCrate.sqf
@@ -8,12 +8,6 @@
 */
 #include "\q\addons\custom_server\Configs\blck_defines.hpp";
 private _crate = _this select 0;
-#ifdef blck_debugMode
-diag_log format["_fnc_loadMisionLootcrate: _this = %1",_this];
-diag_log format["_fnc_loadMisionLootcrate: difficulty = %1", _crate getVariable "difficulty"];
-diag_log format["_fnc_loadMisionLootcrate: lootCounts = %1", _crate getVariable "lootCounts"];
-diag_log format["_fnc_loadMisionLootcrate: lootArray = %1",_crate getVariable "lootArray"];
-#endif
 [_crate,(_crate getVariable "lootArray"),(_crate getVariable "lootCounts")] call blck_fnc_fillBoxes;
 [_crate, _crate getVariable "difficulty"] call blck_fnc_addMoneyToObject;
 _crate setVariable["lootLoaded",true];
diff --git a/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_cleanupAliveAI.sqf b/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_cleanupAliveAI.sqf
index c600cb4..be042cd 100644
--- a/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_cleanupAliveAI.sqf
+++ b/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_cleanupAliveAI.sqf
@@ -24,10 +24,6 @@ for "_i" from 1 to (count blck_liveMissionAI) do {
 				};
 				[_x] call blck_fnc_deleteAI;
 			} forEach _unitsarr;
-			uiSleep 0.1;
-			#ifdef blck_debugMode
-			if (blck_debugLevel > 1) then {diag_log format["_fnc_mainTread:: blck_liveMissionAI updated to %1",blck_liveMissionAI];};
-			#endif
 		}
 		else {
 			blck_liveMissionAI pushback _units;
diff --git a/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_placeCharacterInBuilding.sqf b/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_placeCharacterInBuilding.sqf
index 1cafabb..e6f2ece 100644
--- a/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_placeCharacterInBuilding.sqf
+++ b/@GMS/addons/custom_server/Compiles/Units/GMS_fnc_placeCharacterInBuilding.sqf
@@ -16,7 +16,7 @@ private ["_obj"];
 if !(_characterBuildingConfigs isEqualTo []) then
 {
 	_obj = createVehicle[(_characterBuildingConfigs select 0),_center vectorAdd (_characterBuildingConfigs select 1),[],0,"CAN_COLLIDE"];
-	//diag_log format["_fnc_placeCharacterInBuilding:  _obj = %1",_obj];
+	diag_log format["_fnc_placeCharacterInBuilding:  _obj = %1",_obj];
 	_obj setDir (_characterBuildingConfigs select 2);
 	_obj allowDamage true;
 	_obj enableDynamicSimulation true;		
diff --git a/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_releaseVehicleToPlayers.sqf b/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_releaseVehicleToPlayers.sqf
index 96b0c8d..feea774 100644
--- a/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_releaseVehicleToPlayers.sqf
+++ b/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_releaseVehicleToPlayers.sqf
@@ -1,8 +1,7 @@
 
 /*
-	Killed handler for _units
 	By Ghostrider-GRG-
-
+	And Ignatz-HeMan
 	--------------------------
 	License
 	--------------------------
@@ -10,12 +9,10 @@
 
 	http://creativecommons.org/licenses/by-nc-sa/4.0/
 */
-//  Needs optimization for headless clients
+
 #include "\q\addons\custom_server\Configs\blck_defines.hpp";
 
 	params["_veh"];
-	blck_monitoredVehicles = blck_monitoredVehicles - [_veh];
-	//diag_log format["_fnc_releaseVehicleToPlayersl: _veh = %1 | isLocal _veh = %3 | (owner _veh) = %2",_veh,(owner _veh),Local _veh];
     if (local _veh) then {
         _veh lock false;
     }
@@ -27,12 +24,11 @@
             [[_veh,false],["lock",_veh]] remoteExecCall ["remoteExecCall", 2];    // If run on HC, move to the server. Server will remoteexec on local machine
         };
     };
-	//diag_log format["_fnc_releaseVehicleToPlayers: _veh=%1 | owner = %2 | lock = %3",_veh,owner _veh, locked _veh];
+
 	{
 		_veh removealleventhandlers _x;
 	} forEach ["GetIn","GetOut","fired","hit","hitpart","reloaded","dammaged","HandleDamage"];
 	{
 		_veh removeAllMPEventHandlers _x;
 	} forEach ["MPHit","MPKilled"];
-	_veh setVariable["blck_DeleteAt",nil];
-	if ((damage _veh) > 0.6) then {_veh setDamage 0.6};
+	if ((damage _veh) > 0.6) then {_veh setDamage 0.6};  //  So they don't blow up when a player tries to get in.
diff --git a/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_vehicleMonitor.sqf b/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_vehicleMonitor.sqf
index e235c8e..51d8004 100644
--- a/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_vehicleMonitor.sqf
+++ b/@GMS/addons/custom_server/Compiles/Vehicles/GMS_fnc_vehicleMonitor.sqf
@@ -11,64 +11,61 @@
 */
 #include "\q\addons\custom_server\Configs\blck_defines.hpp";
 
-private ["_vehList"];
-_vehList = +blck_monitoredVehicles;
-
-//diag_log format["_fnc_vehicleMonitor:: function called at %1 with _vehList %2 ",diag_tickTime,_vehList,blck_monitoredVehicles];
-
+//diag_log format["_fnc_vehicleMonitor:: function called at %1 with _vehList %2 ",diag_tickTime,blck_monitoredVehicles];
+private _serverIDs =  ([2] + (entities "HeadlessClient_F"));
+for "_i" from 1 to (count blck_monitoredVehicles) do
 {
-	private["_veh","_isEmplaced","_allCrewDead","_evaluate","_deleteAtTime"];
-	_veh = _x; // (purely for clarity at this point, _x could be used just as well)
-	
-	_isEmplaced = _veh getVariable["GRG_vehType","none"] isEqualTo "emplaced";
-	_allCrewDead = {alive _x} count (crew _veh) == 0;
-	_evaluate = 0;
-	_deleteAtTime = _veh getVariable ["blck_deleteAtTime",diag_tickTime + 1];
-
-	if (diag_tickTime > _deleteAtTime) then 
+	if (_i > (count blck_monitoredVehicles)) exitWith {};
+	private _veh = blck_monitoredVehicles deleteAt 0;
+	if !(_veh isEqualTo objNull) then
 	{
-		_evaluate = 3;
-	} else {
-		if (_allCrewDead) then
+		// if the owner is a player do not add back for further monitoring
+		if ((owner _veh) in (_serverIDs)) then 
 		{
-			_evaluate = if (_isEmplaced) then {1} else {2};
-		};
-	};
-
-	//diag_log format["_fnc_vehicleMonitor: vehicle = %1 | owner = %2 | crew = %3 | _evaluate = %4",_veh, owner _veh, {alive _x} count (crew _veh), _evaluate];
-	switch (_evaluate) do
-	{
-		case 0:{[_veh] call blck_fnc_reloadVehicleAmmo;};
-		case 1:{
-			if (blck_killEmptyStaticWeapons) then
+			//diag_log format["_fnc_vehicleMonitor: vehicle %1 to be deleted at %2",_veh,(_veh getVariable ["blck_deleteAtTime",0])];
+			if ((_veh getVariable ["blck_deleteAtTime",0]) > 0) then
 			{
-				if (blck_debugLevel > 2) then {diag_log format["_fnc_vehicleMonitor:: case of destroyed where vehicle = %1",_veh];};
-				_veh setDamage 1;
-				_veh setVariable["blck_deleteAtTime",diag_tickTime + 60];
-			}else {
-				//diag_log format["_fnc_vehicleMonitor: calling _fnc_releaseVehicleToPlayers for vehicle %1",_veh];
-				[_veh] call blck_fnc_releaseVehicleToPlayers;
-			};
-		};
-		case 2:{
-			if (blck_killEmptyAIVehicles) then
-			{
-				//if (blck_debugLevel > 2) then {diag_log format["_fnc_vehicleMonitor:: case of destroyed where vehicle = %1",_veh];};
-				_veh setDamage 0.7;
-				_veh setFuel 0;
-				_veh setVariable["blck_deleteAtTime",diag_tickTime + 60];
+				if (diag_tickTime > ( _veh getVariable ["blck_deleteAtTime",0])) then
+				{
+					//diag_log format["_fnc_vehicleMonitor: deleting vehicle and crew for %1",_veh];
+					[_veh] call blck_fnc_destroyVehicleAndCrew;				
+				} else {
+					blck_monitoredVehicles pushBack _veh;
+				};
 			} else {
-				//diag_log format["_fnc_vehicleMonitor: calling _fnc_releaseVehicleToPlayers for vehicle %1",_veh];					
-				[_veh] call blck_fnc_releaseVehicleToPlayers;
+				if ({alive _veh} count (crew _veh) == 0) then
+				{	
+					if (_veh getVariable["GRG_vehType","none"] isEqualTo "emplaced") then
+					{
+						if (blck_killEmptyStaticWeapons) then
+						{
+							//diag_log format["_fnc_vehicleMonitor: disabling static %1 and setting its delete time",_veh];
+							_veh setDamage 1;
+							_veh setVariable["blck_deleteAtTime",diag_tickTime + 60,true];
+						}else {
+							//diag_log format["_fnc_vehicleMonitor: releasing static %1 to players and setting a default delete timer",_veh];
+							[_veh] call blck_fnc_releaseVehicleToPlayers;
+							_veh setVariable["blck_DeleteAt",diag_tickTime + blck_vehicleDeleteTimer,true];
+						};			
+					} else {
+						if (blck_killEmptyAIVehicles) then
+						{
+							//diag_log format["_fnc_vehicleMonitor: disabling vehicle %1 and setting a delete time",_veh];
+							_veh setDamage 0.7;
+							_veh setFuel 0;
+							_veh setVariable["blck_deleteAtTime",diag_tickTime + 60];
+						} else {
+							//diag_log format["-------->_fnc_vehicleMonitor: releasing vehicle %1 to players and setting a default delete timer",_veh];
+							_veh setVariable["blck_deleteAtTime",diag_tickTime + blck_vehicleDeleteTimer,true];	
+							[_veh] call blck_fnc_releaseVehicleToPlayers;
+						};
+					};
+					
+				};
+				blck_monitoredVehicles pushBack _veh;
 			};
+		} else {
+			//diag_log format["_fnc_vehicleMonitor:  owner of vehicle %1 is a player, discontinuing further monitoring",_veh];
 		};
-		case 3:{
-			//diag_log format["_fnc_releaseVehicleToPlayers: destroying vehicle and crew for vehicle %1 at time %2",_veh,diag_tickTime];
-			[_veh] call blck_fnc_destroyVehicleAndCrew;				
-		};
-
 	};
-}forEach _vehList;
-
-
-
+};
diff --git a/@GMS/addons/custom_server/Compiles/blck_functions.sqf b/@GMS/addons/custom_server/Compiles/blck_functions.sqf
index 8bd2c70..bb37e92 100644
--- a/@GMS/addons/custom_server/Compiles/blck_functions.sqf
+++ b/@GMS/addons/custom_server/Compiles/blck_functions.sqf
@@ -163,6 +163,11 @@ private _functions = [
 	missionnamespace setvariable [_name,compileFinal  preprocessFileLineNumbers _path];
 } foreach  _functions;
 
+#ifdef GRGserver	
+blck_fnc_broadcastServerFPS = compileFinal  preprocessFileLineNumbers "\q\addons\custom_server\Compiles\Functions\GMS_fnc_broadcastServerFPS.sqf"; 
+diag_log "blck_functions loaded using GRGserver settings ---- >>>> ";
+#endif
+
 onPlayerDisconnected {[_name,_owner] call blck_fnc_onPlayerDisconnected;};