Skip to content

Commit

Permalink
added tickets and despawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Madin5 committed Feb 12, 2024
1 parent 9beb79e commit 3dd69ac
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 31 deletions.
10 changes: 10 additions & 0 deletions addons/staticspawn/CfgModuleCategories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions addons/staticspawn/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ PREP(init);
PREP(initCall);
PREP(loop);
PREP(waitUntil);
PREP(spawnUnit);
PREP(checkSpawnConditions);
PREP(addEH);
PREP(despawnAddToLogic);
37 changes: 37 additions & 0 deletions addons/staticspawn/functions/fnc_addEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: <author>
* Function description
*
* Arguments:
* 0: Objects <ARRAY>
* 1: All <BOOL>
*
* 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);
}];
6 changes: 3 additions & 3 deletions addons/staticspawn/functions/fnc_checkSpawnConditions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 18 additions & 19 deletions addons/staticspawn/functions/fnc_despawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

39 changes: 39 additions & 0 deletions addons/staticspawn/functions/fnc_despawnAddToLogic.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "script_component.hpp"
/*
* Author: <author>
* Function description
*
* Arguments:
* 0: Objects <ARRAY>
* 1: All <BOOL>
*
* 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;
4 changes: 2 additions & 2 deletions addons/staticspawn/functions/fnc_despawnLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

[
Expand Down
6 changes: 5 additions & 1 deletion addons/staticspawn/functions/fnc_firstState.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ params [
["_checkBuildings", true],
["_activateCondition", {true}],
["_executionCodeUnit", {}],
["_executionCodeGroup", {}]
["_executionCodeGroup", {}],
["_maxUnitsPerdistance", 1],
["_tickets", 1]
];

if (_logic isEqualTo objNull) exitWith {};
Expand All @@ -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);
5 changes: 4 additions & 1 deletion addons/staticspawn/functions/fnc_getGroups.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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,
Expand All @@ -142,7 +144,8 @@ private _vehiclesInfo = [];
_sphereBackDistanceUnit,
_sphereDespawnDistanceUnit,
_checkVisibilityUnit,
_forceSpawnDistanceUnit
_forceSpawnDistanceUnit,
_ticketsUnit
];
};
deleteVehicle _unit;
Expand Down
4 changes: 3 additions & 1 deletion addons/staticspawn/functions/fnc_spawnUnit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ _unitArray params [
"_sphereBackDistanceUnit",
"_sphereDespawnDistanceUnit",
"_checkVisibilityUnit",
"_forceSpawnDistanceUnit"
"_forceSpawnDistanceUnit",
["_tickets", 1]
];

private _maxUnitsPerDistance = _logic getVariable [QGVAR(maxUnitsPerdistance), 1];
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions addons/staticspawn/functions/fnc_waitUntil.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
[
Expand All @@ -48,7 +50,9 @@ if (_activate) then {
_checkBuildings,
_activateCondition,
_executionCodeUnit,
_executionCodeGroup
_executionCodeGroup,
_maxUnitsPerdistance,
_tickets
] remoteExecCall [QFUNC(firstState),_owner,false];
} else {
[{_this call QFUNC(WaitUntil)},
Expand Down

0 comments on commit 3dd69ac

Please sign in to comment.