Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
InteractableBoxComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Test", description: "This brief script description.")]
5
6class SCR_InteractableBoxComponent : ScriptComponent
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 float m_Lifetime = 10.0; // object can burn for 15 seconds before dying
14 private bool m_bIsDead = false;
15
16 //------------------------------------------------------------------------------------------------
20 void ToggleIsOnFire(ResourceName particle, vector offset)
21 {
22 if (m_bIsDead)
23 {
24 if (m_Fire)
25 {
26 delete m_Fire;
27 m_Fire = null;
28 m_bIsOnFire = false;
29 }
30 return;
31 }
32
33 m_bIsOnFire = !m_bIsOnFire;
34 if (m_bIsOnFire && particle != string.Empty)
35 {
36 if (!m_Fire)
37 {
39 spawnParams.Parent = m_Owner;
40 spawnParams.Transform[3] = offset;
41 m_Fire = ParticleEffectEntity.SpawnParticleEffect(particle, spawnParams);
42 }
43 }
44 else
45 {
46 if (m_Fire)
47 {
48 m_Fire.Stop();
49 delete m_Fire;
50 m_Fire = null;
51 }
52 }
53 }
54
55 //------------------------------------------------------------------------------------------------
58 bool IsDragging()
59 {
60 return m_bIsDragging;
61 }
62
63 //------------------------------------------------------------------------------------------------
65 string GetActionName()
66 {
67 if (m_bIsDragging)
68 {
69 return "Let Go";
70 }
71 else
72 {
73 return "Drag";
74 }
75 }
76
77 //------------------------------------------------------------------------------------------------
79 string GetActionDescription()
80 {
81 if (!m_bIsDragging)
82 {
83 return "Start dragging this object around.";
84 }
85 else
86 {
87 return "Let go of this object.";
88 }
89 }
90
91 //------------------------------------------------------------------------------------------------
93 string GetFireActionDescription()
94 {
95 if (!m_bIsOnFire)
96 {
97 return "Use lighter to set this object on fire!";
98 }
99 else
100 {
101 return "Attempt to extinguish this object.";
102 }
103 }
104
105 //------------------------------------------------------------------------------------------------
107 string GetFireActionName()
108 {
109 if (!m_bIsOnFire)
110 {
111 return "Burn";
112 }
113 else
114 {
115 return "Extinguish";
116 }
117 }
118
119 //------------------------------------------------------------------------------------------------
121 bool CanPerformDragAction()
122 {
123 if (m_bIsOnFire)
124 return false;
125
126 return true;
127 }
128
129 //------------------------------------------------------------------------------------------------
131 bool CanPerformToggleFire()
132 {
133 if (m_bIsDragging)
134 return false;
135
136 return (!m_bIsDead);
137 }
138
139 //------------------------------------------------------------------------------------------------
141 void CancelDragAction()
142 {
143 m_bIsDragging = false;
144 m_User = null;
145 }
146
147 //------------------------------------------------------------------------------------------------
150 void PerformDragAction(IEntity user)
151 {
152 if (!m_Owner)
153 return;
154
155 if (m_bIsOnFire)
156 return;
157
159 if (m_bIsDragging)
160 {
161 m_User = user;
162 return;
163 }
164 else
165 {
166 m_User = null;
167 return;
168 }
169 }
170
171 //------------------------------------------------------------------------------------------------
172 override void EOnSimulate(IEntity owner, float timeSlice)
173 {
174 if (m_User && m_Owner && m_bIsDragging)
175 {
176 Physics physics = m_Owner.GetPhysics();
177 if (!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 physics.ApplyImpulse(dir * 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 // constructor
247 void SCR_InteractableBoxComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
248 {
249 m_Owner = ent;
250 }
251}
SCR_InteractableBoxComponentClass m_bIsDragging
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
float distance
ChimeraCharacter m_User
string GetFireActionName()
string GetActionName()
void ParticleEffectEntity(IEntitySource src, IEntity parent)
enum EVehicleType IEntity
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external vector GetOrigin()
proto external Physics GetPhysics()
proto external VObject GetVObject()
Returns visual object set to this Entity. No reference is added.
void EOnFrame(IEntity owner, float timeSlice)
void EOnSimulate(IEntity owner, float timeSlice)
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto native vector Vector(float x, float y, float z)