Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectator - Allow spectator on player or a group only #218

Merged
merged 17 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions addons/spectator/CfgFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class CfgFunctions
{
class A3_Expansion_A
{
class Spectator
{
class EGSpectator
{
file = QPATHTOF(functions\DOUBLES(fnc,EGSpectator).sqf);
};
class EGSpectatorCore
{
file = QUOTE(A3\Functions_F_Exp_A\EGSpectator\fn_EGSpectator.sqf);
};
class RscDisplayEGSpectatorCore
{
file = QUOTE(A3\Ui_F\Scripts\Gui\rscdisplayegspectator.sqfc);
veteran29 marked this conversation as resolved.
Show resolved Hide resolved
3Mydlo3 marked this conversation as resolved.
Show resolved Hide resolved
};
};
};
};
4 changes: 4 additions & 0 deletions addons/spectator/CfgScriptPaths.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class CfgScriptPaths
{
AFModsSpectatorGUI = QPATHTOF(functions\);
3Mydlo3 marked this conversation as resolved.
Show resolved Hide resolved
};
5 changes: 5 additions & 0 deletions addons/spectator/RscDisplayEGSpectator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RscDisplayEGSpectator
{
scriptName = "rscdisplayegspectator";
3Mydlo3 marked this conversation as resolved.
Show resolved Hide resolved
scriptPath = "AFModsSpectatorGUI";
3Mydlo3 marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 1 addition & 0 deletions addons/spectator/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREP(canSpectate);
PREP(disable);
PREP(EGSpectator); // This duplicated as BIS_fnc_EGSpectator in CfgFunctions so that BI scripts use updated version
PREP(enable);
PREP(reloadLocal);
PREP(restart);
Expand Down
6 changes: 5 additions & 1 deletion addons/spectator/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class CfgPatches {
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"afm_common"
"afm_common",
"A3_Functions_F_Exp_A"
};
author = "ArmaForces";
VERSION_CONFIG;
Expand All @@ -16,3 +17,6 @@ class CfgPatches {


#include "CfgEventHandlers.hpp"
#include "CfgFunctions.hpp"
#include "CfgScriptPaths.hpp"
#include "RscDisplayEGSpectator.hpp"
130 changes: 130 additions & 0 deletions addons/spectator/functions/fnc_EGSpectator.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Enhanced original BIS_fnc_EGSpectator to support array of units/groups as spectator targets instead of sides only.
*
* Arguments:
* 1: _whitelistedSides - Changed to support units/groups too.
*
* Public: No
*/

/*
Author:
Nelson Duarte

Description:
Spectator instance

Returns:
Multiple values / none

Examples:
["Initialize", [player]] call BIS_fnc_EGSpectator; // Initializes spectator for given player
["Terminate"] call BIS_fnc_EGSpectator; // Terminates spectator for given player
*/

// Do not execute from within 3DEN
if (count (supportInfo "n:is3DEN") > 0 && { is3DEN }) exitWith {};

// Do not serialize this script
disableSerialization;

// Name of this script
scriptName "BIS_fnc_EGSpectator";

// Common spectator defines
#include "\A3\Functions_F_Exp_A\EGSpectatorCommonDefines.inc"

// Parameters
private _mode = _this param [0, "", [""]];
private _params = _this param [1, [], [[]]];

if (_mode != "GetTargetEntities" && _mode != "GetTargetGroups") exitWith {
private _return = _this call BIS_fnc_EGSpectatorCore;

// isNil check is needed to prevent warnings in scheduled
if (isNil "_return") exitWith {};
_return // return
};

// Sub functions
switch (_mode) do
{
/**
* Returns entities that are visible to the spectator
*/
case "GetTargetEntities" :
{
private _allowAi = missionNamespace getVariable [VAR_ALLOW_AI_SWITCH, false];
private _whitelist = missionNamespace getVariable [VAR_WHITELISTED_SIDES, []];
private _whitelistEmpty = count _whitelist < 1;
private _entities = [];
private _validEntities = [];

// AI filter
if (_allowAi) then
{
_entities = allUnits;
}
else
{
_entities = [] call BIS_fnc_listPlayers;
};

// Side filter
{
if
(
simulationEnabled _x && {simulationEnabled vehicle _x} &&
{ !isObjectHidden _x && {!isObjectHidden vehicle _x} } &&
{ !(_x isKindOf SPECTATOR_CLASS) } &&
// Added '|| { group _x in _whitelist || {_x in _whitelist}}' to support unit/group
{ (_whitelistEmpty || { side group _x in _whitelist || { group _x in _whitelist || {_x in _whitelist}}}) }
) then
{
_validEntities pushBack _x;
};
} forEach _entities;

// hint str _validEntities;

_validEntities;
};

/**
* Returns groups that are visible to the spectator
*/
case "GetTargetGroups" :
{
private _allowAi = missionNamespace getVariable [VAR_ALLOW_AI_SWITCH, false];
private _whitelist = missionNamespace getVariable [VAR_WHITELISTED_SIDES, []];
private _whitelistEmpty = count _whitelist < 1;
private _groups = [];
private _validGroups = [];

// AI filter
if (_allowAi) then
{
_groups = allGroups;
}
else
{
private _players = [] call BIS_fnc_listPlayers;
{ _groups pushBackUnique (group _x); } forEach _players;
};

// Side and number of units filter
{
// if ((_whitelistEmpty || { side _x in _whitelist }) && {{!(_x isKindOf SPECTATOR_CLASS)} count units _x > 0 }) then
if ((_whitelistEmpty || { side _x in _whitelist || { _x in _whitelist || units _x findIf {_x in _whitelist} != -1 }}) && {{!(_x isKindOf SPECTATOR_CLASS)} count units _x > 0 }) then
{
_validGroups pushBack _x;
};
} forEach _groups;

// hint str _validGroups;

_validGroups;
};
};
4 changes: 4 additions & 0 deletions addons/spectator/functions/fnc_start.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ private _whitelistedSides = switch _sides do {
case 1: {[playerSide]};
// All sides spectator
case 2: {[WEST, INDEPENDENT, EAST]};
// Player group only
case 3: {[group player]};
// Player only
case 4: {[player]};
default {playerSide call BIS_fnc_friendlySides};
};

Expand Down
Loading
Loading