Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
attachmentsoutofreach.c
Go to the documentation of this file.
1
class
AttachmentsOutOfReach
2
{
3
protected
static
ref
map<string, ref map<int, vector>
>
m_AttData
;
4
5
static
bool
IsAttachmentReachable
(
EntityAI
e,
string
att_slot_name =
""
,
int
slot_id = -1,
float
range = 1.5)
6
{
7
if
( !e.IgnoreOutOfReachCondition() )
8
{
9
PlayerBase
player =
PlayerBase
.Cast(
g_Game
.GetPlayer() );
10
if
( player.IsInVehicle() )
11
{
12
return
false
;
13
}
14
else
15
{
16
17
vector
pos_att;
18
if
( slot_id != -1 )
19
{
20
att_slot_name =
InventorySlots
.
GetSlotName
(slot_id);
21
}
22
if
( att_slot_name !=
""
)
23
{
24
if
( e.MemoryPointExists(att_slot_name) )
25
{
26
vector
mem_point = e.GetMemoryPointPos(att_slot_name);
27
pos_att = e.ModelToWorld(mem_point);
28
}
29
else
30
{
31
pos_att = e.ModelToWorld(
GetAttachmentPosition
(e,
InventorySlots
.
GetSlotIdFromString
( att_slot_name ) ));
32
}
33
34
}
35
36
vector
pos_player = player.GetPosition();
37
38
float
height_diff =
Math
.
AbsFloat
( pos_player[1] - pos_att[1] );
39
if
( height_diff < range )
40
{
41
pos_player[1] = 0;
42
pos_att[1] = 0;
43
if
(
vector
.
Distance
(pos_player, pos_att) <= range )
44
{
45
return
true
;
46
}
47
return
false
;
48
}
49
else
50
{
51
return
false
;
52
}
53
}
54
}
55
else
56
{
57
return
true
;
58
}
59
}
60
61
static
vector
GetAttachmentPosition
(
EntityAI
e,
int
slot_id)
62
{
63
if
(
m_AttData
== NULL )
64
{
65
m_AttData
=
new
map<string, ref map<int, vector>
>();
66
}
67
68
string
type_name = e.GetType();
69
70
if
( !
m_AttData
.Contains( type_name ) )
71
{
72
map<int, vector>
att =
CreateAttachmentPosition
( e );
73
74
m_AttData
.Insert( type_name, att );
75
}
76
77
return
m_AttData
.Get( type_name ).Get( slot_id );
78
}
79
80
static
protected
map<int, vector>
CreateAttachmentPosition
(
EntityAI
entity )
81
{
82
map<int, vector>
ret_val =
new
map<int, vector>
();
83
84
string
type_name = entity.GetType();
85
TStringArray
cfg_attachments =
new
TStringArray
;
86
87
string
cfg_path;
88
89
if
(
g_Game
.ConfigIsExisting(
CFG_VEHICLESPATH
+
" "
+type_name) )
90
{
91
cfg_path =
CFG_VEHICLESPATH
+
" "
+type_name+
" attachments"
;
92
}
93
else
if
(
g_Game
.ConfigIsExisting(
CFG_WEAPONSPATH
+
" "
+type_name) )
94
{
95
cfg_path =
CFG_WEAPONSPATH
+
" "
+type_name+
" attachments"
;
96
}
97
else
if
(
g_Game
.ConfigIsExisting(
CFG_MAGAZINESPATH
+
" "
+type_name) )
98
{
99
cfg_path =
CFG_MAGAZINESPATH
+
" "
+type_name+
" attachments"
;
100
}
101
102
g_Game
.ConfigGetTextArray(cfg_path, cfg_attachments);
103
104
int
child_count =
g_Game
.ConfigGetChildrenCount(
"CfgNonAIVehicles"
);
105
106
for
(
int
x
= 0;
x
< child_count; ++
x
)
107
{
108
string
child_name;
109
g_Game
.ConfigGetChildName(
"CfgNonAIVehicles"
,
x
, child_name);
110
111
string
inventory_slot_name;
112
g_Game
.ConfigGetText(
"CfgNonAIVehicles "
+ child_name +
" inventorySlot"
, inventory_slot_name);
113
114
if
( cfg_attachments.Find( inventory_slot_name ) > 0 )
115
{
116
string
model_path;
117
g_Game
.ConfigGetText(
"CfgNonAIVehicles "
+ child_name +
" model"
, model_path);
118
119
if
( model_path.
Length
() > 5 )
120
{
121
LOD
lod = entity.GetLODByName(
LOD
.
NAME_VIEW
);
122
123
if
( lod )
124
{
125
model_path = model_path.
Substring
(0, model_path.
Length
() - 4);
126
model_path.
ToLower
();
127
128
array<Selection>
selections =
new
array<Selection>
();
129
lod.
GetSelections
(selections);
130
131
for
(
int
i = 0; i < selections.Count(); ++i )
132
{
133
string
selection = selections[i].GetName();
134
selection.
ToLower
();
135
136
if
( selection.
Contains
(model_path) )
137
{
138
ret_val.Set(
InventorySlots
.
GetSlotIdFromString
( inventory_slot_name ), selections[i].GetVertexPosition(lod, 0));
139
}
140
}
141
}
142
}
143
}
144
}
145
146
return
ret_val;
147
}
148
}
AttachmentsOutOfReach
Definition
attachmentsoutofreach.c:2
AttachmentsOutOfReach::GetAttachmentPosition
static vector GetAttachmentPosition(EntityAI e, int slot_id)
Definition
attachmentsoutofreach.c:61
AttachmentsOutOfReach::m_AttData
static ref map< string, ref map< int, vector > > m_AttData
Definition
attachmentsoutofreach.c:3
AttachmentsOutOfReach::IsAttachmentReachable
static bool IsAttachmentReachable(EntityAI e, string att_slot_name="", int slot_id=-1, float range=1.5)
Definition
attachmentsoutofreach.c:5
AttachmentsOutOfReach::CreateAttachmentPosition
map< int, vector > CreateAttachmentPosition(EntityAI entity)
Definition
attachmentsoutofreach.c:80
EntityAI
Definition
inventoryitem.c:2
InventorySlots
provides access to slot configuration
Definition
inventoryslots.c:6
InventorySlots::GetSlotName
static proto native owned string GetSlotName(int id)
InventorySlots::GetSlotIdFromString
static proto native int GetSlotIdFromString(string slot_name)
LOD
LOD class.
Definition
gameplay.c:204
LOD::GetSelections
proto native bool GetSelections(notnull out array< Selection > selections)
LOD::NAME_VIEW
static const string NAME_VIEW
Definition
gameplay.c:207
Math
Definition
enmath.c:7
PlayerBase
Definition
playerbaseclient.c:2
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
map
Definition
cachedequipmentstorage.c:4
vector
Definition
enconvert.c:119
vector::Distance
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
TStringArray
array< string > TStringArray
Definition
enscript.c:712
Math::AbsFloat
static proto float AbsFloat(float f)
Returns absolute value.
CFG_VEHICLESPATH
const string CFG_VEHICLESPATH
Definition
constants.c:220
CFG_WEAPONSPATH
const string CFG_WEAPONSPATH
Definition
constants.c:221
CFG_MAGAZINESPATH
const string CFG_MAGAZINESPATH
Definition
constants.c:222
string::Substring
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
string::Contains
bool Contains(string sample)
Returns true if sample is substring of string.
Definition
enstring.c:286
string::ToLower
proto int ToLower()
Changes string to lowercase.
string::Length
proto native int Length()
Returns length of string.
x
Icon x
Games
Dayz
scripts
4_world
systems
inventory
attachmentsoutofreach.c
Generated by
1.17.0