Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
plugininventoryrepair.c
Go to the documentation of this file.
1
// *************************************************************************************
2
// ! PluginInventoryRepair
3
// *************************************************************************************
4
class
PluginInventoryRepair
extends
PluginBase
5
{
6
protected
static
float
PIR_REQUEST_COOLDOWN
= 5;
7
protected
static
float
PIR_MAX_ITEMS_TO_SEND
= 5;
8
9
protected
ref
array<EntityAI>
m_ItemsToRepair
;
10
protected
ref
array<ref InventoryLocation>
m_CorrectILs
;
11
protected
float
m_TimeFromLastRequest
= 0;
12
13
void
PluginInventoryRepair
()
14
{
15
m_ItemsToRepair
=
new
array<EntityAI>
();
16
m_CorrectILs
=
new
array<ref InventoryLocation>
();
17
}
18
19
bool
RepairItem
(
EntityAI
itemToRepair)
20
{
21
PlayerBase
player =
PlayerBase
.Cast(
g_Game
.GetPlayer());
22
InventoryLocation
repairIl =
new
InventoryLocation
;
23
InventoryLocation
currentIl =
new
InventoryLocation
;
24
25
repairIl.
SetTemporary
(player, itemToRepair);
26
itemToRepair.GetInventory().GetCurrentInventoryLocation(currentIl);
27
28
if
(
GameInventory
.
LocationSyncMoveEntity
(currentIl, repairIl))
29
{
30
if
(currentIl.
GetType
() ==
InventoryLocationType
.HANDS)
31
{
32
player.OnItemInHandsChanged();
33
}
34
return
true
;
35
}
36
return
false
;
37
}
38
39
//Receive from server
40
void
OnRPC
(
ParamsReadContext
ctx)
41
{
42
int
itemCount;
43
44
if
(!ctx.
Read
(itemCount))
45
return
;
46
47
for
(
int
i = 0; i < itemCount; i++)
48
{
49
InventoryLocation
il =
new
InventoryLocation
();
50
if
(!il.
ReadFromContext
(ctx) )
51
return
;
52
53
m_CorrectILs
.Insert(il);
54
}
55
}
56
57
bool
MoveItemToCorrectPosition
(
InventoryLocation
ilCorrect)
58
{
59
PlayerBase
player =
PlayerBase
.Cast(
g_Game
.GetPlayer());
60
InventoryLocation
ilTemp =
new
InventoryLocation
;
61
62
EntityAI
item = ilCorrect.
GetItem
();
63
EntityAI
parent = ilCorrect.
GetParent
();
64
item.GetInventory().GetCurrentInventoryLocation(ilTemp);
65
66
switch
(ilCorrect.
GetType
())
67
{
68
case
InventoryLocationType
.CARGO:
69
InventoryLocation
ilCargoItem =
new
InventoryLocation
;
70
CargoBase
cargo = parent.GetInventory().GetCargo();
71
for
(
int
i = cargo.
GetItemCount
() - 1; i >= 0 ; --i)
72
{
73
EntityAI
itemInCargo = cargo.
GetItem
(i);
74
if
(itemInCargo != item)
75
{
76
itemInCargo.GetInventory().GetCurrentInventoryLocation(ilCargoItem);
77
if
(ilCorrect.
CollidesWith
(ilCargoItem))
78
{
79
if
(!
RepairItem
(itemInCargo))
80
{
81
return
false
;
82
}
83
}
84
}
85
}
86
break
;
87
case
InventoryLocationType
.ATTACHMENT:
88
EntityAI
entityInAttachment = parent.GetInventory().FindAttachment(ilCorrect.
GetSlot
());
89
90
if
(entityInAttachment)
91
{
92
if
(!
RepairItem
(entityInAttachment))
93
{
94
return
false
;
95
}
96
}
97
98
break
;
99
case
InventoryLocationType
.HANDS:
100
EntityAI
entityInHands = player.GetItemInHands();
101
if
(entityInHands)
102
{
103
if
(!
RepairItem
(entityInHands))
104
{
105
return
false
;
106
}
107
}
108
109
break
;
110
default
:
111
break
;
112
}
113
114
if
(!
GameInventory
.
LocationSyncMoveEntity
(ilTemp, ilCorrect))
115
{
116
if
(ilTemp.
GetType
() !=
InventoryLocationType
.TEMP)
117
RepairItem
(item);
118
return
false
;
119
}
120
121
return
true
;
122
}
123
124
override
void
OnUpdate
(
float
delta_time)
125
{
126
if
(
m_CorrectILs
.Count())
127
{
128
for
(
int
j =
m_CorrectILs
.Count() - 1; j >= 0 ; j--)
129
{
130
if
(
MoveItemToCorrectPosition
(
m_CorrectILs
[j]))
131
m_CorrectILs
.Remove(j);
132
}
133
}
134
135
m_TimeFromLastRequest
+= delta_time;
136
if
(
m_ItemsToRepair
.Count())
137
{
138
array<EntityAI>
itemsToSend =
new
array<EntityAI>
;
139
if
(
m_TimeFromLastRequest
>
PIR_REQUEST_COOLDOWN
)
140
{
141
for
(
int
i = 0; i <
m_ItemsToRepair
.Count() && i <
PIR_MAX_ITEMS_TO_SEND
; i++ )
142
{
143
itemsToSend.Insert(
m_ItemsToRepair
[i]);
144
}
145
146
InventoryInputUserData
.
SendClientInventoryCheck
(itemsToSend);
147
m_TimeFromLastRequest
= 0;
148
}
149
}
150
}
151
152
void
Remove
(
EntityAI
item)
153
{
154
m_ItemsToRepair
.RemoveItem(item);
155
}
156
157
void
Add
(
EntityAI
item)
158
{
159
if
(
m_ItemsToRepair
.Find(item) < 0)
160
{
161
m_ItemsToRepair
.Insert(item);
162
}
163
}
164
}
CargoBase
represents base for cargo storage for entities
Definition
cargo.c:7
CargoBase::GetItemCount
proto native int GetItemCount()
CargoBase::GetItem
proto native EntityAI GetItem(int index)
EntityAI
Definition
inventoryitem.c:2
GameInventory
script counterpart to engine's class Inventory
Definition
inventory.c:81
GameInventory::LocationSyncMoveEntity
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
InventoryInputUserData
Definition
inventoryinputuserdata.c:3
InventoryInputUserData::SendClientInventoryCheck
static void SendClientInventoryCheck(array< EntityAI > items)
Definition
inventoryinputuserdata.c:31
InventoryLocation
InventoryLocation.
Definition
inventorylocation.c:30
InventoryLocation::GetSlot
proto native int GetSlot()
returns slot id if current type is Attachment
InventoryLocation::GetParent
proto native EntityAI GetParent()
returns parent of current inventory location
InventoryLocation::GetType
proto native int GetType()
returns type of InventoryLocation
InventoryLocation::CollidesWith
proto native bool CollidesWith(notnull InventoryLocation rhs)
InventoryLocation::ReadFromContext
bool ReadFromContext(ParamsReadContext ctx)
Definition
inventorylocation.c:310
InventoryLocation::GetItem
proto native EntityAI GetItem()
returns item of current inventory location
InventoryLocation::SetTemporary
proto native void SetTemporary(notnull EntityAI parent, EntityAI e)
PlayerBase
Definition
playerbaseclient.c:2
PluginBase
Class PluginMessageManager provides some basic Message Distribution mechanics, if you get instance of...
Definition
pluginbase.c:2
PluginBase::m_ItemsToRepair
ref array< EntityAI > m_ItemsToRepair
Definition
plugininventoryrepair.c:9
PluginBase::PluginInventoryRepair
void PluginInventoryRepair()
Definition
plugininventoryrepair.c:13
PluginBase::PIR_REQUEST_COOLDOWN
static float PIR_REQUEST_COOLDOWN
Definition
plugininventoryrepair.c:6
PluginBase::m_CorrectILs
ref array< ref InventoryLocation > m_CorrectILs
Definition
plugininventoryrepair.c:10
PluginBase::Add
void Add(EntityAI item)
Definition
plugininventoryrepair.c:157
PluginBase::RepairItem
bool RepairItem(EntityAI itemToRepair)
Definition
plugininventoryrepair.c:19
PluginBase::MoveItemToCorrectPosition
bool MoveItemToCorrectPosition(InventoryLocation ilCorrect)
Definition
plugininventoryrepair.c:57
PluginBase::Remove
void Remove(EntityAI item)
Definition
plugininventoryrepair.c:152
PluginBase::OnRPC
void OnRPC(ParamsReadContext ctx)
Definition
plugininventoryrepair.c:40
PluginBase::PIR_MAX_ITEMS_TO_SEND
static float PIR_MAX_ITEMS_TO_SEND
Definition
plugininventoryrepair.c:7
PluginBase::OnUpdate
override void OnUpdate(float delta_time)
Definition
plugininventoryrepair.c:124
PluginBase::m_TimeFromLastRequest
float m_TimeFromLastRequest
Definition
plugininventoryrepair.c:11
Serializer::Read
proto bool Read(void value_in)
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
ParamsReadContext
Serializer ParamsReadContext
Definition
gameplay.c:15
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition
inventorylocation.c:4
Games
Dayz
scripts
4_world
plugins
pluginbase
plugininventoryrepair.c
Generated by
1.17.0