Skip to content

EN API UO TargetToObject

Codex edited this page Oct 11, 2026 · 3 revisions

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

UO.TargetToObject

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

C# signatures

void UO.TargetToObject(object? arg0);

Immediately responds to an already active server target serial object.

Parameters

  • ObjID — Serial/ID of an item or character, number or hex/decimal string, self/backpack/lasttarget/lastobject or saved name AddObject. This is not type. Before acting on a named object, check Exists; an unresolved alias gives serial 0.

Return value

void - no return value. Call on a separate line; do not use as true/false, serial or type. Metadata object? for compatible forms does not change the actual result of void.

Behavior

  • Without an active server cursor, it does nothing and does not create a deferred response. For preliminary preparation, use WaitTargetObject/WaitTargetTile/WaitTargetXYZ.
  • Local ClientRequest* and other callback sights are not processed by this command.
  • The server determines whether the target is valid. For serial not in memory, ID is sent with zero graphics/coordinate fields.

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.

1. Reply to open sight - direct script

Parameters and execution flow:

  • The parameters define the character itself.
  • Nothing is added to the future target cursor queue.
if (Truth(UO.TargetPresent()))
{
    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. First wait for sight - script function

Parameters and execution flow:

  • 3000 — maximum wait in milliseconds; The action that requested the sight must be performed previously.
  • The command is called only after the sight appears; the game action may then end in server failure.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
    if (Truth(UO.WaitForTarget(3000)))
    {
        UO.TargetToObject("self");
    }
    else
    {
        UO.Print("Target timeout");
    }

    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. Check for deferred response - script class

Parameters and execution flow:

  • CancelTarget closes the old sight and clears the queue.
  • In the absence of a new target cursor, the challenge does not create anticipation. The queue output remains 0 unless another script has changed it.
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()
    {
        UO.CancelTarget();
        UO.TargetToObject("self");
        UO.Print("Queued: " + Convert.ToString(UO.IsWaitTargetActive()));
        return null;
    }
}

Clone this wiki locally