Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
plugininventoryrepair.c
Go to the documentation of this file.
1// *************************************************************************************
2// ! PluginInventoryRepair
3// *************************************************************************************
4class PluginInventoryRepair extends PluginBase
5{
6 protected static float PIR_REQUEST_COOLDOWN = 5;
7 protected static float PIR_MAX_ITEMS_TO_SEND = 5;
8
11 protected float m_TimeFromLastRequest = 0;
12
18
19 bool RepairItem(EntityAI itemToRepair)
20 {
21 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
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
41 {
42 int itemCount;
43
44 if (!ctx.Read(itemCount))
45 return;
46
47 for (int i = 0; i < itemCount; i++)
48 {
50 if (!il.ReadFromContext(ctx) )
51 return;
52
53 m_CorrectILs.Insert(il);
54 }
55 }
56
58 {
59 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
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 {
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>;
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
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}
represents base for cargo storage for entities
Definition cargo.c:7
proto native int GetItemCount()
proto native EntityAI GetItem(int index)
script counterpart to engine's class Inventory
Definition inventory.c:81
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
static void SendClientInventoryCheck(array< EntityAI > items)
InventoryLocation.
proto native int GetSlot()
returns slot id if current type is Attachment
proto native EntityAI GetParent()
returns parent of current inventory location
proto native int GetType()
returns type of InventoryLocation
proto native bool CollidesWith(notnull InventoryLocation rhs)
bool ReadFromContext(ParamsReadContext ctx)
proto native EntityAI GetItem()
returns item of current inventory location
proto native void SetTemporary(notnull EntityAI parent, EntityAI e)
Class PluginMessageManager provides some basic Message Distribution mechanics, if you get instance of...
Definition pluginbase.c:2
ref array< EntityAI > m_ItemsToRepair
static float PIR_REQUEST_COOLDOWN
ref array< ref InventoryLocation > m_CorrectILs
void Add(EntityAI item)
bool RepairItem(EntityAI itemToRepair)
bool MoveItemToCorrectPosition(InventoryLocation ilCorrect)
void Remove(EntityAI item)
void OnRPC(ParamsReadContext ctx)
static float PIR_MAX_ITEMS_TO_SEND
override void OnUpdate(float delta_time)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
Serializer ParamsReadContext
Definition gameplay.c:15
InventoryLocationType
types of Inventory Location