DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Grenade_Base.c
Go to the documentation of this file.
2{
8
10class GrenadeLight : ExplosiveLight {}
11
13{
14 protected static float m_DefaultBrightness = 50;
15 protected static float m_DefaultRadius = 20;
16
18 {
19 SetVisibleDuringDaylight(true);
20 SetRadiusTo(m_DefaultRadius);
21 SetBrightnessTo(m_DefaultBrightness);
22 SetFlareVisible(false);
23 SetAmbientColor(1.0, 1.0, 1.0);
24 SetDiffuseColor(1.0, 1.0, 1.0);
25 SetLifetime(0.35);
26 SetDisableShadowsWithinRadius(-1);
27 }
28}
29
31{
32 protected const float DEFAULT_FUSE_DELAY = 10;
33
34 protected ref Timer m_FuseTimer;
35 protected float m_FuseDelay;
36 protected float m_RemainingFuseTime;
37
38 protected bool m_Pinned;
39 protected bool m_Pinnable;
40 //protected bool m_Explodable; //! DEPRECATED; not used anywhere
41
43
44 void Pin()
45 {
46 if (!m_Pinned && m_Pinnable)
47 {
48 OnPin();
49 }
50 }
51
52 void Unpin()
53 {
54 if (m_Pinned)
55 {
56 OnUnpin();
57 }
58 }
59
61 override void OnActivatedByTripWire();
62
63 override void OnActivatedByItem(notnull ItemBase item)
64 {
65 if (item == this)
66 {
68 return;
69 }
70
71 Unpin();
72 }
73
74 bool IsPinned()
75 {
76 return m_Pinned;
77 }
78
80 {
82 if (m_FuseTimer.IsRunning())
83 {
84 return false;
85 }
86
87 return m_Pinnable;
88 }
89
91 {
93 }
94
96 {
97 float delay = Math.RandomFloat(1, 20);
98 delay *= 1000;
100 }
101
102 void SetPinnable(bool state)
103 {
104 m_Pinnable = state;
105 }
106
107 void SetFuseDelay(float delay)
108 {
109 m_FuseDelay = delay;
110 }
111
113 {
114 m_GrenadeType = type;
115 }
116
118 {
119 return m_GrenadeType;
120 }
121
122 protected void Activate()
123 {
124 if (!m_FuseTimer.IsRunning())
125 {
127 if (m_RemainingFuseTime > 0)
128 {
129 //Debug.Log(string.Format("Grenade activated num of seconds to explosion: %1", m_RemainingFuseTime));
130 m_FuseTimer.Run(m_RemainingFuseTime, this, "OnActivateFinished");
131 }
132 else
133 {
134 //Debug.Log(string.Format("Grenade activated num of seconds to explosion: %1", m_FuseDelay));
135 m_FuseTimer.Run(m_FuseDelay, this, "OnActivateFinished");
136 }
137
138 }
139 }
140
141 protected void Deactivate()
142 {
143 if (m_FuseTimer.IsRunning())
144 {
145 m_RemainingFuseTime = m_FuseTimer.GetRemaining();
147 OnDeactivate();
148 }
149 }
150
151 protected override void InitiateExplosion()
152 {
153 switch (GetGrenadeType())
154 {
155 case EGrenadeType.FRAGMENTATION:
156 case EGrenadeType.ILLUMINATING:
157 for (int i = 0; i < m_AmmoTypes.Count(); i++)
158 {
159 Explode(DamageType.EXPLOSION, m_AmmoTypes[i]);
160 }
161 break;
162 case EGrenadeType.CHEMICAL:
163 case EGrenadeType.NON_LETHAL:
164 break;
165 }
166
167 OnExplode();
168 }
169
171 protected void ExplodeGrenade(EGrenadeType grenade_type)
172 {
174 }
175
176 protected void OnPin()
177 {
178 m_Pinned = true;
179 if (GetGame().IsServer())
180 {
181 ForceFarBubble(false);
182 SetSynchDirty();
183 }
184
185 Deactivate();
186 }
187
188 protected void OnUnpin()
189 {
190 m_Pinned = false;
191 if (GetGame().IsServer())
192 {
193 ForceFarBubble(true);
194 SetSynchDirty();
195 }
196
198 }
199
200 protected void OnActivateStarted();
201 protected void OnActivateFinished()
202 {
203 if (GetGame().IsServer())
204 {
205 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
206 SetTakeable(false);
207 }
208 }
209
210 protected void OnActivateImmediate()
211 {
212 if (GetGame().IsServer())
213 {
214 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
215 SetTakeable(false);
216 }
217 }
218
219 protected void OnDeactivate();
220
222 {
223 super.OnStoreSave(ctx);
224
225 if (GetGame().SaveVersion() >= 107)
226 {
227 ctx.Write(m_Pinned);
228 }
229 }
230
231 override bool OnStoreLoad(ParamsReadContext ctx, int version)
232 {
233 if (!super.OnStoreLoad(ctx, version))
234 return false;
235
236 bool pinned;
237 if (version >= 107)
238 {
239 if (!ctx.Read(pinned))
240 {
241 return false;
242 }
243
244 m_Pinned = pinned;
245 }
246
247 return true;
248 }
249
250 override bool CanBeArmed()
251 {
252 return false;
253 }
254
255 override bool CanBeDisarmed()
256 {
257 return false;
258 }
259
260 override bool CanExplodeInFire()
261 {
262 return true;
263 }
264
265 override void SetActions()
266 {
267 super.SetActions();
268
269 AddAction(ActionUnpin);
270 AddAction(ActionPin);
271 }
272
273 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
274 {
275 super.EEItemLocationChanged(oldLoc, newLoc);
276
278 if (newLoc.GetType() != InventoryLocationType.HANDS && !IsPinned())
279 {
280 Activate();
281 }
282 }
283
284 override void OnWasAttached(EntityAI parent, int slot_id)
285 {
286 super.OnWasAttached(parent, slot_id);
287
288 if (parent.IsAnyInherited({TrapBase,ImprovisedExplosive}))
289 {
290 Deactivate();
291 }
292 }
293
295 {
296 m_Pinned = true;
297 m_FuseTimer = new Timer;
299
300 SetPinnable(true);
302 SetGrenadeType(EGrenadeType.FRAGMENTATION);
303
304 RegisterNetSyncVariableBool("m_Pinned");
305 }
306}
void AddAction(typename actionName)
enum eAreaDecayStage m_DefaultBrightness
protected float m_DefaultRadius
DamageType
exposed from C++ (do not change)
protected void OnExplode()
void ExplosivesBase()
protected ref array< string > m_AmmoTypes
void FlashGrenadeLight()
EGrenadeType
Definition Grenade_Base.c:2
@ CHEMICAL
Definition Grenade_Base.c:4
@ FRAGMENTATION
Definition Grenade_Base.c:3
@ NON_LETHAL
Definition Grenade_Base.c:6
@ ILLUMINATING
Definition Grenade_Base.c:5
InventoryLocationType
types of Inventory Location
override void SetTakeable(bool pState)
Definition ItemBase.c:8843
override void Explode(int damageType, string ammoType="")
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
protected float m_RemainingFuseTime
void SetGrenadeType(EGrenadeType type)
override void OnStoreSave(ParamsWriteContext ctx)
override bool CanBeDisarmed()
protected ref Timer m_FuseTimer
void ActivateRandomTime()
void SetFuseDelay(float delay)
void Grenade_Base()
void SetPinnable(bool state)
override bool CanExplodeInFire()
protected override void InitiateExplosion()
protected void Deactivate()
protected void OnDeactivate()
protected void OnPin()
override void OnActivatedByTripWire()
DEPRECATED use OnActivatedByItem.
protected float m_FuseDelay
bool IsPinnable()
protected void Activate()
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
protected void OnActivateStarted()
override bool OnStoreLoad(ParamsReadContext ctx, int version)
protected const float DEFAULT_FUSE_DELAY
override void OnActivatedByItem(notnull ItemBase item)
protected void OnActivateImmediate()
override void OnWasAttached(EntityAI parent, int slot_id)
protected void OnActivateFinished()
protected bool m_Pinned
bool IsPinned()
protected bool m_Pinnable
protected void ExplodeGrenade(EGrenadeType grenade_type)
DEPRECATED - for backward compatibility only.
override bool CanBeArmed()
protected EGrenadeType m_GrenadeType
EGrenadeType GetGrenadeType()
void ActivateImmediate()
protected void OnUnpin()
override void SetActions()
InventoryLocation.
Definition EnMath.c:7
proto void CallLater(func fn, int delay=0, bool repeat=false, 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)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
override void Stop()
proto native CGame GetGame()
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10