DayZ 1.24
Loading...
Searching...
No Matches
MetalWire.c
Go to the documentation of this file.
1class 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 return false;
25 }
26
27 return true;
28 }
29
31 {
32 HideAllSelections();
33 EntityAI energy_source = GetCompEM().GetEnergySource();
34
35 if (energy_source)
36 {
37 string ES_model = energy_source.GetModelName();
38 EntityAI powered_device = GetCompEM().GetPluggedDevice();
39
41 {
42 // Show metal wire selection
43 string selection_wire = SEL_WIRE_PREFIX + ES_model + SEL_WIRE_SUFIX;
44 ShowSelection(selection_wire);
45
46 // Show plug selection
47 string selection_plug = SEL_WIRE_PREFIX + ES_model + SEL_PLUG_SUFIX;
48 selection_plug.ToLower();
49 ShowSelection(selection_plug);
50
51 // Set plug's texture
52 int selection_index = GetHiddenSelectionIndex(selection_plug);
53 string texture_path = powered_device.GetCompEM().GetCordTextureFile();
54 SetObjectTexture(selection_index, texture_path);
55 }
56 else
57 {
58 // Show metal wire selection
59 string selection_wire2 = SEL_WIRE_PREFIX + ES_model;
60 ShowSelection(selection_wire2);
61 }
62 }
63 else
64 ShowSelection(SEL_WIRE_ROLLED);
65 }
66
67 // Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter
68 override void OnInventoryEnter(Man player)
69 {
70 super.OnInventoryEnter(player);
71
74 if (player_PB.GetItemInHands() == this && GetCompEM().IsPlugged())
75 return;
76
77 //Only unplug if we are "powering" something
78 ItemBase powered_device = ItemBase.Cast(GetCompEM().GetPluggedDevice());
80 {
81 GetCompEM().UnplugAllDevices();
82
83 if (!player_PB.IsPlacingLocal())
84 GetCompEM().UnplugThis();
85 }
86 }
87
88 // Called when THIS is attached to battery
90 {
92 }
93
94 // Called when THIS is detached from battery
96 {
98 GetCompEM().UnplugAllDevices();
99 }
100
101 // Called when some device is plugged into THIS
103 {
105 }
106
107 // Called when some device is unplugged from THIS
109 {
111 }
112
113 override void SetActions()
114 {
115 super.SetActions();
116
120 AddAction(ActionAttach);
121 }
122}
void AddAction(typename actionName)
Super root of all classes in Enforce script.
Definition EnScript.c:11
override void OnInventoryEnter(Man player)
Definition MetalWire.c:68
override bool CanPutAsAttachment(EntityAI parent)
Definition MetalWire.c:13
override void OnIsPlugged(EntityAI source_device)
Definition MetalWire.c:89
override void OnOwnSocketReleased(EntityAI device)
Definition MetalWire.c:108
override void OnOwnSocketTaken(EntityAI device)
Definition MetalWire.c:102
override void SetActions()
Definition MetalWire.c:113
static string SEL_PLUG_SUFIX
Definition MetalWire.c:6
override void OnIsUnplugged(EntityAI last_energy_source)
Definition MetalWire.c:95
void MetalWire()
Definition MetalWire.c:8
static string SEL_WIRE_SUFIX
Definition MetalWire.c:5
void UpdateAllSelections()
Definition MetalWire.c:30
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.