From cd0f11a614a0f28642f17b2bfa94a716ec4f47c7 Mon Sep 17 00:00:00 2001 From: Madin Date: Sat, 2 Mar 2024 13:03:21 +0100 Subject: [PATCH] Fixed AI spawn after players nearby --- addons/staticspawn/CfgModuleCategories.hpp | 12 ++++++++++ addons/staticspawn/functions/fnc_addEH.sqf | 27 ++++++++++++++++++++++ addons/staticspawn/stringtable.xml | 12 ++++++---- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/addons/staticspawn/CfgModuleCategories.hpp b/addons/staticspawn/CfgModuleCategories.hpp index a833231..fb350f3 100644 --- a/addons/staticspawn/CfgModuleCategories.hpp +++ b/addons/staticspawn/CfgModuleCategories.hpp @@ -68,6 +68,18 @@ class CfgVehicles typeName = "NUMBER"; control = "EditShort"; }; + + class GVAR(respawnDelay): Default + { + displayName = "$STR_MAI_respawnDelay"; + tooltip = "$STR_MAI_respawnDelay"; + property = QGVAR(respawnDelay); + defaultValue = "[10,30,45]"; + expression = "_this setVariable ['%s', _value];"; + typeName = "ARRAY"; + control = "Timeout"; + }; + class GVAR(sphereSize): Default { displayName = "$STR_MAI_sphereSize"; diff --git a/addons/staticspawn/functions/fnc_addEH.sqf b/addons/staticspawn/functions/fnc_addEH.sqf index f261498..c4ee526 100644 --- a/addons/staticspawn/functions/fnc_addEH.sqf +++ b/addons/staticspawn/functions/fnc_addEH.sqf @@ -23,6 +23,7 @@ _unit addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; private _logic = _unit getVariable [QGVAR(logic), objNull]; + if !(alive _logic) exitWith {}; private _delaySpawnNearbyUnits = _logic getVariable [QGVAR(delaySpawnNearbyUnits), 5]; _unit setVariable [QGVAR(delaySpawnNearbyUnits), time + random _delaySpawnNearbyUnits]; @@ -30,6 +31,32 @@ _unit addEventHandler ["Killed", { _tickets = _tickets - 1; if (_tickets <= 0) exitWith {}; + private _unitArray = _unit getVariable [QGVAR(unitArray), []]; + // _unitArray params [ + // "_type", + // "_loadout", + // "_pos", + // "_dir", + // "_stance", + // "_disabledAiFeatures", + // "_vehicleArray", + // "_building", + // "_buildingStatus", + // "_sphereSizeUnit", + // "_sphereBackDistanceUnit", + // "_sphereDespawnDistanceUnit", + // "_checkVisibilityUnit", + // "_forceSpawnDistanceUnit", + // ["_tickets", 1] + // ]; + private _pos = _unitArray select 2; + + private _sphereBackDistance = _logic getVariable [QGVAR(sphereBackDistance), 30]; + private _nearplayers = _pos nearEntities ["allVehicles", _sphereBackDistance]; + private _playerIndex = _nearplayers findIf {isPlayer _x}; + // stop spawn near units if player nearby + if (_playerIndex > -1) exitWith {}; + _unit setVariable [QGVAR(tickets), _tickets]; private _respawnDelay = _logic getVariable [QGVAR(respawnDelay), [10, 20, 30]]; diff --git a/addons/staticspawn/stringtable.xml b/addons/staticspawn/stringtable.xml index c530f5f..d82e232 100644 --- a/addons/staticspawn/stringtable.xml +++ b/addons/staticspawn/stringtable.xml @@ -9,8 +9,8 @@ Dystans sprawdzania obecności graczy - Despawn distance - Dystans despawnu + Despawn distance, added to spawn distance. + Dystans despawnu, dodany do dystansu spawnu. The distance of checking the presence of players above which units will be removed. Added to spawn value. @@ -25,11 +25,15 @@ Nieaktywne - Offset checking - Przsunięcie sprawdzania + Minimum distance of the player to the bot, below which the bot will appear / Offset checkingShifting the checking center of nearby players in the opposite direction to the bot's direction. + Minimalny dystans gracza do bota, poniżej którego bot się pojawi / Przsunięcie środka sprawdzania pobliskich graczy w przeciwnym kierunku do kierunku bota. How far back will players be checked. Jak daleko do tyłu będzie sprawdzane obecność graczy. + + How long after death can a bot respawn, if it has tickets. + Po jakim czasie od śmierci bot może ponownie się odrodzić, jeśli posiada tickety. +