Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
scriptedentities.c
Go to the documentation of this file.
1#ifdef DEVELOPER
2const bool DebugTrigger = false;
3#else
4const bool DebugTrigger = false;
5#endif
6
8{
9 ref OLinkT insider;
10 int timeStamp;
11 void TriggerInsider(Object obj)
12 {
13 insider = new OLinkT(obj);
14 }
15
16 Object GetObject()
17 {
18 return insider.Ptr();
19 }
20};
21
22class Trigger extends ScriptedEntity
23{
24 const int TIMEOUT = 1000;
25 ref array<ref TriggerInsider> m_insiders;
26 Shape shape;
27
28 protected void Cleanup()
29 {
30 if(shape)
31 {
32 shape.Destroy();
33 shape = NULL;
34 }
35 }
36
37 void OnEnter(Object obj)
38 {
39 if(DebugTrigger)
40 {
41 Print("entered");
42 Print(obj);
43 }
44 }
45
46 void OnLeave(Object obj)
47 {
48 if(DebugTrigger)
49 {
50 Print("left");
51 Print(obj);
52 }
53 }
54
55 protected void UpdateInsiders(int timeout)
56 {
57 int timeStamp = g_Game.GetTime();
58
59 for(int n = 0; n < m_insiders.Count(); )
60 {
61 TriggerInsider ins = m_insiders.Get(n);
62 if(ins.insider == NULL)
63 {
64 //object has been deleted. Remove it
65 m_insiders.Remove(n);
66 continue;
67 }
68
69 int timeDiff = timeStamp - ins.timeStamp;
70 if(timeDiff > timeout)
71 {
72 //object left. Remove it
73 OnLeave(ins.insider.Ptr());
74 m_insiders.Remove(n);
75 continue;
76 }
77
78 n++;
79 }
80 }
81
82 protected void AddInsider(Object obj)
83 {
85 for(int n = 0; n < m_insiders.Count(); n++)
86 {
87 ins = m_insiders.Get(n);
88 //already in?
89 if(ins.insider.Ptr() == obj)
90 {
91 //just update timestamp
92 ins.timeStamp = g_Game.GetTime();
93 return;
94 }
95 }
96 ins = new TriggerInsider(obj);
97 ins.timeStamp = g_Game.GetTime();
98 m_insiders.Insert(ins);
99 OnEnter(obj);
100 }
101
102 override void EOnFrame(IEntity other, float timeSlice)
103 {
105 }
106
107 override void EOnTouch(IEntity other, int extra)
108 {
109 Object obj;
110 if (Class.CastTo(obj, other))
111 AddInsider(obj);
112 }
113
114 float GetRadius(vector min, vector max)
115 {
116 vector v;
117 for(int n = 0; n < 3; n++)
118 {
119 float m1 = Math.AbsFloat(min[n]);
120 float m2 = Math.AbsFloat(max[n]);
121
122 if(m1 > m2)
123 v[n] = m1;
124 else
125 v[n] = m2;
126 }
127
128 return v.Length();
129 }
130
131 void SetExtents(vector mins, vector maxs)
132 {
133 SetCollisionBox(mins, maxs);
134
135 if(DebugTrigger)
136 {
137 vector mat[4];
138 GetTransform(mat);
139 if(shape)
140 {
141 shape.Destroy();
142 shape = NULL;
143 }
144
145 shape = Shape.Create(ShapeType.BBOX, 0x1fff7f7f, ShapeFlags.TRANSP|ShapeFlags.NOZWRITE, mins, maxs);
146
147 if (shape) // Hackfix! Function AddDShape must return Shape! That's why this condition is probably never passed!
148 {
149 shape.SetMatrix(mat);
150 }
151 }
152 }
153
154
155 override void EOnInit(IEntity other, int extra)
156 {
157 const vector mins = "-2 -4 -2";
158 const vector maxs = "2 4 2";
159 SetExtents(mins, maxs);
160 }
161
162 override void EEDelete(EntityAI parent)
163 {
164 super.EEDelete(parent);
165
166 Cleanup();
167 }
168
169 private void Trigger()
170 {
171 m_insiders = new array<ref TriggerInsider>;
172 SetEventMask(EntityEvent.FRAME|EntityEvent.INIT|EntityEvent.TOUCH);
173 SetFlags(EntityFlags.TRIGGER, false);
174 }
175};
176
177class ManTrigger extends Trigger
178{
179 override void OnEnter(Object obj)
180 {
181 }
182
183 override void EOnTouch(IEntity other, int extra)
184 {
185 Object obj;
186 if(Class.CastTo(obj, other))
187 {
188 if(obj.IsMan()) AddInsider(obj);
189 }
190 }
191
192 array<ref TriggerInsider> GetInsiders()
193 {
194 return m_insiders;
195 }
196
197 override void EOnInit(IEntity other, int extra)
198 {
199 const vector mins = "-2 -2 -2";
200 const vector maxs = "2 2 2";
201 SetExtents(mins, maxs);
202 }
203
204};
void SetExtents(vector mins, vector maxs)
Super root of all classes in Enforce script.
Definition enscript.c:11
Trigger only accepting Object which IsMan()
Definition mantrigger.c:3
Definition enmath.c:7
override void EEDelete(EntityAI parent)
void AddInsider(Object obj)
void OnLeave(Object obj)
float GetRadius(vector min, vector max)
void SetExtents(vector mins, vector maxs)
override void EOnFrame(IEntity other, float timeSlice)
void UpdateInsiders(int timeout)
override void EOnInit(IEntity other, int extra)
override void EOnTouch(IEntity other, int extra)
void OnEnter(Object obj)
Scripted Trigger.
override void OnLeave(Object obj)
Definition hologram.c:1586
void UpdateInsiders(int timeout)
Definition hologram.c:1595
void AddInsider(Object obj)
Adding of new TriggerInsider.
Definition trigger.c:228
The object which is in a trigger and its metadata.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
@ TIMEOUT
DayZGame g_Game
Definition dayzgame.c:3868
override void EOnTouch(IEntity other, int extra)
Definition easteregg.c:106
Link< Object > OLinkT
Definition gameplay.c:1516
proto void Print(void var)
Prints content of variable to console/log.
ShapeType
Definition endebug.c:116
proto native void SetFlags(ShapeFlags flags)
ShapeFlags
Definition endebug.c:126
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition enentity.c:45
EntityFlags
Entity flags.
Definition enentity.c:115
const bool DebugTrigger
proto native void SetCollisionBox(vector mins, vector maxs)
Sets collision box for object.