Dayz  1.11.153731
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 
33  {
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  // Called when THIS is attached to battery
72  override void OnIsPlugged(EntityAI source_device)
73  {
75  }
76 
77  // Called when THIS is detached from battery
78  override void OnIsUnplugged(EntityAI last_energy_source)
79  {
82  }
83 
84  // Called when some device is plugged into THIS
85  override void OnOwnSocketTaken( EntityAI device )
86  {
88  }
89 
90  // Called when some device is unplugged from THIS
91  override void OnOwnSocketReleased( EntityAI device )
92  {
94  }
95 
96  override void SetActions()
97  {
98  super.SetActions();
99 
103  }
104 }
ItemBase
Definition: InventoryItem.c:445
GetHiddenSelectionIndex
int GetHiddenSelectionIndex(string selection)
Returns index of the string found in cfg array 'hiddenSelections'. If it's not found then it returns ...
Definition: EntityAI.c:1505
ActionAttachToConstruction
Definition: ActionAttachToConstruction.c:1
ItemBase::UpdateAllSelections
void UpdateAllSelections()
Definition: MetalWire.c:32
AddAction
void AddAction(typename actionName)
Definition: AdvancedCommunication.c:86
ActionRestrainTarget
Definition: ActionRestrainTarget.c:23
VehicleBattery
Definition: VehicleBattery.c:1
ItemBase::OnIsPlugged
override void OnIsPlugged(EntityAI source_device)
Definition: MetalWire.c:72
ComponentEnergyManager::UnplugAllDevices
void UnplugAllDevices()
Energy manager: Unplugs everything directly connected to this device.
Definition: ComponentEnergyManager.c:450
ItemBase::OnOwnSocketReleased
override void OnOwnSocketReleased(EntityAI device)
Definition: MetalWire.c:91
SetObjectTexture
proto native void SetObjectTexture(int index, string texture_name)
Change texture in hiddenSelections.
PlayerBase
Definition: PlayerBaseClient.c:1
ShowSelection
void ShowSelection(string selection_name)
Shows selection of the given name. Must be configed in config.hpp and models.cfg.
Definition: EntityAI.c:1849
ItemBase::SetActions
override void SetActions()
Definition: MetalWire.c:96
ItemBase::SEL_WIRE_SUFIX
static string SEL_WIRE_SUFIX
Definition: MetalWire.c:5
ItemBase::OnIsUnplugged
override void OnIsUnplugged(EntityAI last_energy_source)
Definition: MetalWire.c:78
GetCompEM
ComponentEnergyManager GetCompEM()
energy manager ENERGY MANAGER:Documentation: Confluence >> Camping & Squatting >> Electricity >> Ener...
Definition: EntityAI.c:1885
ItemBase::SEL_PLUG_SUFIX
static string SEL_PLUG_SUFIX
Definition: MetalWire.c:6
ActionRestrainSelf
Definition: ActionRestrainSelf.c:23
string::ToLower
proto int ToLower()
Changes string to lowercase.
ItemBase::CanPutAsAttachment
override bool CanPutAsAttachment(EntityAI parent)
Definition: MetalWire.c:13
ItemBase::OnOwnSocketTaken
override void OnOwnSocketTaken(EntityAI device)
Definition: MetalWire.c:85
ItemBase::MetalWire
void MetalWire()
Definition: MetalWire.c:8
ComponentEnergyManager::GetPluggedDevice
EntityAI GetPluggedDevice()
Energy manager: Returns a device which is plugged into this one. If there are more devices to choose ...
Definition: ComponentEnergyManager.c:1232
HideAllSelections
void HideAllSelections()
Sets all animation values to 1, making them INVISIBLE if they are configured in models....
Definition: EntityAI.c:881
EntityAI
Base native class of all vehicles in game.
Definition: Building.c:4
ComponentEnergyManager::GetEnergySource
EntityAI GetEnergySource()
Energy manager: Returns the energy source this device is plugged into.
Definition: ComponentEnergyManager.c:1209