Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
CharacterCinematicTrack.c
Go to the documentation of this file.
1[CinematicTrackAttribute(name:"Character Track", description:"Allows you to control characters")]
3{
4
5 [Attribute("0.0", params: "0.0 3.0")]
6 float m_fMoveSpeed;
7
8 [Attribute("1.0", params: "-1.0 1.0")]
9 float m_fForwardBackward;
10
11 [Attribute("0.0", params: "-1.0 1.0")]
12 float m_fStrafeLeftRight;
13
14 [Attribute("0.0", params: "-3.0 3.0")]
15 float m_fHeadingAngle;
16
17 [Attribute("0", params: "-1.5 1.5")]
18 float m_fAimingLeftRight;
19
20 [Attribute("0.0", params: "-1.5 1.5")]
21 float m_fAimingDownUp;
22
23 [Attribute("1.0", params: "0.0 1.0")]
24 float m_fStance;
25
26 [Attribute("false")]
27 bool m_bRollLeft;
28
29 [Attribute("false")]
30 bool m_bRollRight;
31
32 [Attribute("true")]
33 bool m_bWeaponRised;
34
35 [Attribute("0", params: "0 1")]
36 int m_iMuzzle;
37
38 [Attribute("1", params: "1 3")]
39 int m_iFireMode;
40
41 [Attribute("")]
42 string m_sWhatToEquip;
43
44 [Attribute("")]
45 string m_sEntityToAim;
46
48 void jump()
49 {
50 if (m_Character && m_Character_c)
51 m_Character_c.SetJump(1.0);
52 }
53
55 void reload()
56 {
57 if (m_Character_c)
58 {
59 m_Character_c.ReloadWeapon();
60 }
61 }
62
64 void equipMuzzle()
65 {
66 if (m_Character_c)
67 {
68 m_Character_c.SetMuzzle(m_iMuzzle);
69 GetGame().GetCallqueue().CallLater(RefreshWeapon, 100);
70 }
71 }
72
74 void singleShoot()
75 {
76 if (m_Character_c)
77 {
78 m_Character_c.SetSafety(false,false);
79 m_Character_c.SetMuzzle(m_iMuzzle);
80 m_Character_c.SetFireMode(m_iFireMode);
81 m_Character_c.SetFireWeaponWanted(1);
82
83 GetGame().GetCallqueue().CallLater(RefreshWeapon, 100);
84 }
85 }
86
88 void autoShootStart()
89 {
90 if (m_Character_c)
91 {
92 m_Character_c.SetSafety(false,false);
93 m_Character_c.SetMuzzle(m_iMuzzle);
94 m_Character_c.SetFireMode(m_iFireMode);
95 m_Character_c.SetFireWeaponWanted(1);
96 }
97 }
98
100 void autoShootEnd()
101 {
102 if (m_Character_c)
103 {
104 m_Character_c.SetSafety(false,false);
105 m_Character_c.SetMuzzle(m_iMuzzle);
106 m_Character_c.SetFireMode(m_iFireMode);
107 m_Character_c.SetFireWeaponWanted(0);
108 }
109 }
110
112 void die()
113 {
114 if (m_Character_c)
115 {
116 m_Character_c.ForceDeath();
117 }
118 }
119
121 void throwStart()
122 {
123 CharacterGrenadeSlotComponent grenade = CharacterGrenadeSlotComponent.Cast(m_Character.FindComponent(CharacterGrenadeSlotComponent));
124 if (m_Character_c && grenade)
125 {
126 m_Character_c.SelectWeapon(grenade);
127 m_Character_c.SetThrow(true, false);
128 }
129 }
130
132 void throwEnd()
133 {
134 CharacterGrenadeSlotComponent grenade = CharacterGrenadeSlotComponent.Cast(m_Character.FindComponent(CharacterGrenadeSlotComponent));
135 if (m_Character_c && grenade)
136 {
137 m_Character_c.SelectWeapon(grenade);
138 m_Character_c.SetThrow(false, false);
139 }
140 }
141
143 void actionGetInPilot()
144 {
145 getIn = true;
146 compType = ECompartmentType.PILOT;
147 if (m_Character)
148 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionGetIn);
149 }
150
152 void actionGetOutPilot()
153 {
154 getIn = false;
155 compType = ECompartmentType.PILOT;
156 if (m_Character)
157 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionGetIn);
158 }
159
161 void actionGetInCargo()
162 {
163 getIn = true;
164 compType = ECompartmentType.CARGO;
165 if (m_Character)
166 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionGetIn);
167 }
168
170 void actionGetOutCargo()
171 {
172 getIn = false;
173 compType = ECompartmentType.CARGO;
174 if (m_Character)
175 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionGetIn);
176 }
177
179 void actionGetInTurret()
180 {
181 getIn = true;
182 compType = ECompartmentType.TURRET;
183 if (m_Character)
184 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionGetIn);
185 }
186
188 void actionGetOutTurret()
189 {
190 getIn = false;
191 compType = ECompartmentType.TURRET;
192 if (m_Character)
193 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionGetIn);
194 }
195
197 void actionEquip()
198 {
199 if (m_Character)
200 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionEquip);
201 }
202
204 void actionActivate()
205 {
206 if (m_Character)
207 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionActivate);
208 }
209
211 void actionOpen()
212 {
213 if (m_Character)
214 actualWorld.QueryEntitiesBySphere(m_Character.GetOrigin(), 3, PerformActionOpen);
215 }
216
217 private World actualWorld;
218 private GenericEntity m_Character;
219 private CharacterControllerComponent m_Character_c;
220 private float previousMoveSpeed;
221 private vector originalYawPitchRoll;
222 private string m_sLastActionName;
223
224 private bool getIn;
225 private ECompartmentType compType;
226
227 override void OnInit(World world)
228 {
229 // Find character entity by using name of track
230 findCharacter(world);
231
232 actualWorld = world;
233
234 if (m_Character) {
235
236 m_Character_c = CharacterControllerComponent.Cast(m_Character.FindComponent(CharacterControllerComponent));
237
238 if (m_Character_c) {
239
240 //Getting original heading angle of character
241 originalYawPitchRoll = m_Character.GetYawPitchRoll();
242 }
243 }
244 }
245
246 void findCharacter(World world)
247 {
248 // Find particle entity by using name of track
249 TStringArray strs = new TStringArray;
250 GetTrackName().Split("_", strs, true);
251
252 m_Character = GenericEntity.Cast(world.FindEntityByName(strs.Get(0)));
253 }
254
255 // Weapon need to be refreshed after while to keep possibility to fire again
256 void RefreshWeapon()
257 {
258 if (m_Character_c)
259 m_Character_c.SetFireWeaponWanted(0);
260 }
261
262
263 override void OnApply(float time)
264 {
265
266 if (m_Character && m_Character_c)
267 {
268
269 //Dynamic stance
270 m_Character_c.SetDynamicStance(m_fStance);
271
272
273 //Character animations are not smooth in the interval of (0, 0.5), setting to 0.5 for lower values
274 if (m_fMoveSpeed > 0 && m_fMoveSpeed < 0.5)
275 m_fMoveSpeed = 0.5;
276 else if (m_fMoveSpeed > 2)
277 m_bWeaponRised = false;
278
279 //This is called only when the moving speed is changing on timeline
280 if (previousMoveSpeed != m_fMoveSpeed)
281 {
282 vector move = {m_fStrafeLeftRight, 0, m_fForwardBackward};
283 m_Character_c.SetMovement(m_fMoveSpeed, move);
284 }
285
286 //Checking expresion if moving value is changing on timeline
287 previousMoveSpeed = m_fMoveSpeed;
288
289 //Heading and Aiming angles
290 m_Character_c.SetHeadingAngle( Math.DEG2RAD * originalYawPitchRoll[0] + m_fHeadingAngle, false);
291
292 //Aiming angle
293 if (m_sEntityToAim == "")
294 {
295 float x_rad = Math.DEG2RAD * originalYawPitchRoll[0] + m_fHeadingAngle + m_fAimingLeftRight;
296 float y_rad = m_fAimingDownUp;
297 vector aiming_vector = {x_rad, y_rad, 0};
298 m_Character_c.GetInputContext().SetAimingAngles( aiming_vector );
299 }
300 else
301 {
302 GenericEntity target = GenericEntity.Cast(actualWorld.FindEntityByName(m_sEntityToAim));
303 if(target)
304 {
305 vector shooterTransform[4], aimingTransform[4], aimingRotation[3];
306 vector direction = vector.Direction(m_Character.GetOrigin(), target.GetOrigin());
307 m_Character.GetWorldTransform(shooterTransform);
308 vector shooterUp = shooterTransform[1];
309 Math3D.DirectionAndUpMatrix(direction,shooterUp,aimingTransform);
310 aimingRotation[0] = aimingTransform[0];
311 aimingRotation[1] = aimingTransform[1];
312 aimingRotation[2] = aimingTransform[2];
313 vector resultAngles = Math3D.MatrixToAngles(aimingRotation);
314 vector finalRadAngles;
315 finalRadAngles[0] = resultAngles[0] * Math.DEG2RAD;
316 finalRadAngles[1] = resultAngles[1] * Math.DEG2RAD;
317 finalRadAngles[2] = resultAngles[2] * Math.DEG2RAD;
318
319 m_Character_c.GetInputContext().SetAimingAngles( finalRadAngles );
320 }
321
322 }
323
324 //Rolling to left
325 if (m_bRollLeft)
326 m_Character_c.SetRoll(1);
327 else
328 m_Character_c.SetRoll(0);
329
330 //Rolling to right
331 if (m_bRollRight)
332 m_Character_c.SetRoll(2);
333 else
334 m_Character_c.SetRoll(0);
335
336 //Rising weapon
337 if (m_bWeaponRised)
338 m_Character_c.SetWeaponRaised(true);
339 else
340 m_Character_c.SetWeaponRaised(false);
341 }
342 }
343
344 bool PerformActionGetIn(IEntity entity)
345 {
346
347 SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(entity.FindComponent(SCR_BaseCompartmentManagerComponent));
348 if (!compartmentManager)
349 return true;
350 array<BaseCompartmentSlot> slots = {};
351
352 if (getIn)
353 compartmentManager.GetFreeCompartmentsOfType(slots, compType);
354 else
355 compartmentManager.GetCompartmentsOfType(slots, compType);
356
357 if (!slots.IsEmpty())
358 {
359 BaseCompartmentSlot slot = slots[0];
360 BaseUserAction getInAction;
361
362 if (getIn)
363 getInAction = slot.GetGetInAction();
364 else
365 getInAction = slot.GetGetOutAction();
366
367 ActionsPerformerComponent actionsPerformer = ActionsPerformerComponent.Cast(m_Character.FindComponent(ActionsPerformerComponent));
368 actionsPerformer.PerformAction(getInAction);
369
370 return false;
371 }
372
373 return true;
374 }
375
376 bool PerformActionEquip(IEntity entity)
377 {
379 if (!actionsManager)
380 return true;
381
382 array<BaseUserAction> outActions = {};
383 actionsManager.GetActionsList(outActions);
384
385 foreach (BaseUserAction openAction : outActions)
386 {
387 if (openAction.GetOwner().GetName() == m_sWhatToEquip && openAction.GetActionName().Contains("Equip"))
388 {
389 ActionsPerformerComponent actionsPerformer = ActionsPerformerComponent.Cast(m_Character.FindComponent(ActionsPerformerComponent));
390 actionsPerformer.PerformAction(openAction);
391 return true;
392 }
393 }
394
395 return true;
396 }
397
398 bool PerformActionActivate(IEntity entity)
399 {
401 if (!actionsManager)
402 return true;
403
404 array<BaseUserAction> outActions = {};
405 actionsManager.GetActionsList(outActions);
406
407 foreach (BaseUserAction openAction : outActions)
408 {
409 if (openAction.GetOwner().GetName() == m_sWhatToEquip && openAction.GetActionName().Contains("Activate"))
410 {
411 ActionsPerformerComponent actionsPerformer = ActionsPerformerComponent.Cast(m_Character.FindComponent(ActionsPerformerComponent));
412 actionsPerformer.PerformAction(openAction);
413 return true;
414 }
415 }
416
417 return true;
418 }
419
420 bool PerformActionOpen(IEntity entity)
421 {
422
424 if (!actionsManager)
425 return true;
426
427 array<BaseUserAction> outActions = {};
428 actionsManager.GetActionsList(outActions);
429
430 foreach (BaseUserAction openAction : outActions)
431 {
432
433 DoorComponent door = DoorComponent.Cast(openAction.GetOwner().FindComponent(DoorComponent));
434 if (!door)
435 continue;
436
437 if (openAction.GetActionName().Contains("Open"))
438 {
439 ActionsPerformerComponent actionsPerformer = ActionsPerformerComponent.Cast(m_Character.FindComponent(ActionsPerformerComponent));
440 actionsPerformer.PerformAction(openAction);
441 return false;
442 }
443 }
444
445 return true;
446 }
447}
ECompartmentType
ArmaReforgerScripted GetGame()
Definition game.c:1398
void CinematicEventAttribute(string name="")
Definition attributes.c:18
vector direction
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
Definition Math.c:13
Definition World.c:16
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385