DayZ 1.24
Loading...
Searching...
No Matches
AreaDamageComponentRaycasted.c
Go to the documentation of this file.
1
2class AreaDamageComponentRaycasted : AreaDamageComponent
3{
4 // Defined in local space of the trigger
7
10
11 void AreaDamageComponentRaycasted(AreaDamageManager parent)
12 {
14 m_RaycastEndOffset = "0 0.5 0";
15
18 }
19
20 override void OnTriggerCreated()
21 {
22 super.OnTriggerCreated();
23
24 ClearCache();
25 }
26
28 {
29 m_RaycastSources.Clear();
30
31 // convert Array of string to array of Vectors
32 int nrOfSources = raycast_sources.Count();
33 for (int v = 0; v < nrOfSources; ++v)
34 m_RaycastSources.Insert(raycast_sources[v].ToVector());
35 }
36
41
43 {
45 }
46
48 {
49 super.OnStayFinishServerEvent();
50
51 ClearCache();
52 }
53
55 {
57 data.Hitzone = GetRaycastedHitZone(object);
58
59 return data;
60 }
61
62 protected void ClearCache()
63 {
64 m_RaycastCache.Clear();
66 }
67
69 {
71 for (int c = 0; c < nrOfCachedResults; ++c)
72 {
74 if (cachedRes.obj == victim)
75 return victim.GetDamageZoneNameByComponentIndex(cachedRes.component);
76 }
77
78 int nrOfSources = m_RaycastSources.Count();
80
81 string hitzone = "";
82
84
87 params.flags = CollisionFlags.ONLYDYNAMIC;
88
89 for (int i = m_RaycastCachedIndex + 1; i < nrOfSources; ++i)
90 {
92
93 params.begPos = trigger.ModelToWorld(m_RaycastSources[i]);
94 params.endPos = params.begPos + m_RaycastEndOffset;
95
97 {
98 for (int j = 0; j < victims.Count(); ++j)
99 {
101
102 if (res.obj == victim)
103 hitzone = victim.GetDamageZoneNameByComponentIndex(res.component);
104
105 if (res.obj.IsAnyInherited(m_DamageableTypes))
106 m_RaycastCache.Insert(res);
107 }
108
109 if (!(hitzone == ""))
110 return hitzone;
111
112 victims.Clear();
113 }
114 }
115
117 }
118
120 {
121 Error(string.Format("[WARNING] :: [%1] :: [AreaDamageComponentRaycasted] :: No proper HitZone found for damaging %2, using fallback.",
122 m_Parent, Object.GetDebugName(victim)));
123
124 // Fallbacks, currently are implemented assuming that foot/leg damagezones would be desired to damage
125 if (victim.IsInherited(DayZPlayer) || victim.IsInherited(DayZInfected))
126 {
127 // Damage random leg since we don't know what part of player's body was caught in the trap.
128 if (Math.RandomIntInclusive(0, 1) == 1)
129 return "RightFoot";
130 return "LeftFoot";
131 }
132 else
133 {
135 victim.GetDamageZones(damageZones);
136
137 int nrOfDmgZones = damageZones.Count();
138
139 if (nrOfDmgZones > 0)
140 {
141 for (int z = 0; z < nrOfDmgZones; ++z)
142 {
143 if (damageZones[z].Contains("Foot") || damageZones[z].Contains("Leg"))
144 return damageZones[z];
145 }
146
147 return damageZones.GetRandomElement();
148 }
149 else
150 return "";
151 }
152 }
153}
Widget m_Parent
Definition SizeToChild.c:86
Newer implementation equivalent of "AreaDamageRegularRaycasted", hitzone selection only.
AreaDamageComponentData GetAreaDamageComponentData(Object object)
void SetRaycastSourcesVector(array< vector > raycast_sources)
void AreaDamageComponentRaycasted(AreaDamageManager parent)
ref array< ref RaycastRVResult > m_RaycastCache
void SetRaycastSources(array< string > raycast_sources)
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
Definition EnMath.c:7
static const vector Zero
Definition EnConvert.c:110
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
CollisionFlags
Definition EnDebug.c:141
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54