Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
quantityconversions.c
Go to the documentation of this file.
1
class
QuantityConversions
2
{
3
static
string
GetItemQuantityText
(
EntityAI
item,
bool
showMax =
false
)
4
{
5
string
quantity_text =
""
;
6
if
( item.IsInherited(
InventoryItem
) )
7
{
8
ItemBase
item_base;
9
Class
.
CastTo
(item_base, item);
10
float
quantity = item_base.GetQuantity();
11
int
ammo;
12
if
( item.IsMagazine() )
13
{
14
Magazine magazine_item;
15
Class
.
CastTo
(magazine_item, item);
16
ammo = magazine_item.GetAmmoCount();
17
18
return
ammo.ToString();
19
}
20
else
if
( item.IsInherited( ItemBook) )
21
{
22
return
""
;
23
}
24
int
stack_max = item.GetQuantityMax();
25
26
//int max = item.ConfigGetInt("varQuantityMax");
27
//string unit = item.ConfigGetString("stackedUnit");
28
29
if
(stack_max > 0)
30
{
31
if
(stack_max == 1)
32
{
33
if
(quantity > 1)
34
{
35
if
(showMax)
36
quantity_text =
string
.
Format
(
"%1/%2"
, quantity.
ToString
(), stack_max.ToString() );
37
//quantity_text = string.Format("%i/%i", quantity, stack_max );
38
else
39
quantity_text = quantity.
ToString
();
40
}
41
else
42
{
43
quantity_text =
""
;
44
}
45
}
46
else
47
{
48
if
(showMax)
49
quantity_text =
string
.
Format
(
"%1/%2"
, quantity.
ToString
(), stack_max.ToString() );
50
//quantity_text = string.Format("%i/%i", quantity, stack_max );
51
else
52
quantity_text = quantity.
ToString
();
53
// if (unit == "ml")
54
// {
55
// float liters = round(quantity / 1000.0);
56
// if ( quantity < 2000 )
57
// {
58
// liters = ( round( (quantity / 100.0) ) ) / 10;
59
// }
60
// quantity_text = ftoa(liters) + "l";
61
// }
62
// else
63
// {
64
// quantity_text = itoa(quantity) + unit;
65
// }
66
}
67
}
68
}
69
return
quantity_text;
70
}
71
72
static
float
GetItemQuantity
(
InventoryItem
item)
73
{
74
float
quantity = 0;
75
if
( item.IsInherited(
InventoryItem
))
76
{
77
ItemBase
item_base;
78
Class
.
CastTo
(item_base, item);
79
if
(item_base)
80
{
81
if
(item.IsMagazine())
82
{
83
Magazine magazine_item;
84
Class
.
CastTo
(magazine_item, item);
85
quantity = magazine_item.GetAmmoCount();
86
}
87
else
88
{
89
quantity = item_base.GetQuantity();
90
}
91
}
92
}
93
return
quantity;
94
}
95
96
static
float
GetItemQuantityMax
(
InventoryItem
item)
97
{
98
float
quantity = 0;
99
if
(item.IsInherited(
InventoryItem
))
100
{
101
ItemBase
item_base;
102
Class
.
CastTo
(item_base, item);
103
if
(item_base)
104
{
105
if
(item.IsMagazine())
106
{
107
Magazine magazine_item;
108
Class
.
CastTo
(magazine_item, item);
109
quantity = magazine_item.GetAmmoMax();
110
}
111
else
112
{
113
quantity = item_base.GetQuantityMax();
114
}
115
}
116
}
117
return
quantity;
118
}
119
120
static
void
GetItemQuantity
(
InventoryItem
item, out
float
q_cur, out
float
q_min, out
float
q_max )
121
{
122
if
( item.IsInherited(
InventoryItem
) )
123
{
124
ItemBase
item_base;
125
Class
.
CastTo
(item_base, item);
126
if
( item.IsMagazine() )
127
{
128
Magazine magazine_item;
129
Class
.
CastTo
(magazine_item, item);
130
q_cur = magazine_item.GetAmmoCount();
131
q_min = 0;
132
q_max = magazine_item.GetAmmoMax();
133
}
134
else
135
{
136
q_cur = item_base.GetQuantity();
137
q_min = item_base.GetQuantityMin();
138
q_max = item_base.GetQuantityMax();
139
}
140
}
141
}
142
143
static
int
HasItemQuantity
( notnull
EntityAI
item )
144
{
145
ItemBase
ib;
146
if
(
Class
.
CastTo
(ib, item) )
147
{
148
if
( item.IsMagazine() )
149
return
QUANTITY_COUNT
;
150
151
if
( !ib.m_CanShowQuantity )
152
return
QUANTITY_HIDDEN
;
153
154
int
max = item.GetQuantityMax();
155
if
( max > 0 )
156
{
157
if
( ib.m_HasQuantityBar )
158
{
159
return
QUANTITY_PROGRESS
;
160
}
161
else
162
{
163
if
(max == 1)
164
{
165
return
QUANTITY_HIDDEN
;
166
}
167
else
168
{
169
return
QUANTITY_COUNT
;
170
}
171
}
172
}
173
}
174
return
QUANTITY_HIDDEN
;
175
}
176
}
Class
Super root of all classes in Enforce script.
Definition
enscript.c:11
EntityAI
Definition
inventoryitem.c:2
InventoryItem
Definition
itembase.c:21
ItemBase
Definition
inventoryitem.c:742
QuantityConversions
Definition
quantityconversions.c:2
QuantityConversions::GetItemQuantityMax
static float GetItemQuantityMax(InventoryItem item)
Definition
quantityconversions.c:96
QuantityConversions::GetItemQuantityText
static string GetItemQuantityText(EntityAI item, bool showMax=false)
Definition
quantityconversions.c:3
QuantityConversions::HasItemQuantity
static int HasItemQuantity(notnull EntityAI item)
Definition
quantityconversions.c:143
QuantityConversions::GetItemQuantity
static float GetItemQuantity(InventoryItem item)
Definition
quantityconversions.c:72
QuantityConversions::GetItemQuantity
static void GetItemQuantity(InventoryItem item, out float q_cur, out float q_min, out float q_max)
Definition
quantityconversions.c:120
float::ToString
proto string ToString(bool simple=true)
QUANTITY_PROGRESS
const int QUANTITY_PROGRESS
Definition
constants.c:521
QUANTITY_COUNT
const int QUANTITY_COUNT
Definition
constants.c:520
QUANTITY_HIDDEN
const int QUANTITY_HIDDEN
Definition
constants.c:519
Class::CastTo
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
string::Format
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
Games
Dayz
scripts
4_world
static
quantityconversions.c
Generated by
1.17.0