locally tested. adds settings, fixes removal logic

This commit is contained in:
2024-01-26 16:16:18 -08:00
parent 754d7356e1
commit 7e4af79fed
3 changed files with 101 additions and 18 deletions

View File

@@ -1,8 +1,10 @@
// execute for all // execute for all
milsim_respawn_setting_maxRangeToReady = 400; // distance in meters from a base at which players can ready up for pickup. players removed from the queue if they move further away than this distance if (isNil "milsim_respawn_setting_reinsertion_maxRangeToReady") then {
// configured in CBA settings
milsim_respawn_setting_reinsertion_maxRangeToReady = 400; // distance in meters from a base at which players can ready up for pickup. players removed from the queue if they move further away than this distance
};
milsim_respawn_bases = allMissionObjects "ModuleRespawnPosition_F"; // array of all respawn modules in the mission milsim_respawn_bases = allMissionObjects "ModuleRespawnPosition_F"; // array of all respawn modules in the mission
// player self-interacts will be applied in initPlayerLocal via milsim_respawn_fnc_readyForPickup
// on the server, initialize the queue and register the CBA event handler by which players can ready up // on the server, initialize the queue and register the CBA event handler by which players can ready up
if (isServer) then { if (isServer) then {
@@ -14,14 +16,19 @@ if (isServer) then {
["milsim_respawn_fileReinsertRequest", { ["milsim_respawn_fileReinsertRequest", {
params ["_unit", "_closestBaseName"]; params ["_unit", "_closestBaseName"];
milsim_respawn_reinsertionQueue pushBackUnique [_unit, _closestBaseName]; milsim_respawn_reinsertionQueue pushBackUnique [_unit, _closestBaseName];
diag_log text format ["[milsim_respawn] [reinsertion] ADDED name=%1 playerUID=%2 closestBase=%3", name _unit, getPlayerUID _unit, _closestBaseName]; diag_log text format [
"[milsim] (respawn_reinsertion) ADDED name=%1 playerUID=%2 closestBase=%3",
name _unit, getPlayerUID _unit, _closestBaseName
];
publicVariable "milsim_respawn_reinsertionQueue"; publicVariable "milsim_respawn_reinsertionQueue";
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
["milsim_respawn_removeReinsertRequest", { ["milsim_respawn_removeReinsertRequest", {
params ["_unit"]; params ["_unit"];
if (milsim_respawn_reinsertionQueue find {_x#0 isEqualTo _unit} == -1) exitWith {}; if (count (milsim_respawn_reinsertionQueue select {_x#0 isEqualTo _unit}) isEqualTo 0) exitWith {};
milsim_respawn_reinsertionQueue = milsim_respawn_reinsertionQueue select {_x#0 isNotEqualTo _unit}; milsim_respawn_reinsertionQueue = milsim_respawn_reinsertionQueue select {_x#0 isNotEqualTo _unit};
diag_log text format ["[milsim_respawn] [reinsertion] REMOVED BY REQUEST name=%1 playerUID=%2", name _unit, getPlayerUID _unit]; diag_log text format ["[milsim] (respawn_reinsertion) REMOVED BY REQUEST name=%1 playerUID=%2",
name _unit, getPlayerUID _unit
];
publicVariable "milsim_respawn_reinsertionQueue"; publicVariable "milsim_respawn_reinsertionQueue";
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
@@ -41,7 +48,7 @@ if (isServer) then {
if (_distanceFromBase < _nearestDistance) then { if (_distanceFromBase < _nearestDistance) then {
_nearestDistance = _distanceFromBase; _nearestDistance = _distanceFromBase;
}; };
if (_distanceFromBase < milsim_respawn_setting_maxRangeToReady) then { if (_distanceFromBase < milsim_respawn_setting_reinsertion_maxRangeToReady) then {
_nearBase = true; _nearBase = true;
}; };
} forEach milsim_respawn_bases; } forEach milsim_respawn_bases;
@@ -49,7 +56,10 @@ if (isServer) then {
if (_nearBase && alive _player) then { if (_nearBase && alive _player) then {
_stillValid pushBackUnique _queueData; _stillValid pushBackUnique _queueData;
} else { } else {
diag_log text format ["[milsim_respawn] [reinsertion] REMOVED AUTOMATICALLY name=%1 playerUID=%2 nearestBase=%3m", name _player, getPlayerUID _player, _nearestDistance]; diag_log text format [
"[milsim] (respawn_reinsertion) REMOVED AUTOMATICALLY name=%1 playerUID=%2 nearestBase=%3m",
name _player, getPlayerUID _player, _nearestDistance
];
}; };
} forEach milsim_respawn_reinsertionQueue; } forEach milsim_respawn_reinsertionQueue;
@@ -81,13 +91,16 @@ if (hasInterface) then {
{ {
params ["_target", "_player", "_params"]; params ["_target", "_player", "_params"];
private _closestBase = [milsim_respawn_bases, _player] call BIS_fnc_nearestPosition; private _closestBase = [milsim_respawn_bases, _player] call BIS_fnc_nearestPosition;
["milsim_respawn_fileReinsertRequest", [_player, _closestBase getVariable ["name", "unknown"]]] call CBA_fnc_serverEvent; private _closestBaseName = _closestBase getVariable ["name", "unknown"];
format["Re-insert Request Filed at Location %1", _closestBase getVariable ["name", "unknown"]] call CBA_fnc_notify; ["milsim_respawn_fileReinsertRequest", [_player, _closestBaseName]] call CBA_fnc_serverEvent;
[["Re-insert Request Filed"], [format["Pickup at %1", _closestBaseName]]] call CBA_fnc_notify;
}, },
{ {
params ["_target", "_player", "_params"]; params ["_target", "_player", "_params"];
private _closestBase = [milsim_respawn_bases, _player] call BIS_fnc_nearestPosition; private _closestBase = [milsim_respawn_bases, _player] call BIS_fnc_nearestPosition;
(_player distance _closestBase < milsim_respawn_setting_maxRangeToReady) &&
missionNamespace getVariable ["milsim_respawn_setting_reinsertion_enabled", true] &&
(_player distance _closestBase < milsim_respawn_setting_reinsertion_maxRangeToReady) &&
not (_player in ((missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) apply {_x#0})) not (_player in ((missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) apply {_x#0}))
} }
] call ace_interact_menu_fnc_createAction; ] call ace_interact_menu_fnc_createAction;
@@ -100,10 +113,12 @@ if (hasInterface) then {
{ {
params ["_target", "_player", "_params"]; params ["_target", "_player", "_params"];
["milsim_respawn_removeReinsertRequest", [_player]] call CBA_fnc_serverEvent; ["milsim_respawn_removeReinsertRequest", [_player]] call CBA_fnc_serverEvent;
"Re-insert Request has been rescinded." call CBA_fnc_notify; "Re-insert Request Rescinded" call CBA_fnc_notify;
}, },
{ {
params ["_target", "_player", "_params"]; params ["_target", "_player", "_params"];
missionNamespace getVariable ["milsim_respawn_setting_reinsertion_enabled", true] &&
(_player in ((missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) apply {_x#0})) (_player in ((missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) apply {_x#0}))
} }
] call ace_interact_menu_fnc_createAction; ] call ace_interact_menu_fnc_createAction;
@@ -149,7 +164,9 @@ if (hasInterface) then {
call milsim_respawn_fnc_showReinsertQueueNotification; call milsim_respawn_fnc_showReinsertQueueNotification;
}, },
{true} // always allow {
missionNamespace getVariable ["milsim_respawn_setting_reinsertion_enabled", true]
} // always allow
] call ace_interact_menu_fnc_createAction; ] call ace_interact_menu_fnc_createAction;
[_type, 1, ["ACE_SelfActions"], _checkReinsertQueueAction, true] call ace_interact_menu_fnc_addActionToClass; [_type, 1, ["ACE_SelfActions"], _checkReinsertQueueAction, true] call ace_interact_menu_fnc_addActionToClass;
@@ -169,8 +186,14 @@ if (hasInterface) then {
// ADD TIMER FOR PILOTS - IF REINSERT LIST NOT CHECKED FOR 20 MINUTES, SHOW NOTIFICATION AUTOMATICALLY // ADD TIMER FOR PILOTS - IF REINSERT LIST NOT CHECKED FOR 20 MINUTES, SHOW NOTIFICATION AUTOMATICALLY
if ((typeOf player) in ["B_Helipilot_F", "B_helicrew_F"]) then { if ((typeOf player) in ["B_Helipilot_F", "B_helicrew_F"]) then {
[{ [{
if (not (
missionNamespace getVariable ["milsim_respawn_setting_reinsertion_enabled", true]
)) exitWith {};
private _lastCheck = localNamespace getVariable ["milsim_respawn_lastReinsertQueueCheck", diag_tickTime]; private _lastCheck = localNamespace getVariable ["milsim_respawn_lastReinsertQueueCheck", diag_tickTime];
if (diag_tickTime - _lastCheck < (60*20)) exitWith {}; // if last check was less than 20 minutes ago, skip if (
diag_tickTime - _lastCheck <
missionNamespace getVariable ["milsim_respawn_setting_reinsertion_pilotForcedCheckInterval", 60*20]
) exitWith {}; // if last check was less than X minutes ago, skip
// if last check was greater than 20 minutes ago, we'll prompt the notification now and reset the timer // if last check was greater than 20 minutes ago, we'll prompt the notification now and reset the timer
localNamespace setVariable ["milsim_respawn_lastReinsertQueueCheck", diag_tickTime]; localNamespace setVariable ["milsim_respawn_lastReinsertQueueCheck", diag_tickTime];

View File

@@ -2,14 +2,37 @@ private _par = [["Players Awaiting Reinsert", 1.2, [1,0.64,0,1]]];
private _baseNames = (missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) apply {_x#1}; private _baseNames = (missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) apply {_x#1};
{ {
private _baseName = _x; private _baseName = _x;
_par pushBack [format ["Location: %1", _baseName], 1, [0,1,0,1]]; private _peopleAtThisBase = (missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) select {
{
_par pushBack _x;
} forEach ((missionNamespace getVariable ["milsim_respawn_reinsertionQueue", []]) select {
_x#1 isEqualTo _baseName _x#1 isEqualTo _baseName
} apply { } apply {
[name (_x#0), 0.7, [1,1,1,1]]; [name (_x#0), 0.7, [1,1,1,1]];
}); };
private _playerCountText = "";
switch (count _peopleAtThisBase) do {
case 0: {
_playerCountText = "No players";
};
case 1: {
_playerCountText = "1 player";
};
default {
_playerCountText = format ["%1 players", count _peopleAtThisBase];
};
};
_par pushBack [
format ["Location: %1 (%2)",
_baseName,
_playerCountText
],
1,
[0,1,0,1]
];
{
_par pushBack _x;
} forEach _peopleAtThisBase;
} forEach _baseNames; } forEach _baseNames;
_par call CBA_fnc_notify; _par call CBA_fnc_notify;

View File

@@ -125,6 +125,43 @@
] call CBA_fnc_addSetting; ] call CBA_fnc_addSetting;
//---------------------
// Respawn Settings
[
"milsim_respawn_setting_reinsertion_enabled", // variable
"CHECKBOX", // type
["Enabled", "Whether or not players can file for reinsert and pilots can check the reinsert queue"], // title
["17th Battalion", "Re-insert Queue"], // category
true, // default value
true, // global setting
{
params ["_value"];
diag_log format["[milsim] (respawn_reinsertion) enabled set to %1", _value];
}
] call CBA_fnc_addSetting;
[
"milsim_respawn_setting_reinsertion_maxRangeToReady", // variable
"SLIDER", // type
["Max Request Filing Range", "Maximum distance from a respawn point a player can be to ready up"], // title
["17th Battalion", "Re-insert Queue"], // category
[0, 1000, 400, 0, false], // [_min, _max, _default, _trailingDecimals, _isPercentage]
true, // global setting
{
params ["_value"];
diag_log format["[milsim] (respawn_reinsertion) max range to ready set to %1", _value];
}
] call CBA_fnc_addSetting;
[
"milsim_respawn_setting_reinsertion_pilotForcedCheckInterval", // variable
"SLIDER", // type
["Pilot Check Interval", "Pilots will be force shown the queue if they haven't checked it in X seconds"], // title
["17th Battalion", "Re-insert Queue"], // category
[60*10, 60*30, 60*20, 0, false], // [_min, _max, _default, _trailingDecimals, _isPercentage
true
] call CBA_fnc_addSetting;
diag_log text "[MILSIM] (settings) Custom CBA settings initialized"; diag_log text "[MILSIM] (settings) Custom CBA settings initialized";
nil; nil;