Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseAudioScriptedUserAction.c
Go to the documentation of this file.
3 {
4  [Attribute(desc: "Sound effect played when action is exectuted")]
5  protected string m_sActionSoundEffectEventName;
6 
7  [Attribute(desc: "File that contains the sound effect. Only used as backup if SFX was not played by the SoundComponent on the entity", params: "acp")]
8  protected ResourceName m_sActionSoundEffectFile;
9 
10  //================================================== PERFORM ==================================================\\
11  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
12  {
13  PlayActionSoundEffect(pOwnerEntity);
14  }
15 
16  //================================================== AUDIO ==================================================\\
17  protected void PlayActionSoundEffect(IEntity pOwnerEntity)
18  {
19  if (!pOwnerEntity)
20  return;
21 
22  if (SCR_StringHelper.IsEmptyOrWhiteSpace(m_sActionSoundEffectEventName))
23  return;
24 
25  //~ Get sound component
26  SoundComponent soundComponent = SoundComponent.Cast(pOwnerEntity.FindComponent(SoundComponent));
27 
28  //~ Has sound component. Play sound with that offset
29  if (soundComponent)
30  {
31  //~ Check if sound was played. If true simply play it and return
32  if (soundComponent.GetEventIndex(m_sActionSoundEffectEventName) > 0)
33  {
34  soundComponent.SoundEventOffset(m_sActionSoundEffectEventName, GetLocalPositionAction());
35  return;
36  }
37  else
38  {
39  Print(string.Format("'SCR_BaseAudioScriptedUserAction': Trying to play sound for '%1' but sound either sound event '%2' or more likely sound file needed is not included on the SoundComponent! SCR_SoundManagerEntity is used instead (if any in the world) but that means position of sound is not updated if entity moves while sound is playing.", pOwnerEntity, m_sActionSoundEffectEventName, m_sActionSoundEffectFile), LogLevel.WARNING);
40  }
41  }
42 
43  if (SCR_StringHelper.IsEmptyOrWhiteSpace(m_sActionSoundEffectFile))
44  return;
45 
46  //~ No sound manager
47  SCR_SoundManagerEntity soundManagerEntity = GetGame().GetSoundManagerEntity();
48  if (!soundManagerEntity)
49  return;
50 
51  vector transform[4];
52  vector mat[4];
53  pOwnerEntity.GetTransform(mat);
54  transform[3] = GetWorldPositionAction();
55 
56  //~ Create new config
57  SCR_AudioSourceConfiguration audioConfig = new SCR_AudioSourceConfiguration();
58  audioConfig.m_sSoundProject = m_sActionSoundEffectFile;
59  audioConfig.m_sSoundEventName = m_sActionSoundEffectEventName;
60  audioConfig.m_eFlags = SCR_Enum.RemoveFlag(audioConfig.m_eFlags, EAudioSourceConfigurationFlag.Static);
61 
62  //~ Play sound
63  soundManagerEntity.CreateAndPlayAudioSource(pOwnerEntity, audioConfig, transform);
64  }
65 };
SCR_Enum
Definition: SCR_Enum.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ScriptedUserAction
A scripted action class having optional logic to check if vehicle is valid.
Definition: SCR_ScriptedUserAction.c:2
EAudioSourceConfigurationFlag
EAudioSourceConfigurationFlag
Definition: SCR_AudioSourceConfiguration.c:1
SCR_StringHelper
Definition: SCR_StringHelper.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_SoundManagerEntity
Definition: SCR_SoundManagerEntity.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseAudioScriptedUserAction
A scripted action class having optional logic for playing audio as well as checking if the faction is...
Definition: SCR_BaseAudioScriptedUserAction.c:2
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24