Skip to content

EN API UO TargetPresent

LIHACHTETAN edited this page Nov 28, 2026 · 3 revisions

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

UO.TargetPresent

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

C# signatures

dynamic UO.TargetPresent();

Checks for an active target selection cursor in the client.

Parameters

There are no parameters.

Return value

int 1 - TargetManager.IsTargeting set; 0 - no active cursor. The local callback target is also taken into account. This is not serial or the queue state WaitTarget.

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

  • Reads the state once; does not wait for the cursor to appear.
  • To wait for a server crosshair after a game action, use WaitForTarget. For the result of local ClientRequest* - WaitForClientTargetResponse.

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

1. Show status - direct script

Parameters and execution flow:

  • There are no arguments.
  • 1 or 0 is displayed.
UO.Print(Convert.ToString(UO.TargetPresent()));

2. Cancel open cursor - script function

Parameters and execution flow:

  • The condition is checked by the active cursor.
  • CancelTarget in this client also clears prepared responses.
return  RunScenario();
 object? RunScenario()
{
    if (Truth(UO.TargetPresent()))
    {
        UO.CancelTarget();
    }

    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. After requesting a game action - scenario class

Parameters and execution flow:

  • UseSkill requests the skill, WaitForTarget waits until 3000 ms.
  • TargetToObject responds only to the active server target; If there is a timeout, the branch is not executed.
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.UseSkill("Anatomy");
        if (Truth(UO.WaitForTarget(3000)))
        {
            if (Truth(UO.TargetPresent()))
            {
                UO.TargetToObject("self");
            }
        }

        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.TargetPresent() — UO.TargetPresent()

Parameters: No parameters.

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "targetpresent": return new InjectionValue(IsTargeting());

Clone this wiki locally