Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
actionattachonselection.c
Go to the documentation of this file.
2{
4 {
5 m_Text = "#attach";
6 }
7
8 override void CreateConditionComponents()
9 {
12 }
13
15 {
16 AttachActionData action_data = new AttachActionData();
17 return action_data;
18 }
19
21 {
22 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
23 if (targetEntity && item)
24 {
25 GameInventory inv = targetEntity.GetInventory();
26 if (!inv)
28
29 int slotsCount = item.GetInventory().GetSlotIdCount();
30 array<string> selections = new array<string>();
31 targetEntity.GetActionComponentNameList(target.GetComponentIndex(), selections);
32
33 foreach (string selection : selections)
34 {
35 int slotId = -1;
36 if (!targetEntity.TranslateSlotFromSelection(selection, slotId))
37 slotId = InventorySlots.GetSlotIdFromString(selection);
38
39 if (slotId == -1)
40 continue;
41
42 for (int i=0; i < slotsCount; ++i)
43 {
44 int itemSlotId = item.GetInventory().GetSlotId(i);
45 if (slotId == itemSlotId)
46 {
47 ItemBase currentAttachment = ItemBase.Cast(inv.FindAttachment(slotId));
48 if (currentAttachment)
49 {
50 if (currentAttachment.CanBeCombined(item))
51 return itemSlotId;
52 }
53 else
54 {
55 if (inv.CanAddAttachment(item))
56 return itemSlotId;
57 }
58 }
59 }
60 }
61 }
62
64 }
65
66
67 override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
68 {
69 int attSlotId = InventorySlots.INVALID;
70 if (!g_Game.IsDedicatedServer() )
71 {
72 attSlotId = FindSlotIdToAttachOrCombine(player, target, item);
73 }
74
75 if (super.SetupAction( player, target, item, action_data, extra_data))
76 {
77 if (!g_Game.IsDedicatedServer())
78 {
79 if (attSlotId != InventorySlots.INVALID)
80 {
81 AttachActionData action_data_a = AttachActionData.Cast(action_data);
82 action_data_a.m_AttSlot = attSlotId;
83
84 return true;
85 }
86
87 return false;
88 }
89
90 return true;
91 }
92
93 return false;
94 }
95
96 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
97 {
98 if (g_Game.IsMultiplayer() && g_Game.IsServer())
99 return true;
100
101 if (target.GetObject() && target.GetObject().CanUseConstruction())
102 return false;
103
104 return FindSlotIdToAttachOrCombine(player, target, item) != InventorySlots.INVALID;
105 }
106
107 override void OnExecuteServer( ActionData action_data )
108 {
109 if (g_Game.IsMultiplayer())
110 return;
111
112 ClearInventoryReservationEx(action_data);
113
114 AttachActionData action_data_a = AttachActionData.Cast(action_data);
115 EntityAI entity;
116
117 if (action_data.m_Target.IsProxy())
118 {
119 entity = EntityAI.Cast(action_data.m_Target.GetParent());
120 }
121 else
122 {
123 entity = EntityAI.Cast(action_data.m_Target.GetObject());
124 }
125
126 if (entity && action_data.m_MainItem)
127 {
128 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data_a.m_MainItem, action_data_a.m_AttSlot);
129 }
130 }
131
132 override void OnExecuteClient(ActionData action_data)
133 {
134 ClearInventoryReservationEx(action_data);
135 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
136 EntityAI itemEntity = action_data.m_MainItem;
137
138 AttachActionData action_data_a = AttachActionData.Cast(action_data);
139
140 ItemBase attachment = ItemBase.Cast(targetEntity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
141 if (attachment)
142 {
143 attachment.CombineItemsClient(itemEntity);
144 }
145 else
146 {
147 ItemBase item_base = ItemBase.Cast( itemEntity );
148 float stackable = item_base.GetTargetQuantityMax( action_data_a.m_AttSlot );
149
150 if (stackable == 0 || stackable >= item_base.GetQuantity())
151 {
152 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, itemEntity, action_data_a.m_AttSlot);
153 }
154 else if (stackable != 0 && stackable < item_base.GetQuantity())
155 {
156 item_base.SplitIntoStackMaxClient(targetEntity, action_data_a.m_AttSlot);
157 }
158 }
159 }
160}
ActionBase ActionData
Definition actionbase.c:30
class ActionTargets ActionTarget
int FindSlotIdToAttachOrCombine(PlayerBase player, ActionTarget target, ItemBase item)
override void OnExecuteServer(ActionData action_data)
override ActionData CreateActionData()
override void CreateConditionComponents()
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=null)
override void OnExecuteClient(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
string m_Text
Definition actionbase.c:64
ref CCIBase m_ConditionItem
Definition actionbase.c:70
ref CCTBase m_ConditionTarget
Definition actionbase.c:71
void ClearInventoryReservationEx(ActionData action_data)
script counterpart to engine's class Inventory
Definition inventory.c:81
proto native bool CanAddAttachment(notnull EntityAI e)
proto native EntityAI FindAttachment(int slot)
Returns attached entity in slot (you can use InventorySlots.GetSlotIdFromString(name) to get slot id)...
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
const int INVALID
Invalid slot (-1).
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition rag.c:61
Base Param Class with no parameters.
Definition param.c:12
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942