Thanks for sharing your profile, I thought I would use this instead of opening a whole new topic but I am trying to play a sound file if frequency entrance is successful, and another if it failed. I want to do this in inline script since it gives the best result. The trouble is, so far I have been unable to do this. Here is the full script I am using
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Media;
public class VAInline
{
public void main()
{
try
{
string inputRaw = VA.GetText("DestinationAirport")?.Trim().ToLower();
if (string.IsNullOrEmpty(inputRaw))
{
VA.WriteToLog("No airport name or ID provided.", "red");
return;
}
var airportFrequencies = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "a44", "121000" }, { "anapa", "121000" },
{ "a76", "131000" }, { "batumi", "131000" },
{ "b52", "136500" }, { "beslan", "136500" },
{ "f66", "125000" }, { "gelendzhik", "125000" },
{ "f95", "129000" }, { "gudauta", "129000" },
{ "g99", "133000" }, { "kobuleti", "133000" },
{ "k50", "127000" }, { "krasnodar center", "127000" },
{ "k80", "118500" }, { "krasnodar pashkovsky", "118500" },
{ "k71", "131500" }, { "krymsk", "131500" },
{ "k95", "134000" }, { "kutaisi", "134000" },
{ "k73", "126000" }, { "maykop", "126000" },
{ "l72", "130000" }, { "mineralnye vody", "130000" },
{ "m79", "127500" }, { "mozdok", "127500" },
{ "n11", "122500" }, { "nalchik", "122500" },
{ "q79", "130500" }, { "novorossiysk", "130500" },
{ "r10", "132000" }, { "senaki", "132000" },
{ "s96", "130000" }, { "soganlug", "130000" },
{ "s03", "121500" }, { "sochi", "121500" },
{ "ta1", "128000" }, { "sukhumi", "128000" },
{ "t71", "132000" }, { "tbilisi", "132000" },
};
if (!airportFrequencies.TryGetValue(inputRaw, out string frequency))
{
VA.WriteToLog("Unknown airport or ID: " + inputRaw, "red");
return;
}
frequency = frequency.Replace(".", "").PadRight(6, '0');
using (UdpClient client = new UdpClient())
{
client.Connect("127.0.0.1", 7778);
SendCOMM1Selector(client);
Thread.Sleep(500);
SendUDPCommand(client, "UFC_CLR", 300);
foreach (char digit in frequency)
{
SendUDPCommand(client, $"UFC_{digit}", 150);
}
SendUDPCommand(client, "UFC_ENT", 500);
}
VA.WriteToLog($"Switched to {inputRaw.ToUpper()} → {frequency}", "green");
// Play confirmation sound
try
{
string soundPath = @"C:\DCS\VoiceSounds\success.wav";
if (System.IO.File.Exists(soundPath))
{
SoundPlayer player = new SoundPlayer(soundPath);
player.Play();
}
else
{
VA.WriteToLog("Sound file not found: " + soundPath, "orange");
}
}
catch (Exception se)
{
VA.WriteToLog("Sound error: " + se.Message, "orange");
}
}
catch (Exception e)
{
VA.WriteToLog("Error: " + e.Message, "red");
}
}
private void SendCOMM1Selector(UdpClient client)
{
client.Send(Encoding.ASCII.GetBytes("UFC_COMM1_PULL INC\n"), "UFC_COMM1_PULL INC\n".Length);
Thread.Sleep(300);
client.Send(Encoding.ASCII.GetBytes("UFC_COMM1_PULL DEC\n"), "UFC_COMM1_PULL DEC\n".Length);
Thread.Sleep(300);
}
private void SendUDPCommand(UdpClient client, string command, int delayMs)
{
client.Send(Encoding.ASCII.GetBytes($"{command} INC\n"), $"{command} INC\n".Length);
Thread.Sleep(75);
client.Send(Encoding.ASCII.GetBytes($"{command} DEC\n"), $"{command} DEC\n".Length);
Thread.Sleep(delayMs);
}
}
and these are the errors I am getting
78: CS1069: The type name 'SoundPlayer' could not be found in the namespace 'System.Media'. This type has been forwarded to assembly 'System.Windows.Extensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.
78: CS1069: The type name 'SoundPlayer' could not be found in the namespace 'System.Media'. This type has been forwarded to assembly 'System.Windows.Extensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.