DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionPlugIn.c
Go to the documentation of this file.
2{
4 {
5 m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_INTERACTONCE;
6 m_Text = "#plug_in";
7 }
8
9 override void CreateConditionComponents()
10 {
13 }
14
15 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
16 {
17 if (player.IsPlacingLocal())
18 return false;
19
20 ItemBase targetIB = ItemBase.Cast(target.GetObject());
21
22 //Prevent plugging to items in inventory
23 if (targetIB && targetIB.GetHierarchyRoot() == targetIB && item)
24 {
25 if (item.HasEnergyManager() && !item.GetCompEM().IsPlugged() && targetIB.HasEnergyManager() && targetIB.GetCompEM().CanReceivePlugFrom(item))
26 {
27 return true;
28 }
29
30 ItemBase attachedDevice = GetAttachedDevice(targetIB);
31 //Will only ever affect batteries
32 if (attachedDevice)
33 {
34 return attachedDevice.GetCompEM().HasFreeSocket();
35 }
36 }
37
38 return false;
39 }
40
41 override void OnExecuteServer(ActionData action_data)
42 {
43 ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
44
45 if (targetIB.HasEnergyManager())
46 {
47 ItemBase attachedDevice = GetAttachedDevice(targetIB);
48 if (attachedDevice)
49 {
50 targetIB = attachedDevice;
51 }
52
53 action_data.m_MainItem.GetCompEM().PlugThisInto(targetIB);
54
55 if (!action_data.m_Player.IsPlacingServer())
56 {
57 Process(action_data);
58 }
59 }
60 }
61
62 void Process( ActionData action_data )
63 {
64 ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
65
66 targetIB.GetInventory().TakeEntityAsAttachment(InventoryMode.LOCAL, action_data.m_MainItem);
67 }
68
69 override void OnExecuteClient(ActionData action_data)
70 {
71 if (!action_data.m_Player.IsPlacingLocal())
72 {
73 action_data.m_Player.TogglePlacingLocal();
74 }
75 else
76 {
77 Process(action_data);
78 }
79 }
80
82 {
83 if (parent.IsInherited(CarBattery) || parent.IsInherited(TruckBattery))
84 {
85 ItemBase parentAttachment = ItemBase.Cast(parent.GetAttachmentByType(MetalWire));
86 if (!parentAttachment)
87 {
88 parentAttachment = ItemBase.Cast(parent.GetAttachmentByType(BarbedWire));
89 }
90
91 return parentAttachment;
92 }
93
94 return null;
95 }
96};
InventoryMode
Definition Inventory.c:20
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
protected string m_Text
Definition ActionBase.c:49
class ActionTargets ActionTarget
ItemBase m_MainItem
Definition ActionBase.c:28
PlayerBase m_Player
Definition ActionBase.c:33
ref ActionTarget m_Target
Definition ActionBase.c:32
ItemBase GetAttachedDevice(ItemBase parent)
override void OnExecuteServer(ActionData action_data)
override void CreateConditionComponents()
Definition ActionPlugIn.c:9
override void OnExecuteClient(ActionData action_data)
void ActionPlugIn()
Definition ActionPlugIn.c:3
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
void Process(ActionData action_data)
const float DEFAULT
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602