Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
actiondetachfromtarget.c
Go to the documentation of this file.
2{
3
9
11 {
12 m_Text = "#take_to_hands";
13 }
14
15 override typename GetInputType()
16 {
18 }
19
21 {
22 DetachActionData action_data = new DetachActionData;
23 return action_data;
24 }
25
27 {
28 EntityAI target_entity = EntityAI.Cast(target.GetObject());
29
30 if ( player && target_entity )
31 {
32 array<string> selections = new array<string>();
33 target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
34
35 if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
36 {
37 for(int i = 0; i < selections.Count(); i++ )
38 {
39 int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
40 EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
41
42 if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
43 {
44 if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
45 return target_slot_id;
46 }
47 }
48 }
49 }
51 }
52
53 override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
54 {
55 int attSlotId = InventorySlots.INVALID;
56 if (!g_Game.IsDedicatedServer() )
57 {
58 attSlotId = FindSlotIdToDetach(player, target, item);
59 }
60
61 if ( super.SetupAction( player, target, item, action_data, extra_data))
62 {
63 if (!g_Game.IsDedicatedServer())
64 {
65 if(attSlotId != InventorySlots.INVALID)
66 {
67 DetachActionData action_data_a = DetachActionData.Cast(action_data);
68 action_data_a.m_AttSlot = attSlotId;
69 return true;
70 }
71 return false;
72 }
73 return true;
74 }
75 return false;
76 }
77
78 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
79 {
80 if ( g_Game.IsMultiplayer() && g_Game.IsServer() ) return true;
81
82 return FindSlotIdToDetach(player, target, item) != InventorySlots.INVALID;
83 }
84
86 {
87 int target_slot_id = FindSlotIdToDetach(player, target, null);
88 EntityAI target_entity = EntityAI.Cast( target.GetObject() );
89
90 if(target_slot_id != InventorySlots.INVALID)
91 {
92 return target_entity.GetInventory().FindAttachment(target_slot_id);
93 }
94 return null;
95 }
96
97 override void OnExecute(ActionData action_data)
98 {
99 if (g_Game.IsDedicatedServer())
100 {
101 ClearActionJuncture(action_data);
102 return;
103 }
104
105 Process(action_data);
106 }
107
108 void Process( ActionData action_data )
109 {
110 ClearInventoryReservationEx(action_data);
111
112 DetachActionData action_data_a = DetachActionData.Cast(action_data);
113 EntityAI target_entity = EntityAI.Cast( action_data_a.m_Target.GetObject() );
114
115 ItemBase attachment = ItemBase.Cast(target_entity.GetInventory().FindAttachment(action_data_a.m_AttSlot));
116
117 if(attachment)
118 {
119 float stackable = attachment.GetTargetQuantityMax();
120 if( stackable == 0 || stackable >= attachment.GetQuantity() )
121 {
122 //take to hands
123 action_data.m_Player.PredictiveTakeEntityToHands( attachment );
124 }
125 else if( stackable != 0 && stackable < attachment.GetQuantity() )
126 {
127 //split and take to hands
128 attachment.SplitIntoStackMaxHandsClient( action_data.m_Player );
129 }
130 }
131 }
132}
133
134class ActionDetachFromTarget_SpecificSlot: ActionDetachFromTarget
135{
137
138 override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
139 {
140 EntityAI target_entity = EntityAI.Cast(target.GetObject());
141
142 if ( player && target_entity )
143 {
144 array<string> selections = new array<string>();
145 target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
146
147 if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
148 {
149 for(int i = 0; i < selections.Count(); i++ )
150 {
151 if( selections[i] == m_slotToDetach )
152 {
153 int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
154 EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
155
156 if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
157 {
158 if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
159 return target_slot_id;
160 }
161 }
162 }
163 }
164 }
165 return InventorySlots.INVALID;
166 }
167}
168
170{
172
173 override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
174 {
175 EntityAI target_entity = EntityAI.Cast(target.GetObject());
176
177 if ( player && target_entity )
178 {
179 array<string> selections = new array<string>();
180 target_entity.GetActionComponentNameList( target.GetComponentIndex(),selections );
181
182 if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 )
183 {
184 for(int i = 0; i < selections.Count(); i++ )
185 {
186 if (selections[i].Contains(m_slotsToDetach))
187 {
188 int target_slot_id = InventorySlots.GetSlotIdFromString( selections[i] );
189 EntityAI att = target_entity.GetInventory().FindAttachment(target_slot_id);
190
191 if ( att && player.GetInventory().CanAddEntityIntoHands(att) )
192 {
193 if ( att.CanDetachAttachment( target_entity ) && target_entity.CanReleaseAttachment( att ) )
194 return target_slot_id;
195 }
196 }
197 }
198 }
199 }
200 return InventorySlots.INVALID;
201 }
202}
203
204
205class ActionDetachFromTarget_SpecificSlot_WoodenLogs: ActionDetachFromTarget_SpecificSlot
206{
209 m_slotToDetach = "truck_01_woodenlogs";
210 }
211}
212
213class ActionDetachFromTarget_SpecificSlot_WoodenPlanks: ActionDetachFromTarget_SpecificSlot
214{
216 {
217 m_slotToDetach = "truck_01_woodenplanks";
218 }
219}
220
221class ActionDetachFromTarget_SpecificSlot_MetalSheets: ActionDetachFromTarget_SpecificSlot
222{
225 m_slotToDetach = "truck_01_metalsheets";
226 }
227}
228
236
238{
241 m_slotsToDetach = "truck_01_woodencrate";
242 }
243}
ActionBase ActionData
Definition actionbase.c:30
ActionDetachFromTarget_SpecificSlot_WoodenPlanks ActionDetachFromTarget_SpecificSlot ActionDetachFromTarget_SpecificSlot_MetalSheets()
string m_slotsToDetach
ActionDetachFromTarget_SpecificSlotsCategory_Barrel ActionDetachFromTarget_SpecificSlotsCategory ActionDetachFromTarget_SpecificSlotsCategory_WoodenCrate()
override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
ActionDetachFromTarget_SpecificSlotsCategory ActionDetachFromTarget ActionDetachFromTarget_SpecificSlot_WoodenLogs()
ActionDetachFromTarget m_slotToDetach
class ActionTargets ActionTarget
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)
void ClearActionJuncture(ActionData action_data)
override int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
int FindSlotIdToDetach(PlayerBase player, ActionTarget target, ItemBase item)
override ActionData CreateActionData()
override void CreateConditionComponents()
override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
override void OnExecute(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=NULL)
void Process(ActionData action_data)
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
const int INVALID
Invalid slot (-1).
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
void Process()