Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
metalwire.c
Go to the documentation of this file.
1 class MetalWire extends ItemBase
2 {
3  static string SEL_WIRE_ROLLED = "rolled";
4  static string SEL_WIRE_PREFIX = "Att_";
5  static string SEL_WIRE_SUFIX = "_plugged";
6  static string SEL_PLUG_SUFIX = "_plug";
7 
8  void MetalWire()
9  {
10 
11  }
12 
13  override bool CanPutAsAttachment( EntityAI parent )
14  {
15  if (!super.CanPutAsAttachment(parent))
16  return false;
17 
18  if ( parent.IsInherited(VehicleBattery) )
19  {
20  EntityAI battery_owner = EntityAI.Cast( parent.GetHierarchyParent() );
21 
22  // Check for Not player as if parent is not player, battery is already attached and should not receive new attachment
23  if ( battery_owner && !battery_owner.IsInherited(PlayerBase) )
24  {
25  return false;
26  }
27  }
28 
29  return true;
30  }
31 
32  void UpdateAllSelections()
33  {
34  HideAllSelections();
35  EntityAI energy_source = GetCompEM().GetEnergySource();
36 
37  if (energy_source)
38  {
39  string ES_model = energy_source.GetModelName();
40  EntityAI powered_device = GetCompEM().GetPluggedDevice();
41 
42  if (powered_device)
43  {
44  // Show metal wire selection
45  string selection_wire = SEL_WIRE_PREFIX + ES_model + SEL_WIRE_SUFIX;
46  ShowSelection(selection_wire);
47 
48  // Show plug selection
49  string selection_plug = SEL_WIRE_PREFIX + ES_model + SEL_PLUG_SUFIX;
50  selection_plug.ToLower();
51  ShowSelection(selection_plug);
52 
53  // Set plug's texture
54  int selection_index = GetHiddenSelectionIndex(selection_plug);
55  string texture_path = powered_device.GetCompEM().GetCordTextureFile();
56  SetObjectTexture( selection_index, texture_path );
57  }
58  else
59  {
60  // Show metal wire selection
61  string selection_wire2 = SEL_WIRE_PREFIX + ES_model;
62  ShowSelection(selection_wire2);
63  }
64  }
65  else
66  {
67  ShowSelection(SEL_WIRE_ROLLED);
68  }
69  }
70 
71  // Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
72  override void OnInventoryEnter( Man player )
73  {
74  super.OnInventoryEnter( player );
75 
76  PlayerBase player_PB;
77  Class.CastTo( player_PB, player );
78  if ( player_PB.GetItemInHands() == this && GetCompEM().IsPlugged() )
79  {
80  return;
81  }
82 
83  //Only unplug if we are "powering" something
84  ItemBase powered_device = ItemBase.Cast( GetCompEM().GetPluggedDevice() );
85  if ( powered_device )
86  {
87  GetCompEM().UnplugAllDevices();
88 
89  if ( !player_PB.IsPlacingLocal() )
90  {
91  GetCompEM().UnplugThis();
92  }
93  }
94  }
95 
96  // Called when THIS is attached to battery
97  override void OnIsPlugged(EntityAI source_device)
98  {
99  UpdateAllSelections();
100  }
101 
102  // Called when THIS is detached from battery
103  override void OnIsUnplugged(EntityAI last_energy_source)
104  {
105  UpdateAllSelections();
106  GetCompEM().UnplugAllDevices();
107  }
108 
109  // Called when some device is plugged into THIS
110  override void OnOwnSocketTaken( EntityAI device )
111  {
112  UpdateAllSelections();
113  }
114 
115  // Called when some device is unplugged from THIS
116  override void OnOwnSocketReleased( EntityAI device )
117  {
118  UpdateAllSelections();
119  }
120 
121  override void SetActions()
122  {
123  super.SetActions();
124 
129  }
130 }
ItemBase
Definition: inventoryitem.c:730
ActionAttachToConstruction
Definition: actionattachtoconstruction.c:1
ActionRestrainTarget
Definition: actionrestraintarget.c:23
VehicleBattery
Definition: vehiclebattery.c:1
CanPutAsAttachment
override bool CanPutAsAttachment(EntityAI parent)
Definition: itembase.c:4021
OnInventoryEnter
override protected void OnInventoryEnter(Man player)
Definition: fireworksbase.c:71
PlayerBase
Definition: playerbaseclient.c:1
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetActions
void SetActions()
Definition: advancedcommunication.c:79
ActionAttach
ActionAttachWheels ActionAttach
ActionRestrainSelf
Definition: actionrestrainself.c:23
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5