Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionattach.c
Go to the documentation of this file.
2 {
3  int m_AttSlot;
4 }
5 
6 
8 {
9  void ActionAttach()
10  {
11  m_Text = "#attach";
12  }
13 
14  override void CreateConditionComponents()
15  {
18  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_ATTACHITEM;
19  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
20  }
21 
23  {
24  AttachActionData action_data = new AttachActionData();
25  return action_data;
26  }
27 
28  override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
29  {
31  if (!GetGame().IsDedicatedServer())
32  {
33  EntityAI targetEntity;
34  if (target.IsProxy())
35  {
36  targetEntity = EntityAI.Cast(target.GetParent());
37  }
38  else
39  {
40  targetEntity = EntityAI.Cast(target.GetObject());
41  }
42 
43  if (!targetEntity.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, il))
44  return false;
45  }
46 
47  if (super.SetupAction(player, target, item, action_data, extra_data))
48  {
49  #ifndef SERVER
50  AttachActionData action_data_a = AttachActionData.Cast(action_data);
51  action_data_a.m_AttSlot = il.GetSlot();
52  #endif
53 
54  return true;
55  }
56 
57  return false;
58  }
59 
60 
61  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
62  {
63  EntityAI targetEntity = EntityAI.Cast(target.GetObject());
64  if (targetEntity && item)
65  {
66  return targetEntity.GetInventory() && targetEntity.GetInventory().CanAddAttachment(item) && !targetEntity.CanUseConstruction());
67  }
68 
69  return false;
70  }
71 
72  override void OnExecuteServer(ActionData action_data)
73  {
74  if (GetGame().IsMultiplayer())
75  return;
76 
77  ClearInventoryReservationEx(action_data);
78  AttachActionData action_data_a = AttachActionData.Cast(action_data);
79  AttachItem(action_data_a);
80  }
81 
82  override void OnExecuteClient(ActionData action_data)
83  {
84  ClearInventoryReservationEx(action_data);
85 
86  AttachActionData action_data_a = AttachActionData.Cast(action_data);
87  AttachItem(action_data_a);
88  }
89 
90  protected void AttachItem(AttachActionData action_data)
91  {
92  EntityAI entity;
93  if (action_data.m_Target.IsProxy())
94  {
95  entity = EntityAI.Cast(action_data.m_Target.GetParent());
96  }
97  else
98  {
99  entity = EntityAI.Cast(action_data.m_Target.GetObject());
100  }
101 
102  if (entity && action_data.m_MainItem)
103  {
104  action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data.m_MainItem, action_data.m_AttSlot);
105  }
106  }
107 
108  override bool CanBeSetFromInventory()
109  {
110  return false;
111  }
112 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ActionCondition
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition: actionattach.c:61
AttachActionData
Definition: actionattach.c:1
CanBeSetFromInventory
override bool CanBeSetFromInventory()
Definition: actionattach.c:108
UAMaxDistances
Definition: actionconstants.c:104
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
ActionAttach
AttachActionData ActionData ActionAttach()
Definition: actionattach.c:9
OnExecuteServer
override void OnExecuteServer(ActionData action_data)
Definition: actionattach.c:72
OnExecuteClient
override void OnExecuteClient(ActionData action_data)
Definition: actionattach.c:82
SetupAction
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=null)
Definition: actionattach.c:28
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
CCTNonRuined
Definition: cctnonruined.c:1
AttachItem
protected void AttachItem(AttachActionData action_data)
Definition: actionattach.c:90
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
m_Text
protected string m_Text
Definition: actionbase.c:49
ActionSingleUseBase
Definition: actionsingleusebase.c:41
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
CreateActionData
override ActionData CreateActionData()
Definition: actionattach.c:22
CreateConditionComponents
override void CreateConditionComponents()
Definition: actionattach.c:14
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5