From e6f52e06854c52f085e0335bef4437ae19104b3e Mon Sep 17 00:00:00 2001 From: Ravenger2709 <37582773+Ravenger2709@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:11:54 +0300 Subject: [PATCH] Batch zombie monitoring and cache players --- database/ZombieKill.sql | 5 +- database/extDB2/exile.ini | 4 +- database/extDB3/exile.ini | 4 +- exilez_mod/config.sqf | 2 + exilez_mod/init/fn_postInit.sqf | 7 +- exilez_mod/init/fn_preInit.sqf | 3 + exilez_mod/scripts/HarassingZombiesThread.sqf | 5 +- exilez_mod/scripts/HordeThread.sqf | 8 +- exilez_mod/scripts/RefreshPlayerCache.sqf | 16 +++ exilez_mod/scripts/VerifyLocation.sqf | 9 +- exilez_mod/scripts/ZombieMonitor.sqf | 128 ++++++------------ 11 files changed, 82 insertions(+), 109 deletions(-) create mode 100644 exilez_mod/scripts/RefreshPlayerCache.sqf diff --git a/database/ZombieKill.sql b/database/ZombieKill.sql index 171c238..58ee89f 100644 --- a/database/ZombieKill.sql +++ b/database/ZombieKill.sql @@ -1,7 +1,8 @@ /* * - * Add the zedkills field + * Add the zombie kill counter used by addAccountZombieKill. * */ -ALTER TABLE account ADD zedkills int(11) DEFAULT '0' \ No newline at end of file +ALTER TABLE account + ADD COLUMN IF NOT EXISTS zombie_kills INT UNSIGNED NOT NULL DEFAULT 0 AFTER kills; diff --git a/database/extDB2/exile.ini b/database/extDB2/exile.ini index affd60b..813c4f7 100644 --- a/database/extDB2/exile.ini +++ b/database/extDB2/exile.ini @@ -1,4 +1,4 @@ [addAccountZombieKill] -SQL1_1 = UPDATE account SET zedkills = zedkills + 1 WHERE uid = ? +SQL1_1 = UPDATE account SET zombie_kills = zombie_kills + 1 WHERE uid = ? Number Of Inputs = 1 -SQL1_INPUTS = 1 \ No newline at end of file +SQL1_INPUTS = 1 diff --git a/database/extDB3/exile.ini b/database/extDB3/exile.ini index 82dc817..475a65c 100644 --- a/database/extDB3/exile.ini +++ b/database/extDB3/exile.ini @@ -1,4 +1,4 @@ [addAccountZombieKill] -SQL1_1 = UPDATE account SET zedkills = zedkills + 1 WHERE uid = ? +SQL1_1 = UPDATE account SET zombie_kills = zombie_kills + 1 WHERE uid = ? -SQL1_INPUTS = 1 \ No newline at end of file +SQL1_INPUTS = 1 diff --git a/exilez_mod/config.sqf b/exilez_mod/config.sqf index 8f6c739..bdb2997 100644 --- a/exilez_mod/config.sqf +++ b/exilez_mod/config.sqf @@ -15,6 +15,8 @@ EZM_MinSpawnDistance = 20; // Closest distance from any player EZM_MaxSpawnDistance = 100; // Max distance a zombie should spawn from a player. EZM_MaxDistance = 300; // Max distance to players before delete. EZM_MaxTime = 30; // Max time away from a player before delete. +EZM_MonitorInterval = 5; // Seconds between zombie monitor batches. +EZM_MonitorBatchSize = 50; // Maximum zombies checked per monitor batch. EZM_MaxTimeDead = 300; // Max time for a dead Zombie to stay before delete. (Default 5 minutes) EZM_RemoveZfromTraders = true; // Will kill zombies when they get too close to a safezone. (the check is done every MaxTime) EZM_RemoveZfromTerritory = true; // Will kill zombies when they get too close to a flag. (the check is done every MaxTime) diff --git a/exilez_mod/init/fn_postInit.sqf b/exilez_mod/init/fn_postInit.sqf index 17dbcdf..248ec28 100644 --- a/exilez_mod/init/fn_postInit.sqf +++ b/exilez_mod/init/fn_postInit.sqf @@ -296,6 +296,7 @@ EZM_ZMPKilled = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\MPKil EZM_GetRandomLocation = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\GetRandomLocation.sqf"; EZM_VerifyLocation = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\VerifyLocation.sqf"; EZM_TurnTheLightsOff = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\LightsOff.sqf"; +EZM_RefreshPlayerCache = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\RefreshPlayerCache.sqf"; // Compile the Zombie Monitor EZM_ZombieMonitor = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\ZombieMonitor.sqf"; @@ -312,12 +313,12 @@ EZM_HordeThread = compileFinal preprocessFileLineNumbers "exilez_mod\scripts\Hor // Add Zombie Monitor to ExileServer Thread if (EZM_Debug) then { - [EZM_MaxTime/2, EZM_ZombieMonitor, [], true] call ExileServer_system_thread_addTask; + [EZM_MonitorInterval, EZM_ZombieMonitor, [], true] call ExileServer_system_thread_addTask; diag_log "ExileZ Mod: Added Debug Zombie Monitor to ExileServer Thread"; } else { - [EZM_MaxTime, EZM_ZombieMonitor, [], true] call ExileServer_system_thread_addTask; + [EZM_MonitorInterval, EZM_ZombieMonitor, [], true] call ExileServer_system_thread_addTask; diag_log "ExileZ Mod: Added Zombie Monitor to ExileServer Thread"; }; @@ -438,4 +439,4 @@ if ((EZM_UseAreaBlacklist) && (EZM_BlacklistExtendTraders)) then EZM_BlacklistedPositions append EZM_BlacklistedTraders; }; -diag_log format["ExileZ Mod: Version %1 Started at (%2)", exileZmod_version, time]; \ No newline at end of file +diag_log format["ExileZ Mod: Version %1 Started at (%2)", exileZmod_version, time]; diff --git a/exilez_mod/init/fn_preInit.sqf b/exilez_mod/init/fn_preInit.sqf index 3bc3ecf..c0bddf0 100644 --- a/exilez_mod/init/fn_preInit.sqf +++ b/exilez_mod/init/fn_preInit.sqf @@ -49,6 +49,9 @@ if (isNil "EZM_CompiledOkay") exitWith // Create Zombie Monitor EZM_aliveZombies = []; publicVariable "EZM_aliveZombies"; +EZM_playerCache = []; +EZM_playerCacheUpdatedAt = -1; +EZM_zombieMonitorIndex = 0; // Create Dead Zombie Monitor EZM_deadZombies = []; diff --git a/exilez_mod/scripts/HarassingZombiesThread.sqf b/exilez_mod/scripts/HarassingZombiesThread.sqf index e9a6731..024ffeb 100644 --- a/exilez_mod/scripts/HarassingZombiesThread.sqf +++ b/exilez_mod/scripts/HarassingZombiesThread.sqf @@ -4,7 +4,7 @@ ExileZ Mod by [FPS]kuplion - Based on ExileZ 2.0 by Patrix87 */ -private ["_chanceRoll","_nPlayer","_sTime","_group","_count","_groupSize","_vestGroup","_lootGroup","_zombieGroup","_playerObj","_playerName","_playerPosition","_skipPlayer"]; +private ["_chanceRoll","_nPlayer","_sTime","_group","_count","_groupSize","_vestGroup","_lootGroup","_zombieGroup","_playerObj","_playerName","_playerPosition","_skipPlayer","_players"]; _groupSize = (_this select 0) select 0; _vestGroup = (_this select 0) select 1; @@ -21,6 +21,7 @@ if (time < 120) exitWith }; // Run the Harassing Zombie Loop +_players = call EZM_RefreshPlayerCache; { if (EZM_Debug) then { @@ -137,4 +138,4 @@ if (time < 120) exitWith }; uisleep 0.5; } -forEach (allPlayers - entities "HeadlessClient_F"); \ No newline at end of file +forEach _players; diff --git a/exilez_mod/scripts/HordeThread.sqf b/exilez_mod/scripts/HordeThread.sqf index 78c560a..668e269 100644 --- a/exilez_mod/scripts/HordeThread.sqf +++ b/exilez_mod/scripts/HordeThread.sqf @@ -24,13 +24,11 @@ if (time < 120) exitWith // Run the Horde Loop // Count players in game -_nPlayer = count (allPlayers - entities "HeadlessClient_F"); +_playerObjs = call EZM_RefreshPlayerCache; +_nPlayer = count _playerObjs; if (_nPlayer >= 1) then { - //create player list - _playerObjs = allPlayers - entities "HeadlessClient_F"; - //try to pick a lucky winner with a possible valid location for "_i" from 1 to _nPlayer do { @@ -100,4 +98,4 @@ if (_nPlayer >= 1) then diag_log "ExileZ Mod: No valid player found for The Horde.."; }; }; -}; \ No newline at end of file +}; diff --git a/exilez_mod/scripts/RefreshPlayerCache.sqf b/exilez_mod/scripts/RefreshPlayerCache.sqf new file mode 100644 index 0000000..a667574 --- /dev/null +++ b/exilez_mod/scripts/RefreshPlayerCache.sqf @@ -0,0 +1,16 @@ +/* + +ExileZ Mod by [FPS]kuplion - Based on ExileZ 2.0 by Patrix87 + +*/ + +if (isNil "EZM_playerCacheUpdatedAt" || {diag_tickTime - EZM_playerCacheUpdatedAt >= 1}) then +{ + EZM_playerCache = (allPlayers - entities "HeadlessClient_F") select + { + isPlayer _x && alive _x + }; + EZM_playerCacheUpdatedAt = diag_tickTime; +}; + +EZM_playerCache diff --git a/exilez_mod/scripts/VerifyLocation.sqf b/exilez_mod/scripts/VerifyLocation.sqf index 4aa1f15..7ec8746 100644 --- a/exilez_mod/scripts/VerifyLocation.sqf +++ b/exilez_mod/scripts/VerifyLocation.sqf @@ -9,7 +9,7 @@ ExileZ Mod by [FPS]kuplion - Based on ExileZ 2.0 by Patrix87 //_validLocation = [_triggerPosition,false] call VerifyLocation; // Return True if valid -private ["_flags","_validLocation","_distance","_radius","_position","_ignorePlayer"]; +private ["_flags","_validLocation","_distance","_radius","_position","_ignorePlayer","_players"]; _ignorePlayer = false; @@ -20,6 +20,7 @@ if (count _this == 2) then }; _validLocation = true; +_players = call EZM_RefreshPlayerCache; // Check if empty if ((count _position) == 0) then @@ -78,7 +79,7 @@ if (_validLocation) then // Check for players too close if (_validLocation && !_ignorePlayer) then { - if ({isplayer _x} count (_position nearEntities EZM_MinSpawnDistance) == 1) then + if ({(_x distance _position) <= EZM_MinSpawnDistance} count _players > 0) then { _validLocation = false; }; @@ -87,7 +88,7 @@ if (_validLocation && !_ignorePlayer) then // Check for absence of players near if (_validLocation && !_ignorePlayer) then { - if ({isplayer _x} count (_position nearEntities EZM_MaxSpawnDistance) == 0) then + if ({(_x distance _position) <= EZM_MaxSpawnDistance} count _players == 0) then { _validLocation = false; }; @@ -95,4 +96,4 @@ if (_validLocation && !_ignorePlayer) then // return -_validLocation; \ No newline at end of file +_validLocation; diff --git a/exilez_mod/scripts/ZombieMonitor.sqf b/exilez_mod/scripts/ZombieMonitor.sqf index 4034649..7f2b8c0 100644 --- a/exilez_mod/scripts/ZombieMonitor.sqf +++ b/exilez_mod/scripts/ZombieMonitor.sqf @@ -4,111 +4,61 @@ ExileZ Mod by [FPS]kuplion - Based on ExileZ 2.0 by Patrix87 */ -private ["_device","_zombie","_zombiePos","_zombieClass","_distance","_radius","_flags"]; +private ["_players","_processed","_zombieCount","_zombie","_zombiePos","_remove","_devices"]; -if (EZM_ExtendedLogging) then +_players = call EZM_RefreshPlayerCache; +_processed = 0; +_zombieCount = count EZM_aliveZombies; + +if (EZM_Debug) then { - diag_log format["ExileZ Mod: Monitored Zombies | %1 ", (count EZM_aliveZombies)]; + diag_log format["ExileZ Mod: Monitoring zombie batch | Alive: %1 | Players: %2", _zombieCount, count _players]; }; +while {_processed < EZM_MonitorBatchSize && {_processed < _zombieCount} && {count EZM_aliveZombies > 0}} do { - _zombie = _x; - _zombieClass = typeOf _zombie; - _zombiePos = getPos _zombie; - - if ((isNull _zombie) || (!(alive _zombie))) exitWith + if (EZM_zombieMonitorIndex >= count EZM_aliveZombies) then { - deleteVehicle _zombie; - EZM_aliveZombies = EZM_aliveZombies - [_zombie]; - - if (EZM_ExtendedLogging) then - { - diag_log format["ExileZ Mod: Removing 1 Zombie (Probably dead..) | Position : %1 | Class : %2",_zombiePos,_zombieClass]; - }; + EZM_zombieMonitorIndex = 0; }; - - // Check for the absence of players - if (({isplayer _x} count (_zombiePos nearEntities EZM_MaxDistance) == 0) && alive _zombie) then + + _zombie = EZM_aliveZombies select EZM_zombieMonitorIndex; + _remove = isNull _zombie || {!alive _zombie}; + + if (!_remove) then { - //_zombie setdamage 1; - //uisleep 5; - deleteVehicle _zombie; - EZM_aliveZombies = EZM_aliveZombies - [_zombie]; - - if (EZM_ExtendedLogging) then + _zombiePos = getPosATL _zombie; + _remove = ({(_x distance _zombiePos) <= EZM_MaxDistance} count _players) == 0; + + if (!_remove && {EZM_RemoveZfromTraders}) then { - diag_log format["ExileZ Mod: Removing 1 Zombie due to no Players | Position : %1 | Class : %2",_zombiePos,_zombieClass]; + _remove = _zombiePos call ExileClient_util_world_isInTraderZone; }; - }; - - // Check for safe zones - if ((EZM_RemoveZfromTraders) && ((getPosATL _zombie) call ExileClient_util_world_isInTraderZone) && (alive _zombie)) then - { - //_zombie setdamage 1; - //uisleep 5; - deleteVehicle _zombie; - EZM_aliveZombies = EZM_aliveZombies - [_zombie]; - - if (EZM_ExtendedLogging) then + + if (!_remove && {EZM_RemoveZfromTerritory}) then { - diag_log format["ExileZ Mod: Removing 1 Zombie at a SafeZone | Position : %1 | Class : %2",_zombiePos,_zombieClass]; + _remove = _zombiePos call ExileClient_util_world_isInTerritory; }; - }; - - // Check for flags - if ((EZM_RemoveZfromTerritory) && ((getPosATL _zombie) call ExileClient_util_world_isInTerritory) && (alive _zombie)) then - { - //_zombie setdamage 1; - //uisleep 5; - deleteVehicle _zombie; - EZM_aliveZombies = EZM_aliveZombies - [_zombie]; - - if (EZM_ExtendedLogging) then + + if (!_remove) then { - diag_log format["ExileZ Mod: Removing 1 Zombie at a Territory | Position : %1 | Class : %2",_zombiePos,_zombieClass]; + _devices = nearestObjects [_zombiePos, ["Land_Device_assembled_F", "DP_Land_Device_assembled_F", "O_Truck_03_device_F"], 30]; + _remove = count _devices > 0; }; }; - - // Check for the device - if (alive _zombie)then + + if (_remove) then { - _device = _zombiePos nearObjects ["Land_Device_assembled_F", 30]; + if (!isNull _zombie) then { - _distance = (getPosATL _x) distance _zombiePos; - if (_distance <= 30) exitWith - { - //_zombie setdamage 1; - //uisleep 10; - deleteVehicle _zombie; - EZM_aliveZombies = EZM_aliveZombies - [_zombie]; - - if (EZM_ExtendedLogging) then - { - diag_log format["ExileZ Mod: Removing 1 Zombie near a Land Device | Position : %1 | Class : %2",_zombiePos,_zombieClass]; - }; - }; - }forEach _device; - }; - - // Check for the mobile device - if (alive _zombie)then + deleteVehicle _zombie; + }; + EZM_aliveZombies deleteAt EZM_zombieMonitorIndex; + } + else { - _device = _zombiePos nearObjects ["O_Truck_03_device_F", 30]; - { - _distance = (getPosATL _x) distance _zombiePos; - if (_distance <= 30) exitWith - { - //_zombie setdamage 1; - //uisleep 10; - deleteVehicle _zombie; - EZM_aliveZombies = EZM_aliveZombies - [_zombie]; - - if (EZM_ExtendedLogging) then - { - diag_log format["ExileZ Mod: Removing 1 Zombie near a Truck Device | Position : %1 | Class : %2",_zombiePos,_zombieClass]; - }; - }; - }forEach _device; + EZM_zombieMonitorIndex = EZM_zombieMonitorIndex + 1; }; - -}forEach EZM_aliveZombies; + + _processed = _processed + 1; +};