Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_doorOpener.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Utility", description: "Opens door in certain radius.")]
2 class SCR_DoorOpenerEntityClass : GenericEntityClass
3 {
4 };
5 
6 // doorComp.GetOwner() would solve the need for this
7 class DoorStruct
8 {
9  IEntity owner;
10  DoorComponent component;
11 
12  void DoorStruct(IEntity e, DoorComponent comp)
13  {
14  this.owner = e;
15  this.component = comp;
16  }
17 };
18 
20 {
21  [Attribute(defvalue: "10", uiwidget: UIWidgets.Slider, desc: "Radius in which to open door.", "0 1000 1")]
22  protected float m_fRadius;
23 
24  [Attribute(defvalue: "1", uiwidget: UIWidgets.Slider, desc: "How much the doors should be opened", "0. 1 0.01")]
25  protected float m_fControlValue;
26 
27 
28  private ref array<ref DoorStruct> m_aQueriedDoors;
29 
30  #ifdef WORKBENCH
31  private bool m_bVisualize;
32  #endif
33 
34  //------------------------------------------------------------------------------------------------
35  private bool QueryEntities(IEntity e)
36  {
37  DoorComponent door = DoorComponent.Cast(e.FindComponent(DoorComponent));
38  if (door)
39  m_aQueriedDoors.Insert(new DoorStruct(e, door));
40 
41  return true;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  private void GetDoors(float radius)
46  {
47  BaseWorld world = GetWorld();
48  world.QueryEntitiesBySphere(GetOrigin(), radius, QueryEntities);
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  override void EOnInit(IEntity owner)
53  {
54  // server only
55  RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
56  if (rplComponent && !rplComponent.IsMaster())
57  return;
58 
59  // capture doors around
60  m_aQueriedDoors = {};
61  GetDoors(m_fRadius);
62  // set state
63  foreach (DoorStruct door : m_aQueriedDoors)
64  door.component.SetControlValue(m_fControlValue);
65 
66  // cleanup
67  m_aQueriedDoors.Clear();
68  m_aQueriedDoors = null;
69 
70  // destroy self
71  delete owner;
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  void SCR_DoorOpenerEntity(IEntitySource src, IEntity parent)
76  {
77  if (SCR_Global.IsEditMode(this))
78  return;
79 
80  SetEventMask(EntityEvent.INIT);
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  void ~SCR_DoorOpenerEntity()
85  {
86  }
87 
88  #ifdef WORKBENCH
89 
90  private void _CaptureDoors()
91  {
92  m_aQueriedDoors = {};
93  GetDoors(m_fRadius);
94  }
95 
96  override bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
97  {
98  _CaptureDoors();
99  return super._WB_OnKeyChanged(src, key, ownerContainers, parent);
100  }
101 
102  override void _WB_SetExtraVisualiser(EntityVisualizerType type, IEntitySource src)
103  {
104  m_bVisualize = false;
105  switch (type)
106  {
107  case EntityVisualizerType.EVT_NONE:
108  return;
109 
110  case EntityVisualizerType.EVT_NORMAL:
111  return;
112  }
113 
114  m_bVisualize = true;
115  _CaptureDoors();
116  super._WB_SetExtraVisualiser(type, src);
117  }
118 
119  override void _WB_AfterWorldUpdate(float timeSlice)
120  {
121  if (m_bVisualize)
122  {
123  auto origin = GetOrigin();
124  auto radiusShape = Shape.CreateSphere(COLOR_YELLOW, ShapeFlags.WIREFRAME | ShapeFlags.ONCE, origin, m_fRadius);
125 
126  foreach (DoorStruct door : m_aQueriedDoors)
127  {
128  auto arrowShape = Shape.CreateArrow(origin, door.owner.GetOrigin(), 0.1, COLOR_GREEN, ShapeFlags.ONCE);
129  }
130  }
131 
132  super._WB_AfterWorldUpdate(timeSlice);
133  }
134 
135  #endif
136 
137 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
SCR_DoorOpenerEntity
Definition: SCR_doorOpener.c:19
DoorStruct
Definition: SCR_doorOpener.c:7
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_fRadius
float m_fRadius
Definition: SCR_AITargetClusterState.c:30
DoorComponent
Definition: DoorComponent.c:12
SCR_Global
Definition: Functions.c:6
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_DoorOpenerEntityClass
Definition: SCR_doorOpener.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180