DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
InventoryItem.c
Go to the documentation of this file.
1class InventoryItem extends EntityAI
2{
3 static private const float SOUND_CONTACT_SKIP = 0.33;//second
4
5#ifdef DIAG_DEVELOPER
6 static private ref array<ref string> s_ImpactSoundsInfo = new array<ref string>();
7#endif
8
11 private bool m_IsMeleeWeapon = false;
12
14
16 proto native void SwitchOn(bool onOff);
18 proto native bool IsOn();
19
21 proto native void EnableCollisionsWithCharacter(bool state);
22 proto native bool HasCollisionsWithCharacter();
23
25
26 proto native void ThrowPhysically(DayZPlayer player, vector force, bool collideWithCharacters = true);
27
29 // This method performs an OR operation with the config 'forceFarBubble'. If set in the config
30 // this method has no effect.
31 proto native void ForceFarBubble(bool state);
32
34 {
35 InitImpactSoundData();
36
37 if (ConfigIsExisting("isMeleeWeapon"))
38 m_IsMeleeWeapon = ConfigGetBool("isMeleeWeapon");
39 }
40
41
43 {
44
45 }
46
47 event bool OnUseFromInventory(Man owner)
48 {
49 return false;
50 }
51
53 string GetTooltip()
54 {
55 string temp;
56 if (!DescriptionOverride(temp))
57 temp = ConfigGetString("descriptionShort");
58 return temp;
59 }
60
61 override bool IsInventoryItem()
62 {
63 return true;
64 }
65
67 {
68 return 0;
69 }
70
72 {
73 return 1;
74 }
75
77 {
78 return 2;
79 }
80
81 override bool IsMeleeWeapon()
82 {
83 return m_IsMeleeWeapon;
84 }
85
87 {
88 return false;
89 }
90
91 // -------------------------------------------------------------------------------
92 void PlayImpactSound(float weight, float velocity, int surfaceHash)
93 {
94 if (!m_SoundImpactTable)
95 return;
96
97 SoundObjectBuilder soundBuilder = m_SoundImpactTable.GetSoundBuilder(surfaceHash);
98 if (soundBuilder != null)
99 {
100 soundBuilder.SetVariable("weight", weight);
101 soundBuilder.SetVariable("speed", velocity);
103
104 SoundObject soundObject = soundBuilder.BuildSoundObject();
105 if (soundObject != null)
106 {
107 soundObject.SetKind(WaveKind.WAVEEFFECTEX);
108 PlaySound(soundObject, soundBuilder);
109 }
110 }
111 }
112
113 // -------------------------------------------------------------------------------
114 protected void InitImpactSoundData()
115 {
116 #ifndef SERVER
117 string soundImpactType = "default";
118 if ( ConfigIsExisting("soundImpactType") )
119 soundImpactType = ConfigGetString("soundImpactType");
120
121 m_SoundImpactTable = AnimSoundLookupTableBank.GetInstance().GetImpactTable(soundImpactType + "_Impact_LookupTable");
122 #endif
123 }
124
125 // -------------------------------------------------------------------------------
127 {
128 if (so == null)
129 return null;
130
132 AbstractWave wave = GetGame().GetSoundScene().Play3D(so, sob);
133
134 return wave;
135 }
136
137 // -------------------------------------------------------------------------------
139 {
140 AnimSoundEvent soundEvent = GetInventoryItemType().GetSoundEvent(id);
141 if (soundEvent)
142 {
143 SoundObjectBuilder builder = soundEvent.GetSoundBuilder();
144 SoundObject soundObject = builder.BuildSoundObject();
145 if (soundObject)
146 PlaySound(soundObject, builder);
147 }
148 }
149
150
151 // -------------------------------------------------------------------------------
153 {
154 string surface;
155 int liquid = -1;
156 return GetImpactSurfaceTypeEx(other, impact, liquid);
157 }
158
159 // -------------------------------------------------------------------------------
160 string GetImpactSurfaceTypeEx(IEntity other, Contact impact, out int liquid)
161 {
162 vector mins, maxs;
163 GetWorldBounds(mins, maxs);
164 vector size = maxs - mins;
165
166 vector add = impact.RelativeVelocityBefore.Normalized() * size.Length();
167 string surfaceImpact;
169 Object.Cast(other),
170 impact.Position + add,
171 impact.Position - add,
172 surfaceImpact))
173 {
174 return surfaceImpact;
175 }
176 string surface;
177 GetGame().SurfaceUnderObjectEx(this, surface, surfaceImpact, liquid);
178 return surfaceImpact;
179 }
180
183 {
184 return "MeleeSoft";
185 }
186
187 // -------------------------------------------------------------------------------
188 float ProcessImpactSound(IEntity other, Contact extra, float weight, out int surfaceHash)
189 {
190 int liquidType = -1;
191 return ProcessImpactSoundEx(other, extra, weight, surfaceHash,liquidType);
192 }
193
194
195 // -------------------------------------------------------------------------------
196 float ProcessImpactSoundEx(IEntity other, Contact extra, float weight, out int surfaceHash, out int liquidType)
197 {
198 float impactVelocity = extra.RelativeVelocityBefore.Length();
199 if ( impactVelocity < 0.3 )
200 return 0.0;
201
202 float tickTime = GetGame().GetTickTime();
203 if ( m_SoundContactTickTime + SOUND_CONTACT_SKIP > tickTime )
204 return 0.0;
205
206 string surfaceName = GetImpactSurfaceTypeEx(other, extra, liquidType);
207 if ( surfaceName == "" )
208 return 0.0;
209
210#ifdef DIAG_DEVELOPER
211 string infoText = "Surface: " + surfaceName + ", Weight: " + weight + ", Speed: " + impactVelocity;
212
213 if ( s_ImpactSoundsInfo.Count() == 10 )
214 s_ImpactSoundsInfo.Remove(9);
215
216 s_ImpactSoundsInfo.InsertAt(infoText, 0);
217#endif
218
219 m_SoundContactTickTime = tickTime;
220
221 surfaceHash = surfaceName.Hash();
222 return impactVelocity;
223 }
224
225#ifdef DIAG_DEVELOPER
226 static void DrawImpacts()
227 {
228 DbgUI.Begin("Item impact sounds", 10, 200);
229
230 for ( int i = 0; i < s_ImpactSoundsInfo.Count(); ++i )
231 {
232 string line = (i + 1).ToString() + ". " + s_ImpactSoundsInfo.Get(i);
233 DbgUI.Text(line);
234 }
235
236 DbgUI.End();
237 }
238#endif
239};
class AnimSoundObjectBuilderBank AnimSoundLookupTableBank()
EAnimSoundEventID
proto string ToString()
void PlaySound()
WaveKind
Definition Sound.c:2
class SoundObjectBuilder SoundObject(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
proto void SetPosition(vector position)
static AnimSoundObjectBuilderBank GetInstance()
proto void SurfaceUnderObjectEx(notnull Object object, out string type, out string impact, out int liquidType)
proto native AbstractSoundScene GetSoundScene()
proto native float GetTickTime()
Returns current time from start of the game.
static proto bool GetHitSurface(Object other, vector begPos, vector endPos, string surface)
Definition DbgUI.c:60
private float m_SoundContactTickTime
protected void InitImpactSoundData()
private SoundLookupTable m_SoundImpactTable
int GetMeleeMode()
bool IsMeleeFinisher()
AbstractWave PlaySound(SoundObject so, SoundObjectBuilder sob)
proto native bool HasCollisionsWithCharacter()
override bool IsMeleeWeapon()
float ProcessImpactSoundEx(IEntity other, Contact extra, float weight, out int surfaceHash, out int liquidType)
proto native void EnableCollisionsWithCharacter(bool state)
collisions with character
int GetMeleeHeavyMode()
proto native void ForceFarBubble(bool state)
Sets the item to use the server configured 'networkRangeFar' instead of 'networkRangeNear'.
proto native void ThrowPhysically(DayZPlayer player, vector force, bool collideWithCharacters=true)
event bool OnUseFromInventory(Man owner)
override bool IsInventoryItem()
string GetImpactSurfaceTypeEx(IEntity other, Contact impact, out int liquid)
void PlayImpactSound(float weight, float velocity, int surfaceHash)
int GetMeleeSprintMode()
void OnRightClick()
string GetImpactSurfaceType(IEntity other, Contact impact)
float ProcessImpactSound(IEntity other, Contact extra, float weight, out int surfaceHash)
void InventoryItem()
string GetTooltip()
Get tooltip text.
proto native bool IsOn()
Some inventoryItem devices can be switched on/off (radios, transmitters)
void PlaySoundByAnimEvent(EAnimSoundEventID id)
proto native MeleeCombatData GetMeleeCombatData()
string GetRuinedMeleeAmmoType()
returns ammo (projectile) used in melee if the item is destroyed. Override higher for specific use
proto native InventoryItemType GetInventoryItemType()
proto native void SwitchOn(bool onOff)
Some inventoryItem devices can be switched on/off (radios, transmitters)
SoundObjectBuilder GetSoundBuilder(int parameterHash)
proto native void SetVariable(string name, float value)
proto native void UpdateEnvSoundControllers(vector position)
SoundObject BuildSoundObject()
Definition Sound.c:49
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto vector Normalized()
return normalized vector (keeps orginal vector untouched)
proto native float Length()
Returns length of vector (magnitude)
proto native CGame GetGame()
vector Position
Definition EnPhysics.c:319
vector RelativeVelocityBefore
Definition EnPhysics.c:320
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto native void End()
string Get(int index)
Gets n-th character from string.
Definition EnString.c:434
proto native int Hash()
Returns hash of string.