DayZ 1.24
Loading...
Searching...
No Matches
ActionAttachOnSelection.c
Go to the documentation of this file.
2{
4 {
5 m_Text = "#attach";
6 }
7
9 {
12 }
13
19
21 {
22 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
23 if (targetEntity && item)
24 {
25 if (!targetEntity.GetInventory())
27
28 int slotsCount = item.GetInventory().GetSlotIdCount();
30 targetEntity.GetActionComponentNameList(target.GetComponentIndex(), selections);
31
32 foreach (string selection : selections)
33 {
34 int slotId = -1;
35 if (!targetEntity.TranslateSlotFromSelection(selection, slotId))
37
38 if (slotId == -1)
39 continue;
40
41 for (int i = 0; i < slotsCount; ++i)
42 {
43 int itemSlotId = item.GetInventory().GetSlotId(i);
44 if (slotId == itemSlotId)
45 {
46 ItemBase currentAttachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(slotId));
48 {
49 if (currentAttachment.CanBeCombined(item))
50 return itemSlotId;
51 }
52 else
53 {
54 if (targetEntity.GetInventory() && targetEntity.GetInventory().CanAddAttachment(item))
55 return itemSlotId;
56 }
57 }
58 }
59 }
60 }
61
63 }
64
65
67 {
69 if (!GetGame().IsDedicatedServer())
71
72 if (super.SetupAction(player, target, item, action_data, extra_data))
73 {
74 if (!GetGame().IsDedicatedServer())
75 {
77 {
79 action_data_a.m_AttSlot = attSlotId;
80
81 return true;
82 }
83
84 return false;
85 }
86
87 return true;
88 }
89
90 return false;
91 }
92
93 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
94 {
95 if (GetGame().IsMultiplayer() && GetGame().IsServer())
96 return true;
97
98 if (target.GetObject() && target.GetObject().CanUseConstruction())
99 return false;
100
102 }
103
105 {
106 if (GetGame().IsMultiplayer())
107 return;
108
110
113
114 if (action_data.m_Target.IsProxy())
115 entity = EntityAI.Cast(action_data.m_Target.GetParent());
116 else
117 entity = EntityAI.Cast(action_data.m_Target.GetObject());
118
119 if (entity && action_data.m_MainItem)
120 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data_a.m_MainItem, action_data_a.m_AttSlot);
121 }
122
124 {
126 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
127 EntityAI itemEntity = action_data.m_MainItem;
128
130
131 ItemBase attachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
132 if (attachment)
133 attachment.CombineItemsClient(itemEntity);
134 else
135 {
137 float stackable = item_base.GetTargetQuantityMax(action_data_a.m_AttSlot);
138
139 if (stackable == 0 || stackable >= item_base.GetQuantity())
140 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, itemEntity, action_data_a.m_AttSlot);
141 else if (stackable != 0 && stackable < item_base.GetQuantity())
142 item_base.SplitIntoStackMaxClient(targetEntity, action_data_a.m_AttSlot);
143 }
144 }
145}
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:790
override void CreateConditionComponents()
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=null)
int FindSlotIdToAttachOrCombine(PlayerBase player, ActionTarget target, ItemBase item)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override void OnExecuteServer(ActionData action_data)
override ActionData CreateActionData()
override void OnExecuteClient(ActionData action_data)
provides access to slot configuration
const int INVALID
Invalid slot (-1)
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
proto native CGame GetGame()