Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
InteractableBoxComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Test", description: "This brief script description.")]
2 class SCR_InteractableBoxComponentClass : ScriptComponentClass
3 {
4 }
5 
7 {
8  private bool m_bIsDragging = false;
9  private bool m_bIsOnFire = false;
10  private IEntity m_Owner = null;
11  private IEntity m_User = null;
12  private ParticleEffectEntity m_Fire = null;
13  private Physics m_Physics = null;
14  private float m_Lifetime = 10.0; // object can burn for 15 seconds before dying
15  private bool m_bIsDead = false;
16 
17  //------------------------------------------------------------------------------------------------
21  void ToggleIsOnFire(ResourceName particle, vector offset)
22  {
23  if (m_bIsDead)
24  {
25  if (m_Fire)
26  {
27  delete m_Fire;
28  m_Fire = null;
29  m_bIsOnFire = false;
30  }
31  return;
32  }
33 
35  if (m_bIsOnFire && particle != string.Empty)
36  {
37  if (!m_Fire)
38  {
39  ParticleEffectEntitySpawnParams spawnParams();
40  spawnParams.Parent = m_Owner;
41  spawnParams.Transform[3] = offset;
42  m_Fire = ParticleEffectEntity.SpawnParticleEffect(particle, spawnParams);
43  }
44  }
45  else
46  {
47  if (m_Fire)
48  {
49  m_Fire.Stop();
50  delete m_Fire;
51  m_Fire = null;
52  }
53  }
54  }
55 
56  //------------------------------------------------------------------------------------------------
59  bool IsDragging()
60  {
61  return m_bIsDragging;
62  }
63 
64  //------------------------------------------------------------------------------------------------
66  string GetActionName()
67  {
68  if (m_bIsDragging)
69  {
70  return "Let Go";
71  }
72  else
73  {
74  return "Drag";
75  }
76  }
77 
78  //------------------------------------------------------------------------------------------------
81  {
82  if (!m_bIsDragging)
83  {
84  return "Start dragging this object around.";
85  }
86  else
87  {
88  return "Let go of this object.";
89  }
90  }
91 
92  //------------------------------------------------------------------------------------------------
95  {
96  if (!m_bIsOnFire)
97  {
98  return "Use lighter to set this object on fire!";
99  }
100  else
101  {
102  return "Attempt to extinguish this object.";
103  }
104  }
105 
106  //------------------------------------------------------------------------------------------------
109  {
110  if (!m_bIsOnFire)
111  {
112  return "Burn";
113  }
114  else
115  {
116  return "Extinguish";
117  }
118  }
119 
120  //------------------------------------------------------------------------------------------------
123  {
124  if (m_bIsOnFire)
125  return false;
126 
127  return true;
128  }
129 
130  //------------------------------------------------------------------------------------------------
133  {
134  if (m_bIsDragging)
135  return false;
136 
137  return (!m_bIsDead);
138  }
139 
140  //------------------------------------------------------------------------------------------------
143  {
144  m_bIsDragging = false;
145  m_User = null;
146  }
147 
148  //------------------------------------------------------------------------------------------------
151  void PerformDragAction(IEntity user)
152  {
153  if (!m_Owner)
154  return;
155 
156  if (m_bIsOnFire)
157  return;
158 
160  if (m_bIsDragging)
161  {
162  m_User = user;
163  return;
164  }
165  else
166  {
167  m_User = null;
168  return;
169  }
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  override void EOnSimulate(IEntity owner, float timeSlice)
174  {
175  if (m_User && m_Owner && m_bIsDragging)
176  {
177  if (!m_Physics)
178  {
179  m_bIsDragging = false;
180  m_User = null;
181  }
182 
183  vector userMat[4];
184  m_User.GetWorldTransform(userMat);
185  vector userTgtPos = userMat[3] + userMat[2] * 1.3;
186  vector selfOrigin = m_Owner.GetOrigin();
187  vector dir = userTgtPos - selfOrigin;
188  dir[1] = Math.Clamp(dir[1], -0.5, 0.5);
189  float distance = vector.Distance(userTgtPos, selfOrigin);
190  if (distance > 1.5)
191  {
192  m_bIsDragging = false;
193  m_User = null;
194  return;
195  }
196 
197  float upMag = userMat[3][1] - selfOrigin[1];
198  dir += Vector(0, upMag, 0);
199  m_Physics.ApplyImpulse(dir * m_Physics.GetMass());
200  }
201  }
202 
203  //------------------------------------------------------------------------------------------------
204  private void OnDeath()
205  {
206  VObject obj = m_Owner.GetVObject();
207  string materials[256];
208  int numMats = obj.GetMaterials(materials);
209  string remap = "";
210  for (int i = 0; i < numMats; i++)
211  {
212  remap += "$remap '" + materials[i] + "' '{DD86C0AE16B22569}Assets/Props/Garbage/Data/MI_RubberForTrashBinContainer_01.emat';";
213  }
214  m_Owner.SetObject(obj, remap);
215 
216  ToggleIsOnFire(string.Empty, vector.Zero);
217  }
218 
219  //------------------------------------------------------------------------------------------------
220  override void EOnFrame(IEntity owner, float timeSlice)
221  {
222  if (m_bIsOnFire)
223  m_Lifetime -= timeSlice;
224  if (m_Lifetime < 0)
225  {
226  if (!m_bIsDead)
227  {
228  OnDeath();
229  m_bIsDead = true;
230  }
231  m_Lifetime = 0.0;
232  }
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  override void OnPostInit(IEntity owner)
237  {
238  super.OnPostInit(owner);
239  SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME | EntityEvent.SIMULATE);
240  }
241 
242  //------------------------------------------------------------------------------------------------
243  override void EOnInit(IEntity owner)
244  {
245  m_Physics = owner.GetPhysics();
246  }
247 
248  //------------------------------------------------------------------------------------------------
249  // constructor
253  void SCR_InteractableBoxComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
254  {
255  m_Owner = ent;
256  }
257 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
GetFireActionName
string GetFireActionName()
Definition: InteractableBoxComponent.c:108
GetActionDescription
string GetActionDescription()
Definition: InteractableBoxComponent.c:80
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
m_Owner
private IEntity m_Owner
Definition: InteractableBoxComponent.c:10
IsDragging
bool IsDragging()
Definition: InteractableBoxComponent.c:59
ToggleIsOnFire
void ToggleIsOnFire(ResourceName particle, vector offset)
Definition: InteractableBoxComponent.c:21
EOnSimulate
override void EOnSimulate(IEntity owner, float timeSlice)
Definition: InteractableBoxComponent.c:173
m_Physics
private Physics m_Physics
Definition: InteractableBoxComponent.c:13
OnDeath
private void OnDeath()
Definition: InteractableBoxComponent.c:204
SCR_InteractableBoxComponent
void SCR_InteractableBoxComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: InteractableBoxComponent.c:253
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: InteractableBoxComponent.c:220
CanPerformDragAction
bool CanPerformDragAction()
Definition: InteractableBoxComponent.c:122
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
SCR_InteractableBoxComponentClass
Definition: InteractableBoxComponent.c:2
m_bIsDragging
SCR_InteractableBoxComponentClass m_bIsDragging
m_Lifetime
private float m_Lifetime
Definition: InteractableBoxComponent.c:14
m_Fire
private ParticleEffectEntity m_Fire
Definition: InteractableBoxComponent.c:12
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: InteractableBoxComponent.c:236
GetFireActionDescription
string GetFireActionDescription()
Definition: InteractableBoxComponent.c:94
CanPerformToggleFire
bool CanPerformToggleFire()
Definition: InteractableBoxComponent.c:132
m_bIsDead
private bool m_bIsDead
Definition: InteractableBoxComponent.c:15
m_User
private IEntity m_User
Definition: InteractableBoxComponent.c:11
GetActionName
string GetActionName()
Definition: InteractableBoxComponent.c:66
EOnInit
override void EOnInit(IEntity owner)
Definition: InteractableBoxComponent.c:243
CancelDragAction
void CancelDragAction()
Definition: InteractableBoxComponent.c:142
PerformDragAction
void PerformDragAction(IEntity user)
Definition: InteractableBoxComponent.c:151
m_bIsOnFire
private bool m_bIsOnFire
Definition: InteractableBoxComponent.c:9
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180