DayZ 1.24
Loading...
Searching...
No Matches
ActionAttachToConstruction.c
Go to the documentation of this file.
2{
4 {
5 m_Text = "#attach";
6 }
7
13
19
20 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
21 {
22 EntityAI target_entity = EntityAI.Cast(target.GetObject());
23
24 if (target_entity && target_entity.CanUseConstruction())
25 {
26 string selection = target_entity.GetActionComponentName(target.GetComponentIndex());
27 ConstructionActionData construction_action_data = player.GetConstructionActionData();
28 int slot_id = construction_action_data.GetAttachmentSlotFromSelection(player, target_entity, item, selection);
30
31 if (slot_id != -1)
32 {
34 if (base_building.CheckSlotVerticalDistance(slot_id, player) && base_building.IsPlayerInside(player, ""))
35 {
37
38 return true;
39 }
40 }
41 else if (item.IsKindOf("CombinationLock"))
42 {
44
45 //simpler hack
46 /*construction_action_data.SetSlotId( InventorySlots.GetSlotIdFromString("Att_CombinationLock") );
47 return true;*/
48
50 bool found = base_building.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, loc);
51
52 if (found)
53 {
54 //Print("slot name: " + InventorySlots.GetSlotName(loc.GetSlot()) );
55 construction_action_data.SetSlotId(loc.GetSlot());
56
57 return true;
58 }
59 }
60 }
61
62 return false;
63 }
64
66 {
67 //set action initiator
68 ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
69 construction_action_data.SetActionInitiator(action_data.m_Player);
70 }
71
73 {
74 EntityAI target_entity = EntityAI.Cast(action_data.m_Target.GetObject());
75 ItemBase item = ItemBase.Cast(action_data.m_MainItem);
76
77 ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
78 int slot_id = construction_action_data.GetSlotId();
79
80 if (slot_id != -1)
81 {
82 ItemBase attachment = ItemBase.Cast(target_entity.GetInventory().FindAttachment(slot_id));
83
84 if (attachment)
85 {
86 //combine
87 attachment.CombineItemsClient(item);
88 }
89 else// if( target_entity.GetInventory().CanAddAttachmentEx( item, slot_id ) )
90 {
92 float stackable = item_base.GetTargetQuantityMax(slot_id);
93
94 if (stackable == 0 || stackable >= item_base.GetQuantity())
95 action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(target_entity, item, slot_id);
96 else if (stackable != 0 && stackable < item_base.GetQuantity())
97 item_base.SplitIntoStackMaxClient(target_entity, slot_id);
98 }
99 }
100 }
101
107
109 {
110 if (!GetGame().IsMultiplayer())
111 {
113
114 OnExecuteImpl(action_data); // single player
115 }
116 }
117}
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:790
FindInventoryLocationType
flags for searching locations in inventory
override void OnStartClient(ActionData action_data)
void OnExecuteImpl(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override void OnExecuteServer(ActionData action_data)
override void OnExecuteClient(ActionData action_data)
InventoryLocation.
proto native CGame GetGame()