Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ExplosionGenerator.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Test", description: "This is used for explosion stress tests")]
2 class SCR_ExplosionGeneratorClass: GenericEntityClass
3 {
4 };
5 
7 {
8  [Attribute("", UIWidgets.ResourceAssignArray, "Generated explosions will loop through the projectiles on this array", "et")]
9  ref array<ResourceName> m_ProjectilesToTrigger;
10 
11  //Initial values
12  [Attribute("0", UIWidgets.EditBox, "Number of explosions to create. 0 = until time ends")]
13  int m_NumExplosions;
14 
15  [Attribute("0", UIWidgets.EditBox, "Time until this entity creates a new explosion.")]
16  float m_TimeBetweenExplosions;
17 
18  [Attribute("0", UIWidgets.EditBox, "Time (in seconds) until no more explosions are generated. This is not needed if Num Explosions is different to 0")]
19  float m_TotalDuration;
20 
21  // current values
22  ref array<ref Resource> m_LoadedPrefabs = new array<ref Resource>();
23 
24  int m_RemainingExplosions = 0;
25  float m_TimeUntilNextExplosion = 0;
26  float m_RemainingDuration = 0;
27 
28 
29  //keeps track of what explosion prefab will be used
30  int m_CurrentExplosionPrefab = 0;
31 
32 
33  //------------------------------------------------------------------------------------------------
34  void SCR_ExplosionGenerator(IEntitySource src, IEntity parent)
35  {
36  SetEventMask(EntityEvent.FRAME);
37 
38  for(int i = 0; i < m_ProjectilesToTrigger.Count(); i++)
39  {
40  if(m_ProjectilesToTrigger[i])
41  m_LoadedPrefabs.Insert(Resource.Load(m_ProjectilesToTrigger[i]));
42  }
43 
44  m_RemainingExplosions = m_NumExplosions;
45  m_TimeUntilNextExplosion = m_TimeBetweenExplosions;
46  m_RemainingDuration = m_TotalDuration;
47  }
48 
49  //------------------------------------------------------------------------------------------------
50  override protected void EOnFrame(IEntity owner, float timeSlice) //EntityEvent.FRAME
51  {
52  //end conditions, no need to keep updating the object
53  if (m_NumExplosions == 0 && m_RemainingDuration < 0 || m_NumExplosions != 0 && m_RemainingExplosions <= 0)
54  {
55  ClearEventMask(EntityEvent.FRAME);
56  return;
57  }
58 
59  m_TimeUntilNextExplosion -= timeSlice;
60  m_RemainingDuration -= timeSlice;
61 
62  //no explosion
63  if (m_TimeUntilNextExplosion > 0)
64  return;
65 
66  //added instead of assigned to ensure accuracy
67  m_TimeUntilNextExplosion += m_TimeBetweenExplosions;
68 
69  CreateExplosion(owner);
70  }
71 
72  protected void CreateExplosion(IEntity owner)
73  {
74  ref Resource prefab = m_LoadedPrefabs[m_CurrentExplosionPrefab];
75 
76  AdvanceExplosionPrefab();
77 
78  m_RemainingExplosions--;
79 
80  if (!prefab)
81  return;
82 
83  ref EntitySpawnParams spawnParams = new EntitySpawnParams();
84 
85  spawnParams.TransformMode = ETransformMode.WORLD;
86  owner.GetTransform(spawnParams.Transform);
87 
88  IEntity spawnedProjectile = GetGame().SpawnEntityPrefab(prefab, owner.GetWorld(), spawnParams);
89 
90  Managed managedComp = spawnedProjectile.FindComponent(BaseTriggerComponent);
91 
92  BaseTriggerComponent comp = BaseTriggerComponent.Cast(managedComp);
93 
94  if(comp)
95  comp.OnUserTrigger(spawnedProjectile);
96  }
97 
98  //------------------------------------------------------------------------------------------------
99 
100  protected void AdvanceExplosionPrefab()
101  {
102  ++m_CurrentExplosionPrefab;
103 
104  if (m_CurrentExplosionPrefab >= m_LoadedPrefabs.Count())
105  m_CurrentExplosionPrefab = 0;
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  void ~SCR_ExplosionGenerator()
110  {
111  }
112 };
113 
BaseTriggerComponent
Definition: BaseTriggerComponent.c:12
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_ExplosionGeneratorClass
Definition: SCR_ExplosionGenerator.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ExplosionGenerator
Definition: SCR_ExplosionGenerator.c:6
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180