Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayersPresentTriggerEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Triggers", description: "")]
3 {
4 };
5 
6 /*
7  The trigger invokes the onActivate event in case the number of the connected players of the given faction
8  is present in the trigger
9 */
10 
11 //O B S O L E T E !!! DON'T USE IT
12 //WILL BE DELETED
13 
14 class SCR_PlayersPresentTriggerEntity: SCR_BaseTriggerEntity
15 {
16  [Attribute(desc: "Faction which is used for area control calculation. Leave empty for any faction.", category: "Trigger")]
17  protected FactionKey m_sOwnerFactionKey;
18 
19  [Attribute("0", UIWidgets.ComboBox, "By whom the trigger is activated", "", ParamEnumArray.FromEnum(TA_EActivationPresence), category: "Trigger")]
20  protected TA_EActivationPresence m_eActivationPresence;
21 
22  /*
23  [Attribute(desc: "Trigger activation - all connected players of the given faction or just one?", category: "Trigger")]
24  protected bool m_bAllPlayersPresent;
25  */
26 
27  protected Faction m_OwnerFaction;
28  protected int m_iEntitiesInside = 0;
29 
30  //------------------------------------------------------------------------------------------------
31  void SetOwnerFaction(Faction faction)
32  {
33  m_OwnerFaction = faction;
34  }
35 
36  //------------------------------------------------------------------------------------------------
37  bool IsMaster()// IsServer
38  {
39  RplComponent comp = RplComponent.Cast(FindComponent(RplComponent));
40  return comp && comp.IsMaster();
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  protected int GetPlayersCountByFaction()
45  {
46  int iCnt = 0;
47  array<int> aPlayerIDs = {};
48  SCR_PlayerController playerController;
49  GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
50  foreach (int iPlayerID: aPlayerIDs)
51  {
52  playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(iPlayerID));
53  if (!playerController)
54  continue;
55 
56  if (playerController.GetLocalControlledEntityFaction() == m_OwnerFaction)
57  iCnt++;
58  }
59  return iCnt;
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected void GetPlayersByFaction(notnull out array<IEntity> aOut)
64  {
65  array<int> aPlayerIDs = {};
66  SCR_PlayerController playerController;
67  GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
68  foreach (int iPlayerID: aPlayerIDs)
69  {
70  playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(iPlayerID));
71  if (!playerController)
72  continue;
73 
74  if (playerController.GetLocalControlledEntityFaction() == m_OwnerFaction)
75  aOut.Insert(playerController.GetLocalMainEntity());
76  }
77  }
78 
79 
81  override bool ScriptedEntityFilterForQuery(IEntity ent)
82  {
83  if (!ChimeraCharacter.Cast(ent))
84  return false;
85 
86  // take only players
87  if (m_eActivationPresence == TA_EActivationPresence.PLAYER)
88  {
89  if (!EntityUtils.IsPlayer(ent))
90  return false;
91  }
92  if (m_sOwnerFactionKey.IsEmpty())
93  return true; //if faction is not specified, any faction can (de)activate the trigger
94 
95  FactionAffiliationComponent pFaciliation = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
96  if (!pFaciliation)
97  return false;
98 
99  return pFaciliation.GetAffiliatedFaction() == m_OwnerFaction;
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  override protected event void OnActivate(IEntity ent)
104  {
105  if (!IsMaster())
106  return;
107 
108  m_iEntitiesInside++;
109  if (m_eActivationPresence == TA_EActivationPresence.PLAYER || m_eActivationPresence == TA_EActivationPresence.ANY_CHARACTER)
110  {
111  m_OnActivate.Invoke(ent);
112  }
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  override protected event void OnDeactivate(IEntity ent)
117  {
118  m_iEntitiesInside--;
119  m_OnDeactivate.Invoke();
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  override protected void EOnInit(IEntity owner)
124  {
125  FactionManager factionManager = GetGame().GetFactionManager();
126  if (factionManager)
127  m_OwnerFaction = factionManager.GetFactionByKey(m_sOwnerFactionKey);
128  }
129 };
m_OwnerFaction
protected Faction m_OwnerFaction
Definition: SCR_CharacterTriggerEntity.c:64
SCR_PlayerController
Definition: SCR_PlayerController.c:31
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_PlayersPresentTriggerEntityClass
Definition: SCR_PlayersPresentTriggerEntity.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_eActivationPresence
protected TA_EActivationPresence m_eActivationPresence
Definition: SCR_CharacterTriggerEntity.c:20
m_OnActivate
SCR_BaseTriggerEntityClass m_OnActivate
Basic scripted trigger which offers external invoekrs for major events like activation or deactivatio...
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_PlayersPresentTriggerEntity
Definition: SCR_PlayersPresentTriggerEntity.c:14
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_OnDeactivate
protected ref ScriptInvoker m_OnDeactivate
Definition: SCR_BaseTriggerEntity.c:10
Faction
Definition: Faction.c:12
SCR_BaseTriggerEntityClass
Definition: SCR_BaseTriggerEntity.c:2
EntityUtils
Definition: EntityUtils.c:12
m_sOwnerFactionKey
protected FactionKey m_sOwnerFactionKey
Definition: SCR_CharacterTriggerEntity.c:17
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180