Skip to content

EN API UO Connected

LIHACHTETAN edited this page Nov 28, 2026 · 3 revisions

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

UO.Connected

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

C# signatures

dynamic UO.Connected();

Checks if the current session is in the game world and if its game connection is open. Use before a character action or while waiting for entry.

Parameters

There are no parameters.

Return value

int. 1 - there is a player, a loaded card and an active game socket at the same time; otherwise 0. An open client window, a list of characters, or a TCP connection at the login stage does not mean 1. Numeric flag int: 1 (condition met), 0 (condition not met). This is a numeric flag: in C# check result != 0 or result == 0. Direct comparison of int with true/false and if (result) is not allowed.

The result of the command is a numeric flag: 1 means a fulfilled condition, 0 means an unfulfilled one. After var result = command(...) check if (result != 0) or if (result == 0). Save the result of one call: a repeated call can perform the action again or read the state that has already changed.

Behavior

  • There are no parameters: serial, type, character name and IP cannot be passed. UO.Online(), UO.Connected() and UO.IsOnline() check the same thing. This is the state of the given session owner, not another manager profile.
  • The command only reads the local state. It does not send a ping, does not connect, does not pause, and does not check the availability of the Internet. After reading, the connection may change; 1 does not guarantee the success of the next action.
  • UO.Wait takes milliseconds. Autopause when the connection is lost and manual pause delay the execution of examples: the timeout check will continue only after the pause is removed. These commands do not unpause themselves and do not enable auto-reconnect.

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.

object? result = UO.Connected();
UO.Print(result is Array values ? "Count: " + values.Length : Convert.ToString(result));

1. Do not perform the game skill offline - direct script

Parameters and execution flow:

  • false is equivalent to 0. return terminates Main to UseSkill. Hiding is the only parameter of UseSkill, the name of the skill. With 1 the script only asks to use the skill; the result depends on the state of the character and the server.
  • The command only reads the local state. It does not send a ping, does not connect, does not pause, and does not check the availability of the Internet. After reading, the connection may change; 1 does not guarantee the success of the next action.
if (Truth(Truth(UO.Connected()) == false))
{
    return null;
}
UO.UseSkill("Hiding");

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

2. Request connection when no connection - script function

Parameters and execution flow:

  • Comparison with 0 checks the current connection, not the auto-reconnect setting. Connect without arguments uses the saved settings and does not wait for the login to complete. Repeating a command during a login that has already started should not create a second session.
  • The command only reads the local state. It does not send a ping, does not connect, does not pause, and does not check the availability of the Internet. After reading, the connection may change; 1 does not guarantee the success of the next action.
return  RunScenario();
 object? RunScenario()
{
    if (Truth(UO.Connected() == 0))
    {
        UO.Connect();
    }

    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. Wait for world to be ready with time limit - scenario class

Parameters and execution flow:

  • WaitForWorld(timeoutMs) is a fully shown user-defined function, not a built-in command. 5000 — budget in ms, UO.Wait(50) — check interval. A negative value gives false; 0 only allows a ready-made world. Timer measures seconds, so the difference is multiplied by 1000. Autopause must be turned off in advance, otherwise Main exits. The function does not call Connect and does not cancel the started input when the time expires.
  • The command only reads the local state. It does not send a ping, does not connect, does not pause, and does not check the availability of the Internet. After reading, the connection may change; 1 does not guarantee the success of the next action.
return await new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenarioAsync();
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;
    }

    async public Task<object?> RunScenarioAsync()
    {
        if (Truth(UO.GetPauseScriptOnDisconnectStatus()))
        {
            return null;
        }

        if (Truth(await WaitForWorld(5000)))
        {
            UO.UseSkill("Hiding");
        }

        return null;
    }

    async Task<dynamic> WaitForWorld(dynamic timeoutMs)
    {
        if (Truth(timeoutMs < 0))
        {
            return false;
        }

        var started = Environment.TickCount;
        while (!(Truth(UO.Connected())))
        {
            if (Truth((Environment.TickCount - started) * 1000.0 >= timeoutMs))
            {
                return false;
            }

            await Delay(50);
        }

        return true;
    }

    Task Delay(object? milliseconds) => WaitAsync(checked((int)Convert.ToDouble(milliseconds)));
    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.Connected() — UO.Connected()

Parameters: No parameters.

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "connected": return new InjectionValue(bridge.IsOnline());

Clone this wiki locally