DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
DamageSystem.c
Go to the documentation of this file.
3 proto native float GetDamage(string zoneName, string healthType);
4 proto native float GetHighestDamage(string healthType);
5};
6
7//-----------------------------------------------------------------------------
8
11{
12 CLOSE_COMBAT, // 0
13 FIRE_ARM, // 1
15 STUN,
16 CUSTOM
17}
18
19//-----------------------------------------------------------------------------
20class DamageSystem
21{
22 static proto native void CloseCombatDamage(EntityAI source, Object targetObject, int targetComponentIndex, string ammoTypeName, vector worldPos, int directDamageFlags = ProcessDirectDamageFlags.ALL_TRANSFER);
23 static proto native void CloseCombatDamageName(EntityAI source, Object targetObject, string targetComponentName, string ammoTypeName, vector worldPos, int directDamageFlags = ProcessDirectDamageFlags.ALL_TRANSFER);
24
25 static proto native void ExplosionDamage(EntityAI source, Object directHitObject, string ammoTypeName, vector worldPos, int damageType);
26
27 static bool GetDamageZoneMap(EntityAI entity, out DamageZoneMap zoneMap)
28 {
29 string path_base;
30 string path;
31
32 if (entity.IsWeapon())
33 {
34 path_base = CFG_WEAPONSPATH;
35 }
36 else if (entity.IsMagazine())
37 {
38 path_base = CFG_MAGAZINESPATH;
39 }
40 else
41 {
42 path_base = CFG_VEHICLESPATH;
43 }
44
45 path_base = string.Format("%1 %2 DamageSystem DamageZones", path_base, entity.GetType());
46
47 if (!GetGame().ConfigIsExisting(path_base))
48 {
49 return false;
50 }
51 else
52 {
53 string zone;
54 array<string> zone_names = new array<string>;
55 array<string> component_names;
56
57 entity.GetDamageZones(zone_names);
58 for (int i = 0; i < zone_names.Count(); i++)
59 {
60 component_names = new array<string>;
61 zone = zone_names.Get(i);
62
63 path = string.Format("%1 %2 componentNames ", path_base, zone);
64 if (GetGame().ConfigIsExisting(path))
65 {
66 GetGame().ConfigGetTextArray(path,component_names);
67 }
68 zoneMap.Insert(zone,component_names);
69 }
70
71 return true;
72 }
73 }
74
76 static bool GetDamageZoneFromComponentName(notnull EntityAI entity, string component, out string damageZone)
77 {
78 DamageZoneMap zoneMap = entity.GetEntityDamageZoneMap();
79 array<array<string>> components;
80 components = zoneMap.GetValueArray();
81 for (int i = 0; i < components.Count(); i++)
82 {
83 array<string> inner = components.Get(i);
84 for (int j = 0; j < inner.Count(); j++)
85 {
86 string innerComponentName = inner.Get(j);
87 innerComponentName.ToLower();
88
89 //We don't have a component name, no need to proceed
90 if ( innerComponentName == "" )
91 break;
92
93 if (innerComponentName == component)
94 {
95 damageZone = zoneMap.GetKey(i);
96 return true;
97 }
98 }
99 }
100 damageZone = "";
101 return false;
102 }
103
104 static bool GetComponentNamesFromDamageZone(notnull EntityAI entity, string damageZone, out array<string> componentNames)
105 {
106 string path;
107
108 if (entity.IsWeapon())
109 {
111 }
112 else if (entity.IsMagazine())
113 {
115 }
116 else
117 {
119 }
120
121 path = string.Format("%1 %2 DamageSystem DamageZones %3 componentNames", path, entity.GetType(), damageZone);
122 if (GetGame().ConfigIsExisting(path))
123 {
124 GetGame().ConfigGetTextArray(path,componentNames);
125 return true;
126 }
127
128 return false;
129 }
130
131 static string GetDamageDisplayName(EntityAI entity, string zone)
132 {
133 string component_name;
134 entity.GetEntityDamageDisplayNameMap().Find(zone.Hash(), component_name);
135 component_name = Widget.TranslateString(component_name);
136 return component_name;
137 }
138}
139
140typedef map<string,ref array<string>> DamageZoneMap; //<zone_name,<components>>
static string GetDamageDisplayName(EntityAI entity, string zone)
FIRE_ARM
Definition DamageSystem.c:1
static proto native void CloseCombatDamageName(EntityAI source, Object targetObject, string targetComponentName, string ammoTypeName, vector worldPos, int directDamageFlags=ProcessDirectDamageFlags.ALL_TRANSFER)
EXPLOSION
Definition DamageSystem.c:2
static bool GetDamageZoneMap(EntityAI entity, out DamageZoneMap zoneMap)
enum DamageType CloseCombatDamage(EntityAI source, Object targetObject, int targetComponentIndex, string ammoTypeName, vector worldPos, int directDamageFlags=ProcessDirectDamageFlags.ALL_TRANSFER)
static bool GetComponentNamesFromDamageZone(notnull EntityAI entity, string damageZone, out array< string > componentNames)
static proto native void ExplosionDamage(EntityAI source, Object directHitObject, string ammoTypeName, vector worldPos, int damageType)
static bool GetDamageZoneFromComponentName(notnull EntityAI entity, string component, out string damageZone)
Returns damage zone to which the named component belongs.
map< string, ref array< string > > DamageZoneMap
CLOSE_COMBAT
Definition DamageSystem.c:0
CUSTOM
Definition DamageSystem.c:5
STUN
Definition DamageSystem.c:3
DamageType
exposed from C++ (do not change)
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
ProcessDirectDamageFlags
Definition Object.c:2
proto native void ConfigGetTextArray(string path, out TStringArray values)
Get array of strings from config on path.
TODO doc.
Definition EnScript.c:118
proto native float GetDamage(string zoneName, string healthType)
proto native float GetHighestDamage(string healthType)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
const string CFG_VEHICLESPATH
Definition constants.c:195
const string CFG_WEAPONSPATH
Definition constants.c:196
const string CFG_MAGAZINESPATH
Definition constants.c:197
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.
proto native int Hash()
Returns hash of string.
proto int ToLower()
Changes string to lowercase. Returns length.