Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SectorSpawn.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Gamemodes", description: "Combat Area 3")]
2 class SCR_SectorSpawnClass: GenericEntityClass
3 {
4 
5 };
6 
8 {
9  [Attribute("10 5 10", UIWidgets.EditBox, "Size of box")]
10  vector m_size;
11  [Attribute("1", UIWidgets.CheckBox, "Show prefab preview?")]
12  bool m_showPreview;
13 
14  void SCR_SectorSpawn(IEntitySource src, IEntity parent)
15  {
16  SetFlags(EntityFlags.ACTIVE);
17  SetEventMask(EntityEvent.INIT | EntityEvent.TOUCH | EntityEvent.CONTACT);
18  }
19 
20  void ~SCR_SectorSpawn()
21  {
22  // cleanup
23  }
24 
25  override private void EOnInit(IEntity owner)
26  {
27  //Print("SectorSpawn initialized.");
28  autoptr PhysicsGeomDef geoms[] = {PhysicsGeomDef("", PhysicsGeom.CreateBox(m_size), "material/default", EPhysicsLayerDefs.Vehicle | EPhysicsLayerDefs.Character)};
29  Physics.CreateGhostEx(this, geoms);
30  //SpawnChildren("{8F21EDDBADC889FE}entities/Survival/Apple.et");
31  }
32 
33 
34 
35 #ifdef WORKBENCH
36  //-----------------------------------------------------------------------------------------------------------
37  override void _WB_AfterWorldUpdate(float timeSlice)
38  {
39  Shape dbgShape = null;
40  int color = ARGB(64, 0x33, 0x66, 0x99);
41  vector m_start = {m_size[0] * -0.5, m_size[1] * -0.5, m_size[2] * -0.5};
42  vector m_end = {m_size[0] * 0.5, m_size[1] * 0.5, m_size[2] * 0.5};
43 
44  dbgShape = Shape.Create(ShapeType.BBOX, color, ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE, m_start, m_end);
45 
46  vector mat[4];
47  GetWorldTransform(mat);
48  dbgShape.SetMatrix(mat);
49  }
50  override bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
51  {
52  // event when changing shape or position of the trigger in WB
53  bool m_showPreviewLocal;
54  src.Get("m_showPreview",m_showPreviewLocal);
55  if (m_showPreviewLocal)
56  {
57  SpawnPreview();
58  }
59  else
60  {
61  DespawnChildren();
62  }
63  return false;
64  }
65 
66 #endif
67 
68 
69 
70  override private void EOnTouch(IEntity owner, IEntity other, int touchTypesMask)
71  {
72  PrintFormat("OnTouch triggered by entity %1 of type %2", other,touchTypesMask);
73 
74  }
75 
76  override private void EOnContact(IEntity owner, IEntity other, Contact contact)
77  {
78  PrintFormat("OnContact triggered by entity %1 of type %2", other, contact);
79  }
80 
81  void SpawnPreview()
82  {
83  IEntity child = this.GetChildren();
84  vector camMatrix[4];
85 
86 #ifdef WORKBENCH
87  WorldEditorAPI m_API = _WB_GetEditorAPI();
88  if (!child)
89  {
90  Print("No children of sector spawn found!");
91  }
92  while (child)
93  {
94  SCR_SectorPrefabSpawnPoint prefabSpawnPoint = SCR_SectorPrefabSpawnPoint.Cast(child);
95  vector mat[4];
96  prefabSpawnPoint.GetWorldTransform(mat);
97 
98  if (prefabSpawnPoint.ShouldSnapToGround())
99  {
100  vector position = mat[3];
101  position[1] = prefabSpawnPoint.GetWorld().GetSurfaceY(position[0], position[2]);
102  mat[3] = position;
103  }
104  EntitySpawnParams spawnParams = new EntitySpawnParams;
105  spawnParams.TransformMode = ETransformMode.WORLD;
106  spawnParams.Transform = mat;
107  Resource resource = Resource.Load(prefabSpawnPoint.m_sLoadoutResource);
108 
109  //IEntity entity = m_API.CreateEntity(prefab, "moje " + index, m_API.GetCurrentEntityLayerId(), m_API.EntityToSource(prefabSpawnPoint),vector.Zero, vector.Zero);
110 
111  IEntity entity = GetGame().SpawnEntityPrefab(resource, m_API.GetWorld(), spawnParams);
112 
113  if (!entity)
114  {
115  Print("Something is awfully wrong somewhere");
116  }
117  else
118  {
119  prefabSpawnPoint.AddChild(entity,0, EAddChildFlags.AUTO_TRANSFORM);
120  prefabSpawnPoint.GetWorldTransform(mat);
121  entity.SetWorldTransform(mat);
122  }
123  child = child.GetSibling();
124  }
125 #else
126  Print("Running game mode");
127 
128  //IEntity entity = GetGame().SpawnEntityPrefab(resource, null, spawnParams);
129 #endif
130  }
131 
132  void DespawnChildren()
133  {
134  IEntity spawnPoint = this.GetChildren();
135  while (spawnPoint)
136  {
137  IEntity ent = spawnPoint.GetChildren();
138  if (ent)
139  {
140  spawnPoint.RemoveChild(ent);
141  delete ent;
142  }
143  spawnPoint = spawnPoint.GetSibling();
144  }
145  }
146 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_SectorPrefabSpawnPoint
Definition: SCR_SectorPrefabSpawnPoint.c:6
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_SectorSpawn
Definition: SCR_SectorSpawn.c:7
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_SectorSpawnClass
Definition: SCR_SectorSpawn.c:2
GetChildren
void GetChildren(out array< SCR_ScenarioFrameworkLayerBase > children)
Definition: SCR_ScenarioFrameworkLayerBase.c:359
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180