Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TakeControlContextAction.c
Go to the documentation of this file.
3 {
4  override bool CanBeShown(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags)
5  {
6  if (!hoveredEntity || !SCR_PossessingManagerComponent.GetInstance())
7  return false;
8 
9  GenericEntity owner = hoveredEntity.GetOwner();
10  if (!owner)
11  return false;
12 
13  BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(owner.FindComponent(BaseCompartmentManagerComponent));
14 
15  if (!compartmentManager)
16  {
17  SCR_EditableEntityComponent aiEntity = hoveredEntity.GetAIEntity();
18  if (!aiEntity || aiEntity.IsDestroyed())
19  return false;
20 
21  //--- Check if the entity is not a player
22  return SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(aiEntity.GetOwner()) <= 0;
23  }
24  else
25  {
26  return true;
27  }
28  }
29 
30  override bool CanBePerformed(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags)
31  {
32  if (!hoveredEntity || !SCR_PossessingManagerComponent.GetInstance())
33  return false;
34 
35  GenericEntity owner = hoveredEntity.GetOwner();
36  if (!owner)
37  return false;
38 
39  SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(owner.FindComponent(SCR_BaseCompartmentManagerComponent));
40 
41  if (!compartmentManager)
42  {
43  return CanBeShown(hoveredEntity, selectedEntities, cursorWorldPosition, flags);
44  }
45  else
46  {
47  array<IEntity> pilots = new array<IEntity>;
48  compartmentManager.GetOccupantsOfType(pilots, ECompartmentType.Pilot);
49 
50  if (pilots.IsEmpty() || !pilots[0])
51  return false;
52 
53  SCR_EditableEntityComponent pilotEditableEntity = SCR_EditableEntityComponent.Cast(pilots[0].FindComponent(SCR_EditableEntityComponent));
54  if (!pilotEditableEntity)
55  return false;
56 
57  SCR_EditableEntityComponent aiEntity = pilotEditableEntity.GetAIEntity();
58  if (!aiEntity || aiEntity.IsDestroyed())
59  return false;
60 
61  //--- Check if the entity is not a player
62  return SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(aiEntity.GetOwner()) <= 0;
63  }
64  }
65 
66  override void Perform(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags, int param = -1)
67  {
68  if (!hoveredEntity || !SCR_PossessingManagerComponent.GetInstance())
69  return;
70 
71  GenericEntity owner = hoveredEntity.GetOwner();
72  if (!owner)
73  return;
74 
75  SCR_EditableEntityComponent entityToControl;
76  SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(owner.FindComponent(SCR_BaseCompartmentManagerComponent));
77 
78  if (!compartmentManager)
79  {
80  entityToControl = hoveredEntity;
81  }
82  else
83  {
84  array<IEntity> pilots = new array<IEntity>;
85  compartmentManager.GetOccupantsOfType(pilots, ECompartmentType.Pilot);
86 
87  if (pilots.IsEmpty() || !pilots[0])
88  return;
89 
90  entityToControl = SCR_EditableEntityComponent.Cast(pilots[0].FindComponent(SCR_EditableEntityComponent));
91  }
92 
93  if (!entityToControl)
94  return;
95 
96  SCR_EditableEntityComponent aiEntity = entityToControl.GetAIEntity();
97  if (!aiEntity || aiEntity.IsDestroyed())
98  return;
99 
100  //--- Find player controller (param is playerID)
101  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(param));
102  if (!playerController)
103  return;
104 
105  playerController.SetPossessedEntity(aiEntity.GetOwner());
106 
107  //--- Close the editor (ToDo: Move to lobby's OnPossessed event)
109  if (core)
110  {
111  SCR_EditorManagerEntity manager = core.GetEditorManager(param);
112  if (manager)
113  manager.Close();
114  }
115  }
116  override int GetParam()
117  {
118  return GetGame().GetPlayerController().GetPlayerId();
119  }
120  override bool IsServer()
121  {
122  return true;
123  }
124 };
SCR_BaseEditorAction
Definition: SCR_BaseEditorAction.c:24
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_TakeControlContextAction
Definition: SCR_TakeControlContextAction.c:2
SCR_BaseContainerCustomTitleUIInfo
void SCR_BaseContainerCustomTitleUIInfo(string propertyName, string format="%1")
Definition: Attributes.c:788
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26