DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
BarbedWire.c
Go to the documentation of this file.
1class BarbedWire extends ItemBase
2{
3 // Sounds lists
4 const static int SOUNDS_SPARK_COUNT = 4;
5 const static int SOUNDS_CUT_COUNT = 3;
6 const static int SOUNDS_COLLISION_COUNT = 4;
7 const static int SOUNDS_SHOCK_COUNT = 4;
8 const static float RANDOM_SPARK_INTERVAL = 5.0; // TO DO! Currently not used.
9
10 const static string m_SoundsSpark[SOUNDS_SPARK_COUNT] = {"electricFenceSpark1", "electricFenceSpark2", "electricFenceSpark3", "electricFenceSpark4"};
11 const static string m_SoundsCut[SOUNDS_CUT_COUNT] = {"barbedFenceCut1", "barbedFenceCut2", "barbedFenceCut3"};
12 const static string m_SoundsCollision[SOUNDS_COLLISION_COUNT] = {"barbedFenceCollision1", "barbedFenceCollision2", "barbedFenceCollision3", "barbedFenceCollision4"};
13 const static string m_SoundsShock[SOUNDS_SHOCK_COUNT] = {"electricFenceShock1", "electricFenceShock2", "electricFenceShock3", "electricFenceShock4"};
14 const static string m_SoundBuzzLoop = "electricFenceBuzzLoop1";
16
17 SoundOnVehicle m_BuzzSoundLoop;
18
21
22 protected bool m_TriggerActive;
23 protected bool m_IsPlaced;
24
25 //mounting
26 protected bool m_IsMounted;
27 protected bool m_LastMountedState;
28 const string SOUND_MOUNT = "putDown_BarbedWire_SoundSet";
30
31
33 {
34 m_SparkEvent = new Timer( CALL_CATEGORY_SYSTEM );
35 m_TriggerActive = false;
36 m_IsPlaced = false;
37
38 //synchronized variables
39 RegisterNetSyncVariableBool( "m_IsSoundSynchRemote" );
40 RegisterNetSyncVariableBool( "m_IsDeploySound" );
41 RegisterNetSyncVariableBool( "m_IsMounted" );
42 }
43
45 {
47 }
48
49 override void EEInit()
50 {
51 super.EEInit();
52
53 GetGame().GetCallQueue( CALL_CATEGORY_GAMEPLAY ).CallLater( UpdateAttachmentSlot, 100, false );
54 }
55
56 bool IsMounted()
57 {
58 return GetSlotLockedState();
59 }
60
61 protected bool GetSlotLockedState()
62 {
63 BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
64 if ( base_building )
65 {
66 InventoryLocation inventory_location = new InventoryLocation;
67 GetInventory().GetCurrentInventoryLocation( inventory_location );
68 return base_building.GetInventory().GetSlotLock( inventory_location.GetSlot() );
69 }
70
71 return false;
72 }
73
74 void SetMountedState( bool is_mounted )
75 {
76 bsbDebugPrint("[bsb] " + GetDebugName(this) + " SetMountedState mounted=" + is_mounted);
77
78 //lock slot
79 m_IsMounted = is_mounted;
80 LockAttachmentSlot( is_mounted );
81 SetTakeable( !is_mounted );
82
83 //synchronize
85 }
86
87 protected void UpdateAttachmentSlot()
88 {
89 BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
90 if ( base_building )
91 {
92 InventoryLocation inventory_location = new InventoryLocation;
93 GetInventory().GetCurrentInventoryLocation( inventory_location );
94 bool is_mounted = base_building.GetInventory().GetSlotLock( inventory_location.GetSlot() );
95 string slot_name = InventorySlots.GetSlotName( inventory_location.GetSlot() );
96
97 base_building.UpdateAttachmentVisuals( slot_name, is_mounted );
98 base_building.UpdateAttachmentPhysics( slot_name, is_mounted );
99 }
100 }
101
102 protected void LockAttachmentSlot( bool lock_state )
103 {
104 BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
105 if ( base_building )
106 {
107 InventoryLocation inventory_location = new InventoryLocation;
108 GetInventory().GetCurrentInventoryLocation( inventory_location );
109 base_building.GetInventory().SetSlotLock( inventory_location.GetSlot(), lock_state );
110 //string slot_name = InventorySlots.GetSlotName( inventory_location.GetSlot() );
111 //base_building.UpdateAttachmentVisuals( slot_name, lock_state );
112 //base_building.UpdateAttachmentPhysics( slot_name, lock_state );
113 }
114 }
115
116 // --- SYNCHRONIZATION
118 {
119 if ( GetGame().IsServer() )
120 {
121 SetSynchDirty();
122 }
123 }
124
126 {
127 super.OnVariablesSynchronized();
128
129 if ( ( m_IsMounted && !m_LastMountedState ) || ( !m_IsMounted && m_LastMountedState ) )
130 {
131 //Play sound
132 PlaySoundSet( m_MountSound, SOUND_MOUNT, 0.1, 0.1 );
133 }
134 m_LastMountedState = m_IsMounted;
135
136 if ( IsDeploySound() )
137 {
139 }
140
142 {
144 }
145
147 {
149 }
150 }
151
153 {
154 if ( !GetGame().IsDedicatedServer() )
155 {
157 {
159 }
160 }
161 }
162
164 {
165 if ( !GetGame().IsDedicatedServer() )
166 {
169 }
170 }
171
172 // --- EVENTS
173 override void OnStoreSave( ParamsWriteContext ctx )
174 {
175 super.OnStoreSave( ctx );
176 }
177
178 override bool OnStoreLoad( ParamsReadContext ctx, int version )
179 {
180 if ( !super.OnStoreLoad( ctx, version ) )
181 return false;
182
183 //--- Barbed wire data ---
184 //is mounted (removed in ver. 105)
185 if ( version < 105 )
186 {
187 float is_mounted;
188 if ( !ctx.Read( is_mounted ) )
189 {
190 return false;
191 }
192 }
193 //---
194
195 return true;
196 }
197
198 override void AfterStoreLoad()
199 {
200 super.AfterStoreLoad();
201
202 //set mounted state based on locked slot after everything is loaded
204 }
205
206 // ---
207 override void OnWorkStart()
208 {
210 if (m_TriggerActive)
212
213 if (m_IsPlaced)
214 {
215 //TimerRandomSpark();
217 }
218 }
219
220 override void OnWorkStop()
221 {
223 if (m_TriggerActive)
225
226 if (m_IsPlaced)
228
229 m_SparkEvent.Stop();
230 }
231
232 override void OnWork( float consumed_energy ) {}
233
234 override void OnIsPlugged(EntityAI source_device)
235 {
236 SoundCut();
237 }
238
239 override void OnIsUnplugged( EntityAI last_energy_source )
240 {
241 if (m_TriggerActive)
243 SoundCut();
244 }
245
246 override void OnInventoryEnter(Man player)
247 {
248 super.OnInventoryEnter(player);
249 HideSelection("placing");
250 ShowSelection("zbytek");
251 if (m_TriggerActive)
253 GetCompEM().UnplugThis();
254 GetCompEM().UnplugAllDevices();
255 }
256
257 // Area Damage triggers
258 // ---------------------------------------------------------
260 {
262 m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
263 m_AreaDamage.SetLoopInterval(0.3);
264 m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
265 m_AreaDamage.SetAmmoName("BarbedWireHit");
266 m_AreaDamage.Spawn();
267 m_TriggerActive = true;
268 }
269
270 protected void CreateDamageTrigger()
271 {
272 m_AreaDamage = new AreaDamageOneTime(this);
273 m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
274 m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
275 m_AreaDamage.SetAmmoName("BarbedWireHit");
276 m_AreaDamage.Spawn();
277 m_TriggerActive = true;
278 }
279
280 protected void DestroyDamageTrigger()
281 {
282 m_AreaDamage.Destroy();
283 m_TriggerActive = false;
284 }
285 // ---------------------------------------------------------
286
287 // Controls spawn of random sparks
288 /*
289 protected void TimerRandomSpark() // TO DO: Come up with randomized functionality.
290 {
291 if ( GetCompEM().IsSwitchedOn() )
292 {
293 int plugged_devices = GetCompEM().GetEnergySource().GetCompEM().GetPluggedDevicesCount();
294 float rnd_time = Math.RandomFloat(0.3, RANDOM_SPARK_INTERVAL / plugged_devices + 1.0);
295 m_SparkEvent.Run(rnd_time + 0.3, this, "Spark", NULL, true);
296 }
297 }
298 */
299
300 // Spawns spark particle effect and plays sound.
301 void Spark()
302 {
303 ParticleManager.GetInstance().PlayOnObject( ParticleList.BARBED_WIRE_SPARKS, this);
304 SoundSpark();
305 }
306
307
308 // SOUNDS
309 // ---------------------------------------------------------
310 void SoundCut()
311 {
312 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
313 {
314 int random_index = Math.RandomInt(0, SOUNDS_CUT_COUNT);
315 string sound_type = m_SoundsCut[random_index];
316 PlaySound(sound_type, 50);
317 }
318 }
319
320 // Plays sound
322 {
323 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
324 {
325 int random_index = Math.RandomInt(0, SOUNDS_SPARK_COUNT);
326 string sound_type = m_SoundsSpark[random_index];
327 PlaySound(sound_type, 50);
328 }
329 }
330
331 // Plays sound
333 {
334 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
335 {
336 if (!m_BuzzSoundLoop)
337 {
338 m_BuzzSoundLoop = PlaySoundLoop(m_SoundBuzzLoop, 50);
339 }
340 }
341 }
342
343 // Stops sound
345 {
346 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
347 {
348 if (m_BuzzSoundLoop)
349 {
350 GetGame().ObjectDelete(m_BuzzSoundLoop);
351 m_BuzzSoundLoop = NULL;
352 }
353 }
354 }
355
356 // Plays an electric shock sound
358 {
359 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
360 {
361 int random_index = Math.RandomInt(0, SOUNDS_SHOCK_COUNT);
362 string sound_type = m_SoundsShock[random_index];
363 PlaySound(sound_type, 50);
364 }
365 }
366
367 // Plays a collision sound
369 {
370 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
371 {
372 int random_index = Math.RandomInt(0, SOUNDS_COLLISION_COUNT);
373 string sound_type = m_SoundsCollision[random_index];
374 PlaySound(sound_type, 50);
375 }
376 }
377 // ---------------------------------------------------------
378
379 // Area Damage Pre/Post actions
380 // ---------------------------------------------------------
381 override void PreAreaDamageActions()
382 {
383 if ( GetCompEM().IsPlugged() && GetCompEM().IsSwitchedOn() )
384 {
385 Spark();
387 }
389 }
390
391 override void PostAreaDamageActions()
392 {
393 //dmg to barbed wire here
394 MiscGameplayFunctions.DealAbsoluteDmg(this, 1000);
395 }
396 // ---------------------------------------------------------
397
398
399 // TODO: proper handling can be done once the ticket DAYZ-26145 is resolved
400 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
401 {
402 super.OnItemLocationChanged(old_owner, new_owner);
403
404 if (m_TriggerActive)
405 {
407 m_IsPlaced = false;
408 }
409 }
410
411 //================================================================
412 // ADVANCED PLACEMENT
413 //================================================================
414
415 override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
416 {
417 super.OnPlacementComplete( player, position, orientation );
418
419 if ( GetGame().IsServer() )
420 {
421 ShowAllSelections();
422 HideSelection("zbytek");
423
424 if (!GetHierarchyParent())
425 {
426 if (GetCompEM().IsPlugged() && GetCompEM().IsWorking() )
428 else
430 m_IsPlaced = true;
431 }
432
433 SetIsDeploySound( true );
434 }
435 }
436
437 override string GetDeploySoundset()
438 {
439 return "placeBarbedWire_SoundSet";
440 }
441
442 override string GetLoopDeploySoundset()
443 {
444 return "barbedwire_deploy_SoundSet";
445 }
446
447 override void SetActions()
448 {
449 super.SetActions();
450
453 }
454}
void AddAction(typename actionName)
void AreaDamageManager(EntityAI parent)
class BaseBuildingBase extends ItemBase bsbDebugPrint(string s)
protected ref AreaDamageManager m_AreaDamage
void PlaySound()
void PlayDeploySound()
Definition ItemBase.c:8920
override void SetTakeable(bool pState)
Definition ItemBase.c:8843
void SetIsDeploySound(bool is_deploy_sound)
Definition ItemBase.c:8910
bool IsDeploySound()
Definition ItemBase.c:8915
bool CanPlayDeployLoopSound()
Definition ItemBase.c:8947
override string GetDebugName()
Gets the debug name for the ParticleManager.
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
protected ref EffectSound m_DeployLoopSound
Definition TrapBase.c:47
class JsonUndergroundAreaTriggerData GetPosition
proto native void ObjectDelete(Object obj)
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
void SoundStop()
Stops sound.
InventoryLocation.
proto native int GetSlot()
returns slot id if current type is Attachment
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
protected void UpdateAttachmentSlot()
Definition BarbedWire.c:87
protected bool m_TriggerActive
Definition BarbedWire.c:22
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition BarbedWire.c:400
override string GetDeploySoundset()
Definition BarbedWire.c:437
void SetMountedState(bool is_mounted)
Definition BarbedWire.c:74
protected bool GetSlotLockedState()
Definition BarbedWire.c:61
SoundOnVehicle m_BuzzSoundLoop
Definition BarbedWire.c:17
bool IsMounted()
Definition BarbedWire.c:56
override void OnStoreSave(ParamsWriteContext ctx)
Definition BarbedWire.c:173
protected bool m_LastMountedState
Definition BarbedWire.c:27
void SoundCollision()
Definition BarbedWire.c:368
override string GetLoopDeploySoundset()
Definition BarbedWire.c:442
protected ref AreaDamageManager m_AreaDamage
Definition BarbedWire.c:20
override void PostAreaDamageActions()
Definition BarbedWire.c:391
override void OnIsUnplugged(EntityAI last_energy_source)
Definition BarbedWire.c:239
void PlayDeployLoopSound()
Definition BarbedWire.c:152
void StopDeployLoopSound()
Definition BarbedWire.c:163
override void EEInit()
Definition BarbedWire.c:49
override void OnIsPlugged(EntityAI source_device)
Definition BarbedWire.c:234
override void OnWorkStop()
Definition BarbedWire.c:220
static const int SOUNDS_SHOCK_COUNT
Definition BarbedWire.c:7
override void PreAreaDamageActions()
Definition BarbedWire.c:381
void SoundCut()
Definition BarbedWire.c:310
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition BarbedWire.c:415
static const int SOUNDS_SPARK_COUNT
Definition BarbedWire.c:4
protected EffectSound m_MountSound
Definition BarbedWire.c:29
void SoundBuzzLoopStop()
Definition BarbedWire.c:344
override void OnWork(float consumed_energy)
Definition BarbedWire.c:232
void ~BarbedWire()
Definition BarbedWire.c:44
static const int SOUNDS_CUT_COUNT
Definition BarbedWire.c:5
void SoundSpark()
Definition BarbedWire.c:321
override void AfterStoreLoad()
Definition BarbedWire.c:198
void Synchronize()
Definition BarbedWire.c:117
void BarbedWire()
Definition BarbedWire.c:32
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition BarbedWire.c:178
ref Timer m_SparkEvent
Definition BarbedWire.c:19
protected bool m_IsPlaced
Definition BarbedWire.c:23
override void OnWorkStart()
Definition BarbedWire.c:207
ref protected EffectSound m_DeployLoopSound
Definition BarbedWire.c:15
protected void CreateElectrifiedDamageTrigger()
Definition BarbedWire.c:259
override void OnInventoryEnter(Man player)
Definition BarbedWire.c:246
override void OnVariablesSynchronized()
Definition BarbedWire.c:125
void SoundBuzzLoopStart()
Definition BarbedWire.c:332
protected bool m_IsMounted
Definition BarbedWire.c:26
protected void CreateDamageTrigger()
Definition BarbedWire.c:270
void Spark()
Definition BarbedWire.c:301
protected void LockAttachmentSlot(bool lock_state)
Definition BarbedWire.c:102
protected void DestroyDamageTrigger()
Definition BarbedWire.c:280
void SoundElectricShock()
Definition BarbedWire.c:357
override void SetActions()
Definition BarbedWire.c:447
static const int SOUNDS_COLLISION_COUNT
Definition BarbedWire.c:6
Definition EnMath.c:7
static const int BARBED_WIRE_SPARKS
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
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 Read(void value_in)
proto native CGame GetGame()
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8