Skip to content

EN API UO WaitForTarget

LIHACHTETAN edited this page Nov 28, 2026 · 3 revisions

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

UO.WaitForTarget

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

C# signatures

dynamic UO.WaitForTarget(object? maxWaitTimeMS);

Waits for the active target cursor to appear within the timeout.

Parameters

  • maxWaitTimeMS — Maximum wait in milliseconds. Zero and negative values ​​give one immediate check; It's not an endless wait.

Return value

int 1 — the cursor was active during verification; 0 - timeout without cursor. The local callback target also satisfies this test. This is not confirmation of the use of the prepared WaitTarget: the automatic response may already have used up the cursor before checking.

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

  • The check is performed with pauses of up to 25 ms in the script thread and can be interrupted by stopping it.
  • The method itself does not create a crosshair or select a target.

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.WaitForTarget(3000);
UO.Print(result is Array values ? "Count: " + values.Length : Convert.ToString(result));

1. Wait for skill sight - direct script

Parameters and execution flow:

  • MaxWaitTimeMS=3000, then self is selected.
  • WaitTargetSelf is not preset: this example answers explicitly.
UO.UseSkill("Anatomy");
if (Truth(UO.WaitForTarget(3000)))
{
    UO.TargetToObject("self");
}

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

2. One check - script function

Parameters and execution flow:

  • MaxWaitTimeMS=0.
  • ready - 1 or 0; There is no long pause.
return  RunScenario();
 object? RunScenario()
{
    var ready = UO.WaitForTarget(0);
    UO.Print(Convert.ToString(ready));
    return null;
}

3. Handle Timeout - Script Class

Parameters and execution flow:

  • 500 - half a second.
  • The absence of a sight may mean that the action has failed or is being processed automatically: check the game log.
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()
    {
        if (Truth(UO.WaitForTarget(500) == 0))
        {
            UO.CancelWaitTarget();
            UO.Print("Cursor did not arrive");
        }

        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.WaitForTarget(maxWaitTimeMS) — UO.WaitForTarget(Any)

Parameters: maxWaitTimeMS (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "waitfortarget": return new InjectionValue(bridge.WaitUntilTargeting(Arg(0)));

Clone this wiki locally