Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
actionattachonselection.c
Go to the documentation of this file.
1
class
ActionAttachOnSelection
:
ActionSingleUseBase
2
{
3
void
ActionAttachOnSelection
()
4
{
5
m_Text
=
"#attach"
;
6
}
7
8
override
void
CreateConditionComponents
()
9
{
10
m_ConditionItem
=
new
CCINonRuined
();
11
m_ConditionTarget
=
new
CCTCursor
();
12
}
13
14
override
ActionData
CreateActionData
()
15
{
16
AttachActionData
action_data =
new
AttachActionData
();
17
return
action_data;
18
}
19
20
int
FindSlotIdToAttachOrCombine
(
PlayerBase
player,
ActionTarget
target,
ItemBase
item)
21
{
22
EntityAI
targetEntity =
EntityAI
.Cast(target.GetObject());
23
if
(targetEntity && item)
24
{
25
GameInventory
inv = targetEntity.GetInventory();
26
if
(!inv)
27
return
InventorySlots
.
INVALID
;
28
29
int
slotsCount = item.GetInventory().GetSlotIdCount();
30
array<string>
selections =
new
array<string>
();
31
targetEntity.GetActionComponentNameList(target.GetComponentIndex(), selections);
32
33
foreach
(
string
selection : selections)
34
{
35
int
slotId = -1;
36
if
(!targetEntity.TranslateSlotFromSelection(selection, slotId))
37
slotId =
InventorySlots
.
GetSlotIdFromString
(selection);
38
39
if
(slotId == -1)
40
continue
;
41
42
for
(
int
i=0; i < slotsCount; ++i)
43
{
44
int
itemSlotId = item.GetInventory().GetSlotId(i);
45
if
(slotId == itemSlotId)
46
{
47
ItemBase
currentAttachment =
ItemBase
.Cast(inv.
FindAttachment
(slotId));
48
if
(currentAttachment)
49
{
50
if
(currentAttachment.
CanBeCombined
(item))
51
return
itemSlotId;
52
}
53
else
54
{
55
if
(inv.
CanAddAttachment
(item))
56
return
itemSlotId;
57
}
58
}
59
}
60
}
61
}
62
63
return
InventorySlots
.
INVALID
;
64
}
65
66
67
override
bool
SetupAction
(
PlayerBase
player,
ActionTarget
target,
ItemBase
item, out
ActionData
action_data,
Param
extra_data = null)
68
{
69
int
attSlotId =
InventorySlots
.
INVALID
;
70
if
(!
g_Game
.IsDedicatedServer() )
71
{
72
attSlotId =
FindSlotIdToAttachOrCombine
(player, target, item);
73
}
74
75
if
(super.SetupAction( player, target, item, action_data, extra_data))
76
{
77
if
(!
g_Game
.IsDedicatedServer())
78
{
79
if
(attSlotId !=
InventorySlots
.
INVALID
)
80
{
81
AttachActionData
action_data_a =
AttachActionData
.Cast(action_data);
82
action_data_a.
m_AttSlot
= attSlotId;
83
84
return
true
;
85
}
86
87
return
false
;
88
}
89
90
return
true
;
91
}
92
93
return
false
;
94
}
95
96
override
bool
ActionCondition
(
PlayerBase
player,
ActionTarget
target,
ItemBase
item)
97
{
98
if
(
g_Game
.IsMultiplayer() &&
g_Game
.IsServer())
99
return
true
;
100
101
if
(target.GetObject() && target.GetObject().CanUseConstruction())
102
return
false
;
103
104
return
FindSlotIdToAttachOrCombine
(player, target, item) !=
InventorySlots
.
INVALID
;
105
}
106
107
override
void
OnExecuteServer
(
ActionData
action_data )
108
{
109
if
(
g_Game
.IsMultiplayer())
110
return
;
111
112
ClearInventoryReservationEx
(action_data);
113
114
AttachActionData
action_data_a =
AttachActionData
.Cast(action_data);
115
EntityAI
entity;
116
117
if
(action_data.m_Target.IsProxy())
118
{
119
entity =
EntityAI
.Cast(action_data.m_Target.GetParent());
120
}
121
else
122
{
123
entity =
EntityAI
.Cast(action_data.m_Target.GetObject());
124
}
125
126
if
(entity && action_data.m_MainItem)
127
{
128
action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(entity, action_data_a.m_MainItem, action_data_a.
m_AttSlot
);
129
}
130
}
131
132
override
void
OnExecuteClient
(
ActionData
action_data)
133
{
134
ClearInventoryReservationEx
(action_data);
135
EntityAI
targetEntity =
EntityAI
.Cast(action_data.m_Target.GetObject());
136
EntityAI
itemEntity = action_data.m_MainItem;
137
138
AttachActionData
action_data_a =
AttachActionData
.Cast(action_data);
139
140
ItemBase
attachment =
ItemBase
.Cast(targetEntity.GetInventory().FindAttachment(action_data_a.
m_AttSlot
));
141
if
(attachment)
142
{
143
attachment.CombineItemsClient(itemEntity);
144
}
145
else
146
{
147
ItemBase
item_base =
ItemBase
.Cast( itemEntity );
148
float
stackable = item_base.GetTargetQuantityMax( action_data_a.
m_AttSlot
);
149
150
if
(stackable == 0 || stackable >= item_base.GetQuantity())
151
{
152
action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx(targetEntity, itemEntity, action_data_a.
m_AttSlot
);
153
}
154
else
if
(stackable != 0 && stackable < item_base.GetQuantity())
155
{
156
item_base.SplitIntoStackMaxClient(targetEntity, action_data_a.
m_AttSlot
);
157
}
158
}
159
}
160
}
ActionData
ActionBase ActionData
Definition
actionbase.c:30
ActionTarget
class ActionTargets ActionTarget
ActionAttachOnSelection::FindSlotIdToAttachOrCombine
int FindSlotIdToAttachOrCombine(PlayerBase player, ActionTarget target, ItemBase item)
Definition
actionattachonselection.c:20
ActionAttachOnSelection::OnExecuteServer
override void OnExecuteServer(ActionData action_data)
Definition
actionattachonselection.c:107
ActionAttachOnSelection::CreateActionData
override ActionData CreateActionData()
Definition
actionattachonselection.c:14
ActionAttachOnSelection::ActionAttachOnSelection
void ActionAttachOnSelection()
Definition
actionattachonselection.c:3
ActionAttachOnSelection::CreateConditionComponents
override void CreateConditionComponents()
Definition
actionattachonselection.c:8
ActionAttachOnSelection::SetupAction
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=null)
Definition
actionattachonselection.c:67
ActionAttachOnSelection::OnExecuteClient
override void OnExecuteClient(ActionData action_data)
Definition
actionattachonselection.c:132
ActionAttachOnSelection::ActionCondition
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition
actionattachonselection.c:96
ActionBase::m_Text
string m_Text
Definition
actionbase.c:64
ActionBase::m_ConditionItem
ref CCIBase m_ConditionItem
Definition
actionbase.c:70
ActionBase::m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition
actionbase.c:71
ActionBase::ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition
actionbase.c:1040
ActionSingleUseBase::ActionSingleUseBase
void ActionSingleUseBase()
Definition
actionsingleusebase.c:31
AttachActionData
Definition
actionattach.c:2
AttachActionData::m_AttSlot
int m_AttSlot
Definition
actionattach.c:3
CCINonRuined
Definition
ccinonruined.c:2
CCTCursor
Definition
cctcursor.c:2
EntityAI
Definition
inventoryitem.c:2
GameInventory
script counterpart to engine's class Inventory
Definition
inventory.c:81
GameInventory::CanAddAttachment
proto native bool CanAddAttachment(notnull EntityAI e)
GameInventory::FindAttachment
proto native EntityAI FindAttachment(int slot)
Returns attached entity in slot (you can use InventorySlots.GetSlotIdFromString(name) to get slot id)...
InventorySlots
provides access to slot configuration
Definition
inventoryslots.c:6
InventorySlots::GetSlotIdFromString
static proto native int GetSlotIdFromString(string slot_name)
InventorySlots::INVALID
const int INVALID
Invalid slot (-1).
Definition
inventoryslots.c:17
ItemBase
Definition
inventoryitem.c:742
ItemBase::CanBeCombined
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition
rag.c:61
Param
Base Param Class with no parameters.
Definition
param.c:12
PlayerBase
Definition
playerbaseclient.c:2
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
Games
Dayz
scripts
4_world
classes
useractionscomponent
actions
singleuse
actionattachonselection.c
Generated by
1.17.0