From 3dd69ac7bfcb7929a092a16b42899459f700700e Mon Sep 17 00:00:00 2001 From: Madin Date: Mon, 12 Feb 2024 01:46:06 +0100 Subject: [PATCH] added tickets and despawn --- addons/staticspawn/CfgModuleCategories.hpp | 10 +++++ addons/staticspawn/XEH_PREP.hpp | 4 ++ addons/staticspawn/functions/fnc_addEH.sqf | 37 ++++++++++++++++++ .../functions/fnc_checkSpawnConditions.sqf | 6 +-- addons/staticspawn/functions/fnc_despawn.sqf | 37 +++++++++--------- .../functions/fnc_despawnAddToLogic.sqf | 39 +++++++++++++++++++ .../staticspawn/functions/fnc_despawnLoop.sqf | 4 +- .../staticspawn/functions/fnc_firstState.sqf | 6 ++- .../staticspawn/functions/fnc_getGroups.sqf | 5 ++- .../staticspawn/functions/fnc_spawnUnit.sqf | 4 +- .../staticspawn/functions/fnc_waitUntil.sqf | 12 ++++-- 11 files changed, 133 insertions(+), 31 deletions(-) create mode 100644 addons/staticspawn/functions/fnc_addEH.sqf create mode 100644 addons/staticspawn/functions/fnc_despawnAddToLogic.sqf diff --git a/addons/staticspawn/CfgModuleCategories.hpp b/addons/staticspawn/CfgModuleCategories.hpp index 7cb2ef2..a833231 100644 --- a/addons/staticspawn/CfgModuleCategories.hpp +++ b/addons/staticspawn/CfgModuleCategories.hpp @@ -58,6 +58,16 @@ class CfgVehicles class Attributes: AttributesBase { // Arguments shared by specific module type (have to be mentioned in order to be present) + class GVAR(tickets): Default + { + displayName = "$STR_MAI_tickets"; + tooltip = "$STR_MAI_tickets"; + defaultValue = "1"; + property = QGVAR(tickets); + expression = "_this setVariable ['%s',_value];"; + typeName = "NUMBER"; + control = "EditShort"; + }; class GVAR(sphereSize): Default { displayName = "$STR_MAI_sphereSize"; diff --git a/addons/staticspawn/XEH_PREP.hpp b/addons/staticspawn/XEH_PREP.hpp index fff375c..8b100e4 100644 --- a/addons/staticspawn/XEH_PREP.hpp +++ b/addons/staticspawn/XEH_PREP.hpp @@ -6,3 +6,7 @@ PREP(init); PREP(initCall); PREP(loop); PREP(waitUntil); +PREP(spawnUnit); +PREP(checkSpawnConditions); +PREP(addEH); +PREP(despawnAddToLogic); \ No newline at end of file diff --git a/addons/staticspawn/functions/fnc_addEH.sqf b/addons/staticspawn/functions/fnc_addEH.sqf new file mode 100644 index 0000000..f261498 --- /dev/null +++ b/addons/staticspawn/functions/fnc_addEH.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" +/* + * Author: + * Function description + * + * Arguments: + * 0: Objects + * 1: All + * + * Return Value: + * None + * + * Example: + * [[bob, ted], false] call afmf_main_fnc_example + * + * Public: No + */ + +params [["_unit", objNull]]; +if !(alive _unit) exitWith {}; + +_unit addEventHandler ["Killed", { + params ["_unit", "_killer", "_instigator", "_useEffects"]; + + private _logic = _unit getVariable [QGVAR(logic), objNull]; + 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 {}; + + _unit setVariable [QGVAR(tickets), _tickets]; + + private _respawnDelay = _logic getVariable [QGVAR(respawnDelay), [10, 20, 30]]; + [_unit, _logic, false, random _respawnDelay max 1] call FUNC(despawn); +}]; diff --git a/addons/staticspawn/functions/fnc_checkSpawnConditions.sqf b/addons/staticspawn/functions/fnc_checkSpawnConditions.sqf index 33e1891..e3360d6 100644 --- a/addons/staticspawn/functions/fnc_checkSpawnConditions.sqf +++ b/addons/staticspawn/functions/fnc_checkSpawnConditions.sqf @@ -25,12 +25,12 @@ private _minDistance = _logic getVariable [QGVAR(minDistance), 10]; if (_distance > _minDistance) exitWith {false}; // check if new bot will be facing same direction -private _unitDir = _unit getVariable [QGVAR(dir), 0]; +private _unitDir = _unit getVariable [QGVAR(dir), getDir _unit]; private _deltaAngle = [_unitDir, _dir] call BIS_fnc_getAngleDelta; private _maxAngle = _logic getVariable [QGVAR(maxAngle), 22.5]; if (abs _deltaAngle > _maxAngle) exitWith {false}; // var added at EH killed -private _timeToRespawn = _unit getVariable [QGVAR(timeToRespawn), time]; -if (_timeToRespawn < time) exitWith {false}; +private _DelaySpawnNearbyUnits = _unit getVariable [QGVAR(delaySpawnNearbyUnits), time]; +if (_DelaySpawnNearbyUnits < time) exitWith {false}; true \ No newline at end of file diff --git a/addons/staticspawn/functions/fnc_despawn.sqf b/addons/staticspawn/functions/fnc_despawn.sqf index daeb00a..c506642 100644 --- a/addons/staticspawn/functions/fnc_despawn.sqf +++ b/addons/staticspawn/functions/fnc_despawn.sqf @@ -16,28 +16,27 @@ * Public: No */ -params [["_unit", objNull], ["_logic", objNull], ["_unitArray", []]]; +params [["_unit", objNull], ["_logic", objNull], ["_deleteBody", true], ["_waitTime", 0]]; +private _unitArray = _unit getVariable [QGVAR(unitArray), []]; private _groupID = _unit getVariable [QGVAR(groupID), -1]; private _groups = _logic getVariable [QGVAR(groups), []]; -private _side = _unit getVariable [QGVAR(AF_side), side _unit]; +private _side = _unit getVariable [QGVAR(side), side _unit]; private _active = _logic getVariable [QGVAR(active), true]; private _group = group _unit; -deleteVehicle _unit; -if (_groups isEqualTo []) exitWith { - _groups pushBack [_groupID, _side, [_unitArray], group _unit]; - if !(_active) then { - _logic setVariable [QGVAR(active), true]; - _logic call FUNC(loop); - }; + +if (_deleteBody) then { + deleteVehicle _unit; }; -private _groupIndex = _groups findIf {_x select 0 isEqualTo _groupID}; -if (_groupIndex isEqualTo -1) exitWith { - _groups pushBack [_groupID, _side, [_unitArray], group _unit]; - if !(_active) then { - _logic setVariable [QGVAR(active), true]; - _logic call FUNC(loop); - }; + +private _tickets = _unit getVariable [QGVAR(tickets), 1]; +_unitArray set [14, _tickets]; + +if (_waitTime <= 0) exitWith { + [_logic, _unitArray, _groupID, _group, _groups, _side] call FUNC(despawnAddToLogic); }; -private _groupArray = _groups select _groupIndex; -_groupArray params ["_groupID", "_side", "_units", ["_group", grpNull]]; -_units pushBack _unitArray; +[ + {_this call FUNC(despawnAddToLogic)}, + [_logic, _unitArray, _groupID, _group, _groups, _side], + _waitTime +] call CBA_fnc_waitAndExecute; + diff --git a/addons/staticspawn/functions/fnc_despawnAddToLogic.sqf b/addons/staticspawn/functions/fnc_despawnAddToLogic.sqf new file mode 100644 index 0000000..c96b629 --- /dev/null +++ b/addons/staticspawn/functions/fnc_despawnAddToLogic.sqf @@ -0,0 +1,39 @@ +#include "script_component.hpp" +/* + * Author: + * Function description + * + * Arguments: + * 0: Objects + * 1: All + * + * Return Value: + * None + * + * Example: + * [[bob, ted], false] call afmf_main_fnc_example + * + * Public: No + */ + +params [["_logic", objNull], ["_unitArray", []], ["_groupID", objNull], ["_group", grpNull], ["_groups", []], ["_side", []]]; + +private _active = _logic getVariable [QGVAR(active), true]; +if (_groups isEqualTo []) exitWith { + _groups pushBack [_groupID, _side, [_unitArray], _group]; + if !(_active) then { + _logic setVariable [QGVAR(active), true]; + _logic call FUNC(loop); + }; +}; +private _groupIndex = _groups findIf {_x select 0 isEqualTo _groupID}; +if (_groupIndex isEqualTo -1) exitWith { + _groups pushBack [_groupID, _side, [_unitArray], _group]; + if !(_active) then { + _logic setVariable [QGVAR(active), true]; + _logic call FUNC(loop); + }; +}; +private _groupArray = _groups select _groupIndex; +_groupArray params ["_groupID", "_side", "_units", ["_group", grpNull]]; +_units pushBack _unitArray; diff --git a/addons/staticspawn/functions/fnc_despawnLoop.sqf b/addons/staticspawn/functions/fnc_despawnLoop.sqf index a243d9e..4aea4b7 100644 --- a/addons/staticspawn/functions/fnc_despawnLoop.sqf +++ b/addons/staticspawn/functions/fnc_despawnLoop.sqf @@ -22,14 +22,14 @@ private _logic = _unit getVariable [QGVAR(logic), objNull]; if (!alive _logic) exitWith {}; _unitArray = _unit getVariable [QGVAR(unitArray), []]; if (_unitArray isEqualTo []) exitWith {}; -_unitArray params ["_type", "_loadout", "_pos", "_dir", "_stance", "_disabledAiFeatures", "_vehicleArray", "_building", "_buildingStatus", "_sphereSizeUnit", "_sphereBackDistanceUnit", "_sphereDespawnDistanceUnit"]; +_unitArray params ["_type", "_loadout", "_pos", "_dir", "_stance", "_disabledAiFeatures", "_vehicleArray", "_building", "_buildingStatus", "_sphereSizeUnit", "_sphereBackDistanceUnit", "_sphereDespawnDistanceUnit", "_tickets"]; if (_sphereDespawnDistanceUnit < 0) exitWith {}; private _spherePos = _pos getPos [_sphereSizeUnit - _sphereBackDistanceUnit + _sphereDespawnDistanceUnit*0.9, _dir]; private _nearplayers = _spherePos nearEntities ["allVehicles", _sphereSizeUnit + _sphereDespawnDistanceUnit]; private _playerIndex = _nearplayers findIf {isPlayer _x && !(vehicle _x isKindOf "AIR")}; // despawn unit if (_playerIndex == -1) exitWith { - [_unit, _logic, _unitArray] call FUNC(despawn); + [_unit, _logic, true, 0] call FUNC(despawn); }; [ diff --git a/addons/staticspawn/functions/fnc_firstState.sqf b/addons/staticspawn/functions/fnc_firstState.sqf index d35f98a..600e589 100644 --- a/addons/staticspawn/functions/fnc_firstState.sqf +++ b/addons/staticspawn/functions/fnc_firstState.sqf @@ -25,7 +25,9 @@ params [ ["_checkBuildings", true], ["_activateCondition", {true}], ["_executionCodeUnit", {}], - ["_executionCodeGroup", {}] + ["_executionCodeGroup", {}], + ["_maxUnitsPerdistance", 1], + ["_tickets", 1] ]; if (_logic isEqualTo objNull) exitWith {}; @@ -37,5 +39,7 @@ _logic setVariable [QGVAR(checkBuildings), _checkBuildings]; _logic setVariable [QGVAR(activateCondition), _activateCondition]; _logic setVariable [QGVAR(executionCodeUnit), _executionCodeUnit]; _logic setVariable [QGVAR(executionCodeGroup), _executionCodeGroup]; +_logic setVariable [QGVAR(maxUnitsPerdistance), _maxUnitsPerdistance]; +_logic setVariable [QGVAR(tickets), _tickets]; [_logic] call FUNC(loop); \ No newline at end of file diff --git a/addons/staticspawn/functions/fnc_getGroups.sqf b/addons/staticspawn/functions/fnc_getGroups.sqf index 2e8cfdf..5936458 100644 --- a/addons/staticspawn/functions/fnc_getGroups.sqf +++ b/addons/staticspawn/functions/fnc_getGroups.sqf @@ -25,6 +25,7 @@ private _sphereBackDistance = _logic getVariable [QGVAR(sphereBackDistance), 30] private _sphereDespawnDistance = _logic getVariable [QGVAR(sphereDespawnDistance), 50]; private _checkVisibility = _logic getVariable [QGVAR(checkVisibility), true]; private _forceSpawnDistance = _logic getVariable [QGVAR(forceSpawnDistance), 0.35]; +private _tickets = _logic getVariable [QGVAR(tickets), 1]; private _groups = []; private _vehiclesInfo = []; //private _vehiclesToDelete = []; @@ -128,6 +129,7 @@ private _vehiclesInfo = []; private _sphereDespawnDistanceUnit = _unit getVariable [QGVAR(sphereDespawnDistance), _sphereDespawnDistance]; private _checkVisibilityUnit = _unit getVariable [QGVAR(checkVisibility), _checkVisibility]; private _forceSpawnDistanceUnit = _unit getVariable [QGVAR(forceSpawnDistance), _forceSpawnDistance]; + private _ticketsUnit = _unit getVariable [QGVAR(tickets), _tickets]; _units pushBack [ _type, _loadout, @@ -142,7 +144,8 @@ private _vehiclesInfo = []; _sphereBackDistanceUnit, _sphereDespawnDistanceUnit, _checkVisibilityUnit, - _forceSpawnDistanceUnit + _forceSpawnDistanceUnit, + _ticketsUnit ]; }; deleteVehicle _unit; diff --git a/addons/staticspawn/functions/fnc_spawnUnit.sqf b/addons/staticspawn/functions/fnc_spawnUnit.sqf index 1ba3c11..d3676d2 100644 --- a/addons/staticspawn/functions/fnc_spawnUnit.sqf +++ b/addons/staticspawn/functions/fnc_spawnUnit.sqf @@ -34,7 +34,8 @@ _unitArray params [ "_sphereBackDistanceUnit", "_sphereDespawnDistanceUnit", "_checkVisibilityUnit", - "_forceSpawnDistanceUnit" + "_forceSpawnDistanceUnit", + ["_tickets", 1] ]; private _maxUnitsPerDistance = _logic getVariable [QGVAR(maxUnitsPerdistance), 1]; @@ -110,6 +111,7 @@ if !(_unit isEqualTo objNull) then { _unit setVariable [QGVAR(logic), _logic]; _unit setVariable [QGVAR(pos), _pos]; _unit setVariable [QGVAR(dir), _dir]; + _unit setVariable [QGVAR(tickets), _tickets]; [_unit] call FUNC(addEH); [_unit] call FUNC(despawnLoop); diff --git a/addons/staticspawn/functions/fnc_waitUntil.sqf b/addons/staticspawn/functions/fnc_waitUntil.sqf index fe168bc..05133fb 100644 --- a/addons/staticspawn/functions/fnc_waitUntil.sqf +++ b/addons/staticspawn/functions/fnc_waitUntil.sqf @@ -26,9 +26,9 @@ _activate = true; // for testing, function above needs to be rewriten if (_activate) then { private _groups = _logic getVariable ["groups", []]; - if (!isServer && !hasInterface) exitWith { - [_logic, _groups] call FUNC(staticspawnInterval); - }; + // if (!isServer && !hasInterface) exitWith { + // [_logic, _groups] call FUNC(staticspawnInterval); + // }; private _activationTriggers = _logic getVariable [QGVAR(activationTriggers) ,[]]; private _includeAir = _logic getVariable [QGVAR(includeAir), false]; @@ -37,6 +37,8 @@ if (_activate) then { private _activateCondition = _logic getVariable [QGVAR(activateCondition), {true}]; private _executionCodeUnit = _logic getVariable [QGVAR(executionCodeUnit), {}]; private _executionCodeGroup = _logic getVariable [QGVAR(executionCodeGroup), {}]; + private _maxUnitsPerdistance = _logic getVariable [QGVAR(maxUnitsPerdistance), 1]; + private _tickets = _logic getVariable [QGVAR(tickets), 1]; private _owner = call MAI_fnc_HCfind; [ @@ -48,7 +50,9 @@ if (_activate) then { _checkBuildings, _activateCondition, _executionCodeUnit, - _executionCodeGroup + _executionCodeGroup, + _maxUnitsPerdistance, + _tickets ] remoteExecCall [QFUNC(firstState),_owner,false]; } else { [{_this call QFUNC(WaitUntil)},