Skip to content

Commit

Permalink
staticSpawn working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Madin authored and Madin committed May 11, 2024
1 parent fda3b98 commit 884cf3c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 14 deletions.
18 changes: 9 additions & 9 deletions addons/staticspawn/CfgModuleCategories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ class CfgVehicles
typeName = "NUMBER";
control = "EditShort";
};
class GVAR(checkVisibility): Checkbox
{
displayName = "$STR_MAI_checkVisibility";
tooltip = "$STR_MAI_checkVisibilityShort";
property = QGVAR(checkVisibility);
defaultValue = "true";
expression = "_this setVariable ['%s', _value];";
typeName = "BOOL";
};
// class GVAR(checkVisibility): Checkbox
// {
// displayName = "$STR_MAI_checkVisibility";
// tooltip = "$STR_MAI_checkVisibilityShort";
// property = QGVAR(checkVisibility);
// defaultValue = "true";
// expression = "_this setVariable ['%s', _value];";
// typeName = "BOOL";
// };
class GVAR(sphereBackDistance): Default
{
displayName = "$STR_MAI_sphereBackDistance";
Expand Down
3 changes: 2 additions & 1 deletion addons/staticspawn/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ PREP(waitUntil);
PREP(spawnUnit);
PREP(checkSpawnConditions);
PREP(addEH);
PREP(despawnAddToLogic);
PREP(despawnAddToLogic);
PREP(checkRespawnConditionLoop);
35 changes: 35 additions & 0 deletions addons/staticspawn/functions/fnc_checkRespawnConditionLoop.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#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", []], ["_pos", [0,0,0]], ["_waitUntil", 0]];

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 {};

if (_waitUntil <= time) exitWith {
[_logic, _unitArray, _groupID, _group, _groups, _side] call FUNC(despawnAddToLogic);
};

[
{_this call FUNC(checkRespawnConditionLoop)},
_this,
0.9 + random 0.2
] call CBA_fnc_waitAndExecute;
6 changes: 6 additions & 0 deletions addons/staticspawn/functions/fnc_checkSpawnConditions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

params [["_logic", objNull], ["_unit", objNull], ["_pos", [0,0,0]], ["_dir", 0]];

// force spawn when player is nearby
private _sphereBackDistance = _logic getVariable [QGVAR(sphereBackDistance), 30];
private _nearplayers = _pos nearEntities ["allVehicles", _sphereBackDistance];
private _playerIndex = _nearplayers findIf {isPlayer _x};
if (_playerIndex > -1) exitWith {false};

// check if spawn pos of other units in group is more than set in module
private _unitPos = _unit getVariable [QGVAR(pos), getposATL _unit];
private _distance = _unitPos distance _pos;
Expand Down
26 changes: 24 additions & 2 deletions addons/staticspawn/functions/fnc_despawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,37 @@ if (_deleteBody) then {
deleteVehicle _unit;
};

// _unitArray params [
// "_type",
// "_loadout",
// "_pos",
// "_dir",
// "_stance",
// "_disabledAiFeatures",
// "_vehicleArray",
// "_building",
// "_buildingStatus",
// "_sphereSizeUnit",
// "_sphereBackDistanceUnit",
// "_sphereDespawnDistanceUnit",
// "_checkVisibilityUnit",
// "_forceSpawnDistanceUnit",
// ["_tickets", 1]
// ];

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 _pos = _unitArray select 2;
private _waitUntil = time + _waitTime;

[
{_this call FUNC(despawnAddToLogic)},
[_logic, _unitArray, _groupID, _group, _groups, _side],
{_this call FUNC(checkRespawnConditionLoop)},
[_logic, _unitArray, _groupID, _group, _groups, _side, _pos, _waitUntil],
_waitTime
] call CBA_fnc_waitAndExecute;

2 changes: 1 addition & 1 deletion addons/staticspawn/functions/fnc_loop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ params [
if (_logic isEqualTo objNull) exitWith {};
private _groups = _logic getVariable [QGVAR(groups), []];
if (_groups isEqualTo []) exitWith {
systemChat "loop groups isEqualTo []";
// systemChat "loop groups isEqualTo []";
_logic setVariable [QGVAR(active), false];
};

Expand Down
2 changes: 1 addition & 1 deletion addons/staticspawn/functions/fnc_waitUntil.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (_activate) then {
} else {
[{_this call QFUNC(WaitUntil)},
_this,
random [0.9,1,1.1]
0.9 + random 0.2
] call CBA_fnc_waitAndExecute;
};

Expand Down

0 comments on commit 884cf3c

Please sign in to comment.