Skip to content

Commit

Permalink
Fixed AI spawn after players nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
Madin5 committed Mar 2, 2024
1 parent 3dd69ac commit cd0f11a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
12 changes: 12 additions & 0 deletions addons/staticspawn/CfgModuleCategories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
27 changes: 27 additions & 0 deletions addons/staticspawn/functions/fnc_addEH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,40 @@ _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];

private _tickets = _unit getVariable [QGVAR(tickets), 1];
_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]];
Expand Down
12 changes: 8 additions & 4 deletions addons/staticspawn/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<Polish>Dystans sprawdzania obecności graczy</Polish>
</Key>
<Key ID="STR_MAI_sphereDespawnDistance">
<Original>Despawn distance</Original>
<Polish>Dystans despawnu</Polish>
<Original>Despawn distance, added to spawn distance.</Original>
<Polish>Dystans despawnu, dodany do dystansu spawnu.</Polish>
</Key>
<Key ID="STR_MAI_sphereDespawnDistanceShort">
<Original>The distance of checking the presence of players above which units will be removed. Added to spawn value.</Original>
Expand All @@ -25,11 +25,15 @@
<Polish>Nieaktywne</Polish>
</Key>
<Key ID="STR_MAI_sphereBackDistance">
<Original>Offset checking</Original>
<Polish>Przsunięcie sprawdzania</Polish>
<Original>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.</Original>
<Polish>Minimalny dystans gracza do bota, poniżej którego bot się pojawi / Przsunięcie środka sprawdzania pobliskich graczy w przeciwnym kierunku do kierunku bota.</Polish>
</Key>
<Key ID="STR_MAI_sphereBackDistanceShort">
<Original>How far back will players be checked.</Original>
<Polish>Jak daleko do tyłu będzie sprawdzane obecność graczy.</Polish>
</Key>
<Key ID="STR_MAI_respawnDelay">
<Original>How long after death can a bot respawn, if it has tickets.</Original>
<Polish>Po jakim czasie od śmierci bot może ponownie się odrodzić, jeśli posiada tickety.</Polish>
</Key>
</Project>

0 comments on commit cd0f11a

Please sign in to comment.