Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SectorSpawn.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Gamemodes", description: "Combat Area 3")]
2class SCR_SectorSpawnClass: GenericEntityClass
3{
4
5};
6
7class SCR_SectorSpawn: GenericEntity
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 //-----------------------------------------------------------------------------------------------------------
38 {
39 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
40 }
41
42 //-----------------------------------------------------------------------------------------------------------
43 override void _WB_AfterWorldUpdate(float timeSlice)
44 {
45 Shape dbgShape = null;
46 int color = ARGB(64, 0x33, 0x66, 0x99);
47 vector m_start = {m_size[0] * -0.5, m_size[1] * -0.5, m_size[2] * -0.5};
48 vector m_end = {m_size[0] * 0.5, m_size[1] * 0.5, m_size[2] * 0.5};
49
50 dbgShape = Shape.Create(ShapeType.BBOX, color, ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE, m_start, m_end);
51
52 vector mat[4];
54 dbgShape.SetMatrix(mat);
55 }
56 override bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
57 {
58 // event when changing shape or position of the trigger in WB
59 bool m_showPreviewLocal;
60 src.Get("m_showPreview",m_showPreviewLocal);
61 if (m_showPreviewLocal)
62 {
63 SpawnPreview();
64 }
65 else
66 {
67 DespawnChildren();
68 }
69 return false;
70 }
71
72#endif
73
74
75
76 override private void EOnTouch(IEntity owner, IEntity other, int touchTypesMask)
77 {
78 PrintFormat("OnTouch triggered by entity %1 of type %2", other,touchTypesMask);
79
80 }
81
82 override private void EOnContact(IEntity owner, IEntity other, Contact contact)
83 {
84 PrintFormat("OnContact triggered by entity %1 of type %2", other, contact);
85 }
86
87 void SpawnPreview()
88 {
89 IEntity child = this.GetChildren();
90 vector camMatrix[4];
91
92#ifdef WORKBENCH
94 if (!child)
95 {
96 Print("No children of sector spawn found!");
97 }
98 while (child)
99 {
100 SCR_SectorPrefabSpawnPoint prefabSpawnPoint = SCR_SectorPrefabSpawnPoint.Cast(child);
101 vector mat[4];
102 prefabSpawnPoint.GetWorldTransform(mat);
103
104 if (prefabSpawnPoint.ShouldSnapToGround())
105 {
106 vector position = mat[3];
107 position[1] = prefabSpawnPoint.GetWorld().GetSurfaceY(position[0], position[2]);
108 mat[3] = position;
109 }
110 EntitySpawnParams spawnParams = new EntitySpawnParams;
111 spawnParams.TransformMode = ETransformMode.WORLD;
112 spawnParams.Transform = mat;
113 Resource resource = Resource.Load(prefabSpawnPoint.m_sLoadoutResource);
114
115 //IEntity entity = m_API.CreateEntity(prefab, "moje " + index, m_API.GetCurrentEntityLayerId(), m_API.EntityToSource(prefabSpawnPoint),vector.Zero, vector.Zero);
116
117 IEntity entity = GetGame().SpawnEntityPrefab(resource, m_API.GetWorld(), spawnParams);
118
119 if (!entity)
120 {
121 Print("Something is awfully wrong somewhere");
122 }
123 else
124 {
125 prefabSpawnPoint.AddChild(entity,0, EAddChildFlags.AUTO_TRANSFORM);
126 prefabSpawnPoint.GetWorldTransform(mat);
127 entity.SetWorldTransform(mat);
128 }
129 child = child.GetSibling();
130 }
131#else
132 Print("Running game mode");
133
134 //IEntity entity = GetGame().SpawnEntityPrefab(resource, null, spawnParams);
135#endif
136 }
137
138 void DespawnChildren()
139 {
140 IEntity spawnPoint = this.GetChildren();
141 while (spawnPoint)
142 {
143 IEntity ent = spawnPoint.GetChildren();
144 if (ent)
145 {
146 spawnPoint.RemoveChild(ent);
147 delete ent;
148 }
149 spawnPoint = spawnPoint.GetSibling();
150 }
151 }
152};
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SpawnPreview()
Create a preview if it does not exist.
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector position
event void _WB_AfterWorldUpdate(float timeSlice)
Called after updating world in Workbench. The entity must be visible in frustum, selected or named....
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
event bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
event int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
Called after _WB_OnInit or also later when editor needs to know whether _WB_AfterWorldUpdate needs to...
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external IEntity GetChildren()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external bool SetWorldTransform(vector mat[4])
See IEntity::SetTransform. Returns false, if there is no change in transformation.
proto external void RemoveChild(notnull IEntity child, bool keepTransform=false)
Remove Entity from hierarchy.
proto external IEntity GetSibling()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Instance of created debug visualizer.
Definition Shape.c:14
void EntitySpawnParams()
Definition gameLib.c:130
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ShapeType
Definition ShapeType.c:13
ShapeFlags
Definition ShapeFlags.c:13
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
EAddChildFlags
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
proto int ARGB(int a, int r, int g, int b)