DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Barrel_ColorBase.c
Go to the documentation of this file.
2{
3 private bool m_IsLocked = false;
4 private ref Timer m_BarrelOpener;
5
8
10 {
11 m_BarrelOpener = new Timer();
12
13 m_Openable = new OpenableBehaviour(false);
14 m_RainProcurement = new RainProcurementManager(this); //legacy reasons
16
17 m_HalfExtents = Vector(0.30,0.85,0.30);
18
19 RegisterNetSyncVariableBool("m_Openable.m_IsOpened");
20 RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
21 RegisterNetSyncVariableBool("m_IsPlaceSound");
22 }
23
25 {
26 return 110;
27 }
28
29 override void OnStoreSave( ParamsWriteContext ctx )
30 {
31 super.OnStoreSave( ctx );
32
33 ctx.Write( m_Openable.IsOpened() );
34 }
35
36 override bool OnStoreLoad( ParamsReadContext ctx, int version )
37 {
38 if ( !super.OnStoreLoad( ctx, version ) )
39 return false;
40
41 bool opened;
42 if ( version >= 110 && !ctx.Read( opened ) )
43 {
44 return false;
45 }
46
47 if ( opened )
48 {
49 OpenLoad();
50 }
51 else
52 {
53 CloseLoad();
54 }
55
56 return true;
57 }
58
59 bool IsLocked()
60 {
61 return m_IsLocked;
62 }
63
64 override void Open()
65 {
69 SetTakeable(false);
70
72 }
73
74 void OpenLoad()
75 {
78 SetSynchDirty();
79 SetTakeable(false);
80
82 }
83
84 override void Close()
85 {
89 SetTakeable(true);
90
92 }
93
94 void CloseLoad()
95 {
98 SetSynchDirty();
99 SetTakeable(true);
100
102 }
103
104 override bool IsOpen()
105 {
106 return m_Openable.IsOpened();
107 }
108
109 override void OnWasAttached( EntityAI parent, int slot_id)
110 {
111 super.OnWasAttached(parent, slot_id);
112
113 Open();
114 }
115
116 override void OnWasDetached(EntityAI parent, int slot_id)
117 {
118 super.OnWasDetached(parent, slot_id);
119
120 Close();
121 }
122
123 protected void UpdateVisualState()
124 {
125 if ( IsOpen() )
126 {
127 SetAnimationPhase("Lid",1);
128 SetAnimationPhase("Lid2",0);
129 }
130 else
131 {
132 SetAnimationPhase("Lid",0);
133 SetAnimationPhase("Lid2",1);
134 }
135 }
136
138 {
139 super.OnVariablesSynchronized();
140
141 if ( IsPlaceSound() )
142 {
144 }
145 else if ( IsSoundSynchRemote() && !IsBeingPlaced() && m_Initialized )
146 {
147 if ( IsOpen() )
148 {
150 }
151 else if ( !IsOpen() )
152 {
154 }
155 }
157 }
158
160 {
161 EffectSound sound = SEffectManager.PlaySound( "barrel_open_SoundSet", GetPosition() );
162 sound.SetAutodestroy( true );
163 }
164
166 {
167 EffectSound sound = SEffectManager.PlaySound( "barrel_close_SoundSet", GetPosition() );
168 sound.SetAutodestroy( true );
169 }
170
171 void Lock(float actiontime)
172 {
173 m_IsLocked = true;
174 m_BarrelOpener.Run(actiontime, this, "Unlock", NULL,false);
175 }
176
177 void Unlock()
178 {
179 m_IsLocked = false;
180 Open();
181 }
182
184 {
185 int slot_id;
186 ItemBase ingredient;
187 slot_id = InventorySlots.GetSlotIdFromString("Lime");
188 ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
189 if ( ingredient && GetQuantity() > 10000 )
190 {
191 TanPelts(ingredient, player);
192 }
193 else
194 {
195 slot_id = InventorySlots.GetSlotIdFromString("Material_Nails");
196 ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
197 if ( ingredient && GetQuantity() > 10000 )
198 {
199 ColourLeatherClothes(ingredient, player, "Black");
200 }
201 else
202 {
203 slot_id = InventorySlots.GetSlotIdFromString("BirchBark");
204 ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
205 if ( ingredient && GetQuantity() > 10000 )
206 {
207 ColourLeatherClothes(ingredient, player, "Beige");
208 }
209 else
210 {
211 slot_id = InventorySlots.GetSlotIdFromString("OakBark");
212 ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
213 if ( ingredient && GetQuantity() > 10000 )
214 {
215 ColourLeatherClothes(ingredient, player, "Brown");
216 }
217 else
218 {
219
220 slot_id = InventorySlots.GetSlotIdFromString("Disinfectant");
221 ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
222 if ( ingredient && GetQuantity() > 10000 )
223 {
224 BleachClothes(ingredient, player);
225 }
226 else
227 {
228 slot_id = InventorySlots.GetSlotIdFromString("Plant");
229 ingredient = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
230 slot_id = InventorySlots.GetSlotIdFromString("Guts");
231 ItemBase reactant = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
232 if ( ingredient && reactant && GetQuantity() > 5000 )
233 {
234 ProduceFertilizer(ingredient,reactant,player);
235 }
236 else
237 {
238 slot_id = InventorySlots.GetSlotIdFromString("BerryR");
239 ItemBase ingredientR = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
240 slot_id = InventorySlots.GetSlotIdFromString("Plant");
241 ItemBase ingredientG = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
242 slot_id = InventorySlots.GetSlotIdFromString("BerryB");
243 ItemBase ingredientB = ItemBase.Cast( GetInventory().FindAttachment(slot_id) );
244 if ( (ingredientR || ingredientG || ingredientB) && GetQuantity() > 10000)
245 {
246 ColourClothes(ingredientR,ingredientG,ingredientB,player);
247 }
248 }
249 }
250 }
251 }
252 }
253 }
254 Close();
255 }
256
257 void ProduceFertilizer( ItemBase guts, ItemBase plant, PlayerBase player )
258 {
259 float lime_quantity = plant.GetQuantity()*GameConstants.BAREL_LIME_PER_PLANT;
260
261 guts.Delete();
262 plant.Delete();
263
264 ItemBase lime = ItemBase.Cast( GetInventory().CreateInInventory("GardenLime") );
265
266 lime.SetQuantity(lime_quantity);
267 Lock(50);
268 }
269
270 void TanPelts( ItemBase lime, PlayerBase player )
271 {
272 EntityAI item;
273 int item_count = GetInventory().GetCargo().GetItemCount();
274 int pelt_count = 0;
275 int lime_amount = Math.Floor(lime.GetQuantity()/GameConstants.BAREL_LIME_PER_PELT);
276
277
278 for (int i = 0; i < item_count; i++)
279 {
280 item = GetInventory().GetCargo().GetItem(i);
281 if ( item.IsPeltBase() )
282 {
283 pelt_count = g_Game.ConfigGetInt("cfgVehicles " + item.GetType() + " peltGain");
284 if ( pelt_count <= lime_amount )
285 {
286 TanLeatherLambda lambda = new TanLeatherLambda(item, "TannedLeather", player, pelt_count);
287 lambda.SetTransferParams(true, true, true);
288 player.ServerReplaceItemWithNew(lambda);
289
290 lime_amount -= pelt_count;
291 if ( lime_amount <= 0 )
292 {
293 lime.Delete();
294 break;
295 }
296 }
297 }
298 }
299 if ( lime )
300 {
301 lime.SetQuantity(lime_amount*GameConstants.BAREL_LIME_PER_PELT);
302 }
303 if ( pelt_count > 0 )
304 {
305 Lock(30);
306 }
307 }
308
309 void ColourLeatherClothes( ItemBase color_source, PlayerBase player, string color )
310 {
311 EntityAI item;
312 int item_count = GetInventory().GetCargo().GetItemCount();
313 string item_name = "";
314
315
316 for (int i = 0; i < item_count; i++)
317 {
318 item = GetInventory().GetCargo().GetItem(i);
319 if ( item.IsClothing() )
320 {
321 if ( GetGame().ObjectIsKindOf (item, "LeatherSack_Natural") )
322 {
323 item_name = "Bag_LeatherSack_"+color;
324 }
325 else if ( GetGame().ObjectIsKindOf (item, "LeatherStorageVest_Natural") )
326 {
327 item_name = "Vest_LeatherStorage_"+color;
328 }
329 else if ( GetGame().ObjectIsKindOf (item, "LeatherJacket_Natural") )
330 {
331 item_name = "Top_LeatherJacket_"+color;
332 }
333 else if ( GetGame().ObjectIsKindOf (item, "LeatherPants_Natural") )
334 {
335 item_name = "Pants_LeatherPants_"+color;
336 }
337 else if ( GetGame().ObjectIsKindOf (item, "LeatherMoccasinsShoes_Natural") )
338 {
339 item_name = "Shoes_LeatherMoccasins_"+color;
340 }
341 else if ( GetGame().ObjectIsKindOf (item, "LeatherHat_Natural") )
342 {
343 item_name = "Hat_Leather_"+color;
344 }
345 if ( item_name != "" )
346 {
347 TurnItemIntoItemLambda lambda = new TurnItemIntoItemLambda(item, item_name, player);
348 lambda.SetTransferParams(true, true, true);
349 player.ServerReplaceItemWithNew(lambda);
350 }
351 }
352 }
353 if ( item_name != "" )
354 {
355 Lock(20);
356 }
357 }
358
359
360 void BleachClothes( ItemBase bleach, PlayerBase player )
361 {
362 EntityAI item;
363 int bleach_amount = bleach.GetQuantity();
364 int item_count = GetInventory().GetCargo().GetItemCount();
365 string item_name = "";
366
367 for (int i = 0; i < item_count; i++)
368 {
369 item = GetInventory().GetCargo().GetItem(i);
370 if ( item.IsClothing() )
371 {
372 if ( bleach_amount >= GameConstants.BAREL_BLEACH_PER_CLOTH )
373 {
374 if ( ( GetGame().ObjectIsKindOf (item, "TShirt_ColorBase") && !GetGame().ObjectIsKindOf (item, "TShirt_White") ) || ( GetGame().ObjectIsKindOf (item, "Armband_ColorBase") && !GetGame().ObjectIsKindOf (item, "Armband_White") ) ) //cannot bleach white items...?
375 {
376 int index = item.GetType().IndexOf("_");
377 string itemtype = item.GetType().Substring( 0, index + 1 );
378 ItemBase itemIB = ItemBase.Cast(item);
379 MiscGameplayFunctions.TurnItemIntoItem(itemIB,itemtype+"White",player);
380
381 bleach_amount -= GameConstants.BAREL_BLEACH_PER_CLOTH;
382 }
383 if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherSack_ColorBase") )
384 {
385 item_name = "LeatherSack_Natural";
386 }
387 else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherStorageVest_ColorBase") )
388 {
389 item_name = "LeatherStorageVest_Natural";
390 }
391 else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherJacket_ColorBase") )
392 {
393 item_name = "LeatherJacket_Natural";
394 }
395 else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherPants_ColorBase") )
396 {
397 item_name = "LeatherPants_Natural";
398 }
399 else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherMoccasinsShoes_ColorBase") )
400 {
401 item_name = "LeatherMoccasinsShoes_Natural";
402 }
403 else if ( GetGame().IsKindOf (item.GetDisplayName(), "LeatherHat_ColorBase") )
404 {
405 item_name = "LeatherHat_Natural";
406 }
407 if ( item_name != "" )
408 {
409 TurnItemIntoItemLambda lambda = new TurnItemIntoItemLambda(item, item_name, player);
410 lambda.SetTransferParams(true, true, true);
411 player.ServerReplaceItemWithNew(lambda);
412 bleach_amount -= GameConstants.BAREL_BLEACH_PER_CLOTH;
413 }
414 }
415 else
416 {
417 bleach.Delete();
418 break;
419 }
420 }
421 }
422 if ( bleach )
423 {
424 bleach.SetQuantity(bleach_amount);
425 }
426 if ( item_name != "" )
427 {
428 Lock(10);
429 }
430 }
431
432 void ColourClothes( ItemBase rci, ItemBase gci, ItemBase bci, PlayerBase player )
433 {
434 EntityAI item;
435 float r = 0;
436 float g = 0;
437 float b = 0;
438 float a = 1; //alpha
439 int item_count = GetInventory().GetCargo().GetItemCount();
440 bool was_colored = false;
441 if ( rci )
442 {
443 r = rci.GetQuantity()/10;
444 r = Math.Clamp(r, 0, 0.78); //TODO adjust clamp as needed, full RGB would result in a white item
445 }
446 if ( gci )
447 {
448 g = gci.GetQuantity()/10;
449 g = Math.Clamp(g, 0, 0.78);
450 }
451 if ( bci )
452 {
453 b = bci.GetQuantity()/10;
454 b = Math.Clamp(b, 0, 0.78);
455 }
456 for (int i = 0; i < item_count; i++)
457 {
458 item = GetInventory().GetCargo().GetItem(i);
459 if ( item.IsClothing() )
460 {
461 if ( GetGame().ObjectIsKindOf (item, "TShirt_White") || GetGame().ObjectIsKindOf (item, "Armband_White") )
462 {
463 ItemBase itemIB = ItemBase.Cast(item);
464 int index = itemIB.GetType().IndexOf("_");
465 string itemtype = itemIB.GetType().Substring( 0, index + 1 );
466
467 ColourClothesLambda clambda = new ColourClothesLambda(itemIB, itemtype + "Dyed", player, r, g, b, a);
468 clambda.SetTransferParams(true, true, true);
469 MiscGameplayFunctions.TurnItemIntoItemEx(player, clambda);
470 was_colored = true;
471 }
472 }
473 }
474
475 if ( was_colored )
476 {
477 if ( rci )
478 {
479 //rci.AddQuantity(-r*10,true,false);
480 rci.Delete();
481 }
482 if ( gci )
483 {
484 //gci.AddQuantity(-g*10,true,false);
485 gci.Delete();
486 }
487 if ( bci )
488 {
489 //bci.AddQuantity(-b*10,true,false);
490 bci.Delete();
491 }
492 Lock(30);
493 }
494 }
495
496 override bool CanPutInCargo( EntityAI parent )
497 {
498 if ( !super.CanPutInCargo( parent ))
499 return false;
500
501 if ( GetNumberOfItems() == 0 && !IsOpen() )
502 return true;
503
504 return false;
505 }
506
507 override bool CanPutIntoHands( EntityAI parent )
508 {
509 if ( !super.CanPutIntoHands( parent ))
510 return false;
511
512 if ( GetNumberOfItems() == 0 && (GetInventory().IsAttachment() || !IsOpen()) )
513 return true;
514
515 return false;
516 }
517
518 override bool CanReceiveItemIntoCargo( EntityAI item )
519 {
520 if ( IsOpen() )
521 return super.CanReceiveItemIntoCargo( item );
522
523 return false;
524 }
525
526 override bool CanReleaseCargo( EntityAI attachment )
527 {
528 return IsOpen();
529 }
530
531 override bool CanDetachAttachment( EntityAI parent )
532 {
533 if ( GetNumberOfItems() == 0)
534 return true;
535 return false;
536 }
537
538 //================================================================
539 // ADVANCED PLACEMENT
540 //================================================================
541 override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
542 {
543 super.OnPlacementComplete( player, position, orientation );
544
545 SetIsPlaceSound( true );
546 }
547
548 override string GetPlaceSoundset()
549 {
550 return "placeBarrel_SoundSet";
551 }
552 //================================================================
553
554 override float GetLiquidThroughputCoef()
555 {
557 }
558
559 override void SetActions()
560 {
562 super.SetActions();
563
566
567 }
568
569 override void OnDebugSpawn()
570 {
572 }
573
575 //OUBLIETTE OF THE DEPRECATED CODE//
578};
579
584
586{
587 int r, g, b, a;
588 void ColourClothesLambda(EntityAI old_item, string new_item_type, PlayerBase player, int rr, int gg, int bb, int aa)
589 { r = rr; g = gg; b = bb; a = aa; }
590
591 override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
592 {
593 super.CopyOldPropertiesToNew(old_item, new_item);
594
595 //Print("ColourClothesLambda::OnCreated object=" + new_item);
596 ItemBase ib = ItemBase.Cast(new_item);
597 if ( new_item )
598 {
599 new_item.SetObjectTexture(new_item.GetHiddenSelectionsData().GetHiddenSelectionIndex( "personality" ), MiscGameplayFunctions.GetColorString(r, g, b, a));
600
601 //nitem.SetItemVariableString("varColor", color); //SYNCFAIL
602 ib.SetColor(r*255, g*255, b*255, a*255);
603 }
604 }
605};
606
608{
610
611 void TanLeatherLambda (EntityAI old_item, string new_item_type, PlayerBase player, int pelt_count) { m_PeltCount = pelt_count; }
612
613 override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
614 {
615 super.CopyOldPropertiesToNew(old_item, new_item);
616
617 if (new_item)
618 {
619 ItemBase tanned_pelt = ItemBase.Cast( new_item );
620 tanned_pelt.SetQuantity(m_PeltCount);
621 }
622 else
623 {
624 Debug.LogError("TanLeatherLambda: failed to create new item","static");
625 }
626 }
627};
void AddAction(typename actionName)
void DeployableContainer_Base()
Container_Base m_HalfExtents
DayZGame g_Game
Definition DayZGame.c:3654
void SoundSynchRemote()
Definition ItemBase.c:8883
override float GetQuantity()
Definition ItemBase.c:7967
void SetQuantityMax()
Definition ItemBase.c:7871
override bool IsBeingPlaced()
Definition ItemBase.c:5540
override void SetTakeable(bool pState)
Definition ItemBase.c:8843
void SetIsPlaceSound(bool is_place_sound)
Definition ItemBase.c:8900
int GetNumberOfItems()
Returns the number of items in cargo, otherwise returns 0(non-cargo objects). Recursive.
Definition ItemBase.c:8031
void PlayPlaceSound()
Definition ItemBase.c:8938
bool IsPlaceSound()
Definition ItemBase.c:8905
bool IsSoundSynchRemote()
Definition ItemBase.c:8890
protected bool m_Initialized
class JsonUndergroundAreaTriggerData GetPosition
override bool IsOpen()
override void OnDebugSpawn()
protected ref RainProcurementComponentBarrel m_RainProcComponent
override bool CanReleaseCargo(EntityAI attachment)
void TanPelts(ItemBase lime, PlayerBase player)
override void OnStoreSave(ParamsWriteContext ctx)
override bool CanReceiveItemIntoCargo(EntityAI item)
void ColourLeatherClothes(ItemBase color_source, PlayerBase player, string color)
void ColourClothes(ItemBase rci, ItemBase gci, ItemBase bci, PlayerBase player)
void Lock(float actiontime)
override bool CanPutInCargo(EntityAI parent)
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
void DetermineAction(PlayerBase player)
override int GetDamageSystemVersionChange()
override string GetPlaceSoundset()
ref RainProcurementManager m_RainProcurement
override void OnWasDetached(EntityAI parent, int slot_id)
override bool CanPutIntoHands(EntityAI parent)
override bool OnStoreLoad(ParamsReadContext ctx, int version)
override void Close()
private ref Timer m_BarrelOpener
protected ref OpenableBehaviour m_Openable
override void OnWasAttached(EntityAI parent, int slot_id)
override void OnVariablesSynchronized()
protected void UpdateVisualState()
private bool m_IsLocked
override bool CanDetachAttachment(EntityAI parent)
override void Open()
void ProduceFertilizer(ItemBase guts, ItemBase plant, PlayerBase player)
override float GetLiquidThroughputCoef()
void BleachClothes(ItemBase bleach, PlayerBase player)
override void SetActions()
override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
void ColourClothesLambda(EntityAI old_item, string new_item_type, PlayerBase player, int rr, int gg, int bb, int aa)
Definition Debug.c:14
static void LogError(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as error message.
Definition Debug.c:235
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
Definition EnMath.c:7
void StopRainProcurement()
Called on server to queue rain procurement removal (on next cycle end)
void StartRainProcurement()
Called on server to queue rain procurement (on next cycle end)
DEPRECATED, done through the RainProcurementHandler / component instead.
Manager class for managing Effect (EffectParticle, EffectSound)
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.
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 CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
void TanLeatherLambda(EntityAI old_item, string new_item_type, PlayerBase player, int pelt_count)
proto native CGame GetGame()
const int BAREL_LIME_PER_PELT
Definition constants.c:808
const float BAREL_LIME_PER_PLANT
Definition constants.c:810
const int BAREL_BLEACH_PER_CLOTH
Definition constants.c:809
const float LIQUID_THROUGHPUT_BARREL
Definition constants.c:515
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float Floor(float f)
Returns floor of value.