EN UO Topic sound visual environment - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

Sound & Visual Environment

Home · C# · IDE · UO API · A–Z · Examples · Languages

Sounds, lighting, season and client weather effects.

Sections

Topic Commands and explanations
Sound UO.Sound
PlayWav UO.PlayWav
Light UO.Light
Season UO.SetSeason
Weather Filter UO.FilterWeather

All theme commands

Environment

UO.Sound · UO.PlayWav · UO.Alarm · UO.Light · UO.SetSeason · UO.FilterWeather · UO.TicksAnim

Examples on the topic

Each command card has several independent scenarios: direct code, functions and classes. Below are selected short scenarios; restrictions and full analysis are in the cards.

UO.PlayWav

Parameters, result and all scenarios

UO.Print(UO.PlayWav("alert.wav"));

UO.Light

Parameters, result and all scenarios

UO.Light();

Complete command reference


UO.Alarm

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

void UO.Alarm();

Prints the word Alarm to the local ClassicUO syslog. Use as a note about the occurrence of a condition in the script.

Parameters

There are no parameters.

Return value

void - no value. Execute on a separate line. This is not a bool or confirmation that the user saw the message.

Behavior

  • Only the form UO.Alarm() without parameters is registered. For your own text, use UO.Print(text).
  • The command does not play a sound, flash an icon, or activate a window. The message remains local: it is not sent to the game chat.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.

UO.Print("Calling UO.Alarm");
UO.Alarm();

1. Mark the journal - direct script

Parameters and execution flow:

  • There are no parameters; The word Alarm appears in the system log.
UO.Alarm();

2. Warn when health is low - script function

Parameters and execution flow:

  • Alarm does not have a text option. Life returns the number HP; Print adds a clear description of the reason.
return  RunScenario();
 object? RunScenario()
{
    if (Truth(UO.Life() < 30))
    {
        UO.Alarm();
        UO.Print("Health is below 30");
    }

    return null;
}

bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;

3. Mark Search Result - Script Class

Parameters and execution flow:

  • 0x0EED - gold type, -1 - any color, backpack - backpack. Alarm is called only when serial is found; Don't put such a call in a loop without delay.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        var item = UO.FindType(0x0EED, -1, "backpack");
        if (Truth(item != ""))
        {
            UO.Alarm();
            UO.Print("Gold stack found: " + Convert.ToString(item));
        }
        else
        {
            UO.Print("No gold stack in the loaded backpack");
        }

        return null;
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.Alarm() — UO.Alarm()

Parameters: No parameters.

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "alarm":

                    SystemMessage(arguments.Length > 0 ? Text(0) : "Alarm"); return InjectionValue.Unit;

UO.FilterWeather

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

void UO.FilterWeather();
void UO.FilterWeather(object? enabled);

Enables or disables the client weather filter.

Parameters

  • enabled — Optional value: without an argument, the filter is turned on; 0 turns off, non-zero int turns on.

Return value

void - no return value.

Behavior

  • Writes the normalized flag to the runtime state and passes it to the manager. The filter affects the client's processing; server events and other log settings remain separate.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.

UO.Print("Calling UO.FilterWeather");
UO.FilterWeather();

1. Enable without argument - direct script

Parameters and execution flow:

  • A zero number of arguments means include, not read.
UO.FilterWeather();

2. Turn off - script function

Parameters and execution flow:

  • An explicit 0 turns off the client filter.
return  RunScenario();
 object? RunScenario()
{
    UO.FilterWeather(0);
    return null;
}

3. Turn On and Then Turn Off - Script Class

Parameters and execution flow:

  • The filter turns on and clearly returns to the off state.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        UO.FilterWeather(1);
        UO.FilterWeather(0);
        return null;
    }
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.FilterWeather() — UO.FilterWeather()

Parameters: No parameters.

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "filterweather": state.WeatherFilter = arguments.Length == 0 || Arg(0) != 0 ? 1 : 0; bridge.SetWeatherFilter(state.WeatherFilter); break;

UO.FilterWeather(enabled) — UO.FilterWeather(Any)

Parameters: enabled (Any)

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "filterweather": state.WeatherFilter = arguments.Length == 0 || Arg(0) != 0 ? 1 : 0; bridge.SetWeatherFilter(state.WeatherFilter); break;

UO.Light

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

void UO.Light();
void UO.Light(object? value);

Locally sets the overall illumination of the client.

Parameters

  • value — Optional integer: 0..30, limited to this range. The no-argument form uses 0; This is a write, not a read.

Return value

void - no value. Call on a separate line; completion does not confirm the server's action.

Behavior

  • ExecuteLegacyManualAlias passes Arg(0), where the missing argument is 0. SetLight assigns Light.Overall and Light.RealOverall a limited byte value.
  • Does not change the illumination of other players and does not request it from the server. The following lighting server package can replace the value.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.

UO.Print("Calling UO.Light");
UO.Light();

1. Direct call - direct script

Parameters and execution flow:

  • Locally sets the overall illumination of the client.
UO.Light();

2. Explicit option - script function

Parameters and execution flow:

  • ExecuteLegacyManualAlias passes Arg(0), where the missing argument is 0. SetLight assigns Light.Overall and Light.RealOverall a limited byte value.
return  RunScenario();
 object? RunScenario()
{
    UO.Light(15);
    return null;
}

3. Full Helper Function - Script Class

Parameters and execution flow:

  • Does not change the illumination of other players and does not request it from the server. The following lighting server package can replace the value.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        UO.Light(99);
        UO.Print("Light clamped to 30");
        return null;
    }
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.Light() — UO.Light()

Parameters: No parameters.

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "light": bridge.SetLight(Arg(0)); break;

UO.Light(value) — UO.Light(Any)

Parameters: value (Any)

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "light": bridge.SetLight(Arg(0)); break;

UO.PlayWav

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

int UO.PlayWav(object? file);

Plays a local audio file.

Parameters

  • file — Path to the audio file. The absolute path is preserved, the relative path is resolved from CUOEnviroment.ExecutablePath. The extension itself is not checked: the file reads SoundEffect.FromStream.

Return value

Numeric flag int: 1 - sound.Play() accepted, 0 - no file, playback failed or error caught. This is not the end of playback.

Behavior

  • Bridge opens the file for reading, decodes SoundEffect.FromStream, stores received sounds in a limited _sounds list, and deletes/Dispose old ones when the limit is reached.
  • If a file/error does not exist, a message is displayed, the result is 0. The command does not wait for the end of the sound and does not transfer the file to the server.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The result of one call is printed in the journal. A number is not converted to bool; an array is displayed as its element count.

var result = UO.PlayWav("alert.wav");
UO.Print("PlayWav: " + Convert.ToString(result));

1. Direct call - direct script

Parameters and execution flow:

  • Plays a local audio file.
UO.Print(UO.PlayWav("alert.wav"));

2. Explicit option - script function

Parameters and execution flow:

  • Bridge opens the file for reading, decodes SoundEffect.FromStream, stores received sounds in a limited _sounds list, and deletes/Dispose old ones when the limit is reached.
return  RunScenario();
 object? RunScenario()
{
    UO.Print(UO.PlayWav("C:\\UO Sounds\\alert.wav"));
    return null;
}

3. Full Helper Function - Script Class

Parameters and execution flow:

  • If a file/error does not exist, a message is displayed, the result is 0. The command does not wait for the end of the sound and does not transfer the file to the server.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        var accepted = UO.PlayWav("alert.wav");
        if (Truth(accepted == 0))
        {
            UO.Print("Audio file could not be played");
        }

        return null;
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.PlayWav(file) — UO.PlayWav(Any)

Parameters: file (Any/String)

Result: int / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "playwav": return new InjectionValue(bridge.PlayWav(Text(0)));

UO.PlayWav(file) — UO.PlayWav(String)

Parameters: file (Any/String)

Result: int / Integer.

During a call:

Internal implementation code; this is not a standalone script.

public int PlayWav(string file) => bridge.PlayWav(file);

UO.SetSeason

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

void UO.SetSeason(object? season);

Locally changes the displayed season.

Parameters

  • season — int: 0..4; values ​​below 0/above 4 are limited to the nearest boundary. The number corresponds to the client's enum Season.

Return value

void - no value. Call on a separate line; completion does not confirm the server's action.

Behavior

  • Bridge.SetSeason calls _world.ChangeSeason((Season)clamp(season,0,4), -1). This is a display of the client's world, and not a request to change the server season.
  • Server data may later change the season again. The command does not change the map, server weather or calendar date.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.

UO.Print("Calling UO.SetSeason");
UO.SetSeason(0);

1. Direct call - direct script

Parameters and execution flow:

  • Locally changes the displayed season.
UO.SetSeason(0);

2. Explicit option - script function

Parameters and execution flow:

  • Bridge.SetSeason calls _world.ChangeSeason((Season)clamp(season,0,4), -1). This is a display of the client's world, and not a request to change the server season.
return  RunScenario();
 object? RunScenario()
{
    UO.SetSeason(4);
    return null;
}

3. Full Helper Function - Script Class

Parameters and execution flow:

  • Server data may later change the season again. The command does not change the map, server weather or calendar date.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        UO.SetSeason(99);
        UO.Print("Season clamped to 4");
        return null;
    }
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.SetSeason(season) — UO.SetSeason(Any)

Parameters: season (Any)

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "setseason": bridge.SetSeason(Arg(0)); break;

UO.Sound

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

void UO.Sound(object? soundId);

Plays sound on ID from client resources.

Parameters

  • soundId - int ID resource sound UO; not the path to WAV and not the duration.

Return value

void - no value. Call on a separate line; completion does not confirm the server's action.

Behavior

  • ExecuteLegacyManualAlias calls bridge.PlaySound, where RequireGameView("PlaySound").Audio.PlaySound(sound) is executed on the game thread.
  • Requires an open graphics window with audio. A missing error GUI may terminate the call; This void command does not return a playback result. For a local file, use PlayWav.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.

UO.Print("Calling UO.Sound");
UO.Sound(0x0040);

1. Direct call - direct script

Parameters and execution flow:

  • Plays sound on ID from client resources.
UO.Sound(0x0040);

2. Explicit option - script function

Parameters and execution flow:

  • ExecuteLegacyManualAlias calls bridge.PlaySound, where RequireGameView("PlaySound").Audio.PlaySound(sound) is executed on the game thread.
return  RunScenario();
 object? RunScenario()
{
    var soundId = 0x0040;
    UO.Sound(soundId);
    return null;
}

3. Full Helper Function - Script Class

Parameters and execution flow:

  • Requires an open graphics window with audio. A missing error GUI may terminate the call; This Unit command does not return a playback result. For a local file, use PlayWav.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        UO.Sound(0x0040);
        UO.Wait(250);
        UO.Print("Sound request made");
        return null;
    }
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.Sound(soundId) — UO.Sound(Any)

Parameters: soundId (Any)

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "sound": bridge.PlaySound(Arg(0)); break;

UO.TicksAnim

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# signatures

int UO.TicksAnim();

Reads the saved mark TicksAnim.

Parameters

There are no parameters.

Return value

int — mark UO.Timer in tenths of a second from the start of runtime. 0 - the mark has not yet been set or the event occurred in the first tenth of a second; it is not milliseconds or calendar time.

Behavior

  • Returns the field ticksAnim. It is updated by Morph or a non-zero Move result; it is not automatic observation of all manual/server activities. The command itself does not change the mark.
  • UO.Timer() - the mark calculates the age in tenths of a second. Marks are not compared between different runtimes.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The result of one call is printed in the journal. A number is not converted to bool; an array is displayed as its element count.

var result = UO.TicksAnim();
UO.Print("TicksAnim: " + Convert.ToString(result));

1. Direct call - direct script

Parameters and execution flow:

  • Reads the saved mark TicksAnim.
var stamp = UO.TicksAnim();
UO.Print(stamp);

2. Explicit option - script function

Parameters and execution flow:

  • Returns the field ticksAnim. It is updated by Morph or a non-zero Move result; it is not automatic observation of all manual/server activities. The command itself does not change the mark.
return  RunScenario();
 object? RunScenario()
{
    var stamp = UO.TicksAnim();
    var ageTenths = UO.Timer() - stamp;
    UO.Print(ageTenths);
    return null;
}

3. Full Helper Function - Script Class

Parameters and execution flow:

  • UO.Timer() - the mark calculates the age in tenths of a second. Marks are not compared between different runtimes.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        var before = UO.TicksAnim();
        UO.Wait(250);
        var after = UO.TicksAnim();
        UO.Print(before = after);
        return null;
    }
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.TicksAnim() — UO.TicksAnim()

Parameters: No parameters.

Result: int / Integer.

During a call:

Internal implementation code; this is not a standalone script.

public int TicksAnim() => ticksAnim;
⚠️ **GitHub.com Fallback** ⚠️