EN UO Topic sound visual environment - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
Sounds, lighting, season and client weather effects.
| Topic | Commands and explanations |
|---|---|
| Sound | UO.Sound |
| PlayWav | UO.PlayWav |
| Light | UO.Light |
| Season | UO.SetSeason |
| Weather Filter | UO.FilterWeather |
UO.Sound · UO.PlayWav · UO.Alarm · UO.Light · UO.SetSeason · UO.FilterWeather · UO.TicksAnim
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.
Parameters, result and all scenarios
UO.Print(UO.PlayWav("alert.wav"));Parameters, result and all scenarios
UO.Light();Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
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.
There are no parameters.
void - no value. Execute on a separate line. This is not a bool or confirmation that the user saw the message.
- 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.
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.
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();Parameters and execution flow:
- There are no parameters; The word Alarm appears in the system log.
UO.Alarm();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;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;
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: No parameters.
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility. -
InjectionScript.Runtime.InjectionApiUO.SystemMessage:SystemMessage(arguments.Length > 0 ? Text(0) : "Alarm"). -
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility::Text:Text(0).
Internal implementation code; this is not a standalone script.
case "alarm":
SystemMessage(arguments.Length > 0 ? Text(0) : "Alarm"); return InjectionValue.Unit;Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
void UO.FilterWeather();
void UO.FilterWeather(object? enabled);Enables or disables the client weather filter.
-
enabled— Optional value: without an argument, the filter is turned on; 0 turns off, non-zero int turns on.
void - no return value.
- 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.
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.
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();Parameters and execution flow:
- A zero number of arguments means include, not read.
UO.FilterWeather();Parameters and execution flow:
- An explicit 0 turns off the client filter.
return RunScenario();
object? RunScenario()
{
UO.FilterWeather(0);
return null;
}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;
}
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: No parameters.
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias. -
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias::Arg:Arg(0). -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.SetWeatherFilter:bridge.SetWeatherFilter(state.WeatherFilter).
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;Parameters: enabled (Any)
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias. -
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias::Arg:Arg(0). -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.SetWeatherFilter:bridge.SetWeatherFilter(state.WeatherFilter).
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;Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
void UO.Light();
void UO.Light(object? value);Locally sets the overall illumination of the client.
-
value— Optional integer: 0..30, limited to this range. The no-argument form uses 0; This is a write, not a read.
void - no value. Call on a separate line; completion does not confirm the server's action.
- 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.
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.
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();Parameters and execution flow:
- Locally sets the overall illumination of the client.
UO.Light();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;
}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;
}
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: No parameters.
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.SetLight:bridge.SetLight(Arg(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias::Arg:Arg(0).
Internal implementation code; this is not a standalone script.
case "light": bridge.SetLight(Arg(0)); break;Parameters: value (Any)
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.SetLight:bridge.SetLight(Arg(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias::Arg:Arg(0).
Internal implementation code; this is not a standalone script.
case "light": bridge.SetLight(Arg(0)); break;Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
int UO.PlayWav(object? file);Plays a local audio file.
-
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.
Numeric flag int: 1 - sound.Play() accepted, 0 - no file, playback failed or error caught. This is not the end of playback.
- 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.
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.
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));Parameters and execution flow:
- Plays a local audio file.
UO.Print(UO.PlayWav("alert.wav"));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;
}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;
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: file (Any/String)
Result: int / Any.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.PlayWav:bridge.PlayWav(Text(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility::Text:Text(0).
Internal implementation code; this is not a standalone script.
case "playwav": return new InjectionValue(bridge.PlayWav(Text(0)));Parameters: file (Any/String)
Result: int / Integer.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.PlayWav. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.PlayWav:bridge.PlayWav(file).
Internal implementation code; this is not a standalone script.
public int PlayWav(string file) => bridge.PlayWav(file);Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
void UO.SetSeason(object? season);Locally changes the displayed season.
-
season— int: 0..4; values below 0/above 4 are limited to the nearest boundary. The number corresponds to the client's enum Season.
void - no value. Call on a separate line; completion does not confirm the server's action.
- 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.
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.
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);Parameters and execution flow:
- Locally changes the displayed season.
UO.SetSeason(0);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;
}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;
}
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: season (Any)
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.SetSeason:bridge.SetSeason(Arg(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias::Arg:Arg(0).
Internal implementation code; this is not a standalone script.
case "setseason": bridge.SetSeason(Arg(0)); break;Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
void UO.Sound(object? soundId);Plays sound on ID from client resources.
-
soundId- int ID resource sound UO; not the path to WAV and not the duration.
void - no value. Call on a separate line; completion does not confirm the server's action.
- 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.
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.
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);Parameters and execution flow:
- Plays sound on ID from client resources.
UO.Sound(0x0040);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;
}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;
}
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: soundId (Any)
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.PlaySound:bridge.PlaySound(Arg(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteLegacyManualAlias::Arg:Arg(0).
Internal implementation code; this is not a standalone script.
case "sound": bridge.PlaySound(Arg(0)); break;Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
int UO.TicksAnim();Reads the saved mark TicksAnim.
There are no parameters.
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.
- 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.
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.
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));Parameters and execution flow:
- Reads the saved mark TicksAnim.
var stamp = UO.TicksAnim();
UO.Print(stamp);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;
}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;
}
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: No parameters.
Result: int / Integer.
During a call:
Internal implementation code; this is not a standalone script.
public int TicksAnim() => ticksAnim;