DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionTakeArrow.c
Go to the documentation of this file.
1/*class TakeArrowActionReciveData : ActionReciveData
2{
3 EntityAI m_Arrow;
4}
5
6class TakeArrowActionData : ActionData
7{
8 EntityAI m_Arrow;
9}*/
10
12{
14 {
15 m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
16 m_Text = "#take";
17 }
18
20 {
23 }
24
25 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
26 {
27 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
28 if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
29 return false;
30
31 ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
32 if (arrowManager)
33 {
34 ItemBase arrow = ItemBase.Cast(arrowManager.GetFirstArrow());
35 if (arrow)
36 {
37 if (player.GetInventory().CanAddEntityIntoInventory(arrow))
38 return true;
39 }
40 }
41
42 return false;
43 }
44
46 {
47 EntityAI targetEntity = EntityAI.Cast(target.GetObject());
48 if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
49 return null;
50
51 ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
52 if (arrowManager)
53 {
54 return arrowManager.GetFirstArrow();
55 }
56
57 return null;
58 }
59
60 override bool CanBeUsedOnBack()
61 {
62 return false;
63 }
64
65 override bool InventoryReservation(ActionData action_data)
66 {
67 bool success = true;
68
70
71 EntityAI targetEntity;
72 if (EntityAI.CastTo(targetEntity, action_data.m_Target.GetObject()))
73 {
74 ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
75 if (arrowManager)
76 {
77 ItemBase targetArrow = ItemBase.Cast(arrowManager.GetFirstArrow());
78 if (targetArrow)
79 {
80 action_data.m_Player.GetInventory().FindFreeLocationFor(targetArrow , FindInventoryLocationType.ANY, il);
81 if (action_data.m_Player.GetInventory().HasInventoryReservation(targetArrow, il))
82 {
83 success = false;
84 }
85 else
86 {
87 action_data.m_Player.GetInventory().AddInventoryReservationEx(targetArrow, il, GameInventory.c_InventoryReservationTimeoutMS);
88 }
89 }
90 }
91 }
92
93 if (success)
94 {
95 if (il)
96 action_data.m_ReservedInventoryLocations.Insert(il);
97 }
98
99 return success;
100 }
101
102 /*override ActionData CreateActionData()
103 {
104 ActionData action_data = new TakeArrowActionData;
105 return action_data;
106 }
107
108 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
109 {
110 super.WriteToContext(ctx, action_data);
111 TakeArrowActionData ad = TakeArrowActionData.Cast(action_data);
112 ctx.Write(ad.m_Arrow);
113 }
114
115 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
116 {
117 if (!action_recive_data)
118 {
119 action_recive_data = new TakeArrowActionReciveData;
120 }
121
122 if (!super.ReadFromContext( ctx, action_recive_data ))
123 return false;
124
125 TakeArrowActionReciveData recive_data_ta = TakeArrowActionReciveData.Cast( action_recive_data );
126
127 if (!ctx.Read(recive_data_ta.m_Arrow))
128 return false;
129
130 return true;
131 }
132
133 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
134 {
135 super.HandleReciveData(action_recive_data, action_data);
136
137 TakeArrowActionReciveData recive_data_ta = TakeArrowActionReciveData.Cast(action_recive_data);
138 TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
139
140 action_data_ta.m_Arrow = recive_data_ta.m_Arrow;
141 }*/
142
143 override void OnExecuteClient(ActionData action_data)
144 {
145
146 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
147
148 ItemBase arrow = ItemBase.Cast(il.GetItem());
149 InventoryLocation arrowInventoryLocation = new InventoryLocation;
150 arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
151
152 float stackable = arrow.GetTargetQuantityMax(il.GetSlot());
153
154 if ( stackable == 0 || stackable >= arrow.GetQuantity() )
155 {
156 action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
157 }
158 else
159 {
160 arrow.SplitIntoStackMaxToInventoryLocationClient( il );
161 }
162 }
163
164 /*override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
165 {
166 if (super.SetupAction(player, target, item, action_data, extra_data))
167 {
168 #ifndef SERVER
169 TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
170 InventoryLocation il = action_data_ta.m_ReservedInventoryLocations.Get(0);
171 action_data_ta.m_Arrow = il.GetItem();
172 #endif
173
174 return true;
175 }
176
177 return false;
178 }*/
179
180 /*override void OnStartServer(ActionData action_data)
181 {
182 TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
183 action_data.m_Target.GetObject().RemoveChild(action_data_ta.m_Arrow);
184 }*/
185
186 override void OnExecuteServer(ActionData action_data)
187 {
188 //TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
189 //action_data.m_Target.GetObject().RemoveChild(action_data_ta.m_Arrow);
190
191 if (GetGame().IsMultiplayer())
192 return;
193
194 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
195 ItemBase arrow = ItemBase.Cast(il.GetItem());
196 InventoryLocation arrowInventoryLocation = new InventoryLocation;
197 arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
198
199 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
200 if (targetEntity)
201 {
202 targetEntity.RemoveChild(arrow);
203 }
204
205 //float ammoMax = arrow.GetAmmoMax();
206
207 //if ( stackable == 0 || ammoMax >= arrow.GetAmmoCount() )
208 //{
209 action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
210 /*}
211 else
212 {
213 arrow.SplitIntoStackMaxToInventoryLocationClient( il );
214 }*/
215 }
216}
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
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 CanBeUsedOnBack()
override void OnExecuteServer(ActionData action_data)
override void CreateConditionComponents()
override bool InventoryReservation(ActionData action_data)
override void OnExecuteClient(ActionData action_data)
override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
EntityAI GetFirstArrow()
script counterpart to engine's class Inventory
Definition Inventory.c:77
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:683
InventoryLocation.
proto native EntityAI GetItem()
returns item of current inventory location
proto native int GetSlot()
returns slot id if current type is Attachment
const float DEFAULT
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
proto native CGame GetGame()