DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionTakeHybridAttachment.c
Go to the documentation of this file.
1
3{
4 string m_ItemName = "";
5
7 {
8 m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_INVENTORY;
9 m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_INVENTORY;
10 m_Text = "#take";
11 }
12
14 {
17 }
18
19 override bool HasProneException()
20 {
21 return true;
22 }
23
24 override bool ActionConditionContinue( ActionData action_data )
25 {
26 return true;
27 }
28
29 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
30 {
31 EntityAI tgt_entity = EntityAI.Cast( target.GetObject() );
32
33 if ( tgt_entity && BaseBuildingBase.Cast(tgt_entity) &&!tgt_entity.IsBeingPlaced() )
34 {
35 string component_name = tgt_entity.GetActionComponentName( target.GetComponentIndex() );
36
37 /*if (!tgt_entity.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString(component_name)))
38 return false;*/
39
40 ItemBase attachment = ItemBase.Cast(tgt_entity.FindAttachmentBySlotName(component_name));
41
42 if ( attachment && player.GetInventory().CanAddEntityIntoInventory(attachment) && attachment.IsTakeable() )
43 {
44 return true;
45 }
46 }
47 return false;
48 }
49
50 override bool CanBeUsedOnBack()
51 {
52 return true;
53 }
54
55 override bool InventoryReservation(ActionData action_data)
56 {
57 bool success = true;
58
60
61 EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
62 string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
63 ItemBase attachment;
64
65 if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
66 {
67 action_data.m_Player.GetInventory().FindFreeLocationFor( attachment , FindInventoryLocationType.ANY, il );
68 if ( action_data.m_Player.GetInventory().HasInventoryReservation( attachment, il) )
69 {
70 success = false;
71 }
72 else
73 {
74 action_data.m_Player.GetInventory().AddInventoryReservationEx( attachment, il, GameInventory.c_InventoryReservationTimeoutMS);
75 }
76 }
77
78 if ( success )
79 {
80 if( il )
81 action_data.m_ReservedInventoryLocations.Insert(il);
82 }
83
84 return success;
85 }
86
87 override void OnExecuteServer( ActionData action_data )
88 {
89 if (GetGame().IsMultiplayer())
90 return;
91
92 //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
93 EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
94 string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
95 ItemBase attachment;
96
97 if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
98 {
99 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
100 InventoryLocation targetInventoryLocation = new InventoryLocation;
101 attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
102 ClearInventoryReservationEx(action_data);
103 //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
104
105 float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
106
107 if( stackable == 0 || stackable >= attachment.GetQuantity() )
108 {
109 action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
110 }
111 else
112 {
113 attachment.SplitIntoStackMaxToInventoryLocationClient( il );
114 }
115 }
116 //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
117 }
118
119 override void OnExecuteClient( ActionData action_data )
120 {
121 //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
122 EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
123 string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
124 ItemBase attachment;
125
126 if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
127 {
128 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
129 InventoryLocation targetInventoryLocation = new InventoryLocation;
130 attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
131 ClearInventoryReservationEx(action_data);
132 //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
133 //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
134 float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
135
136 if( stackable == 0 || stackable >= attachment.GetQuantity() )
137 {
138 action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
139 }
140 else
141 {
142 attachment.SplitIntoStackMaxToInventoryLocationClient( il );
143 }
144 }
145 }
146};
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:861
protected string m_Text
Definition ActionBase.c:49
class ActionTargets ActionTarget
FindInventoryLocationType
flags for searching locations in inventory
PlayerBase m_Player
Definition ActionBase.c:33
ref array< ref InventoryLocation > m_ReservedInventoryLocations
Definition ActionBase.c:35
ref ActionTarget m_Target
Definition ActionBase.c:32
override bool ActionConditionContinue(ActionData action_data)
override void OnExecuteServer(ActionData action_data)
override bool InventoryReservation(ActionData action_data)
override void OnExecuteClient(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
protected int m_CommandUIDProne
script counterpart to engine's class Inventory
Definition Inventory.c:77
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:683
InventoryLocation.
proto native int GetSlot()
returns slot id if current type is Attachment
override bool IsTakeable()
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
proto native CGame GetGame()