Skip to content

EN API UO WarTargetID

Codex edited this page Nov 6, 2026 · 3 revisions

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

UO.WarTargetID

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

C# signatures

dynamic UO.WarTargetID();

Reads the serial of the last attack target.

Parameters

There are no parameters.

Return value

int — saved serial; 0 means serial is not installed. It's not a bool or a graphic/type; a nonzero ID may no longer exist in the world.

Behavior

  • Field source: bridge.LastAttack. The command does not select, use, or attack the object.
  • Reads the current local state. There is no package, target or automatic update; individual reads may see different states.

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

1. Direct call - direct script

Parameters and execution flow:

  • Reads the serial of the last attack target.
var id = UO.WarTargetID();
UO.Print(Hex(id));

string Hex(object? value) => Convert.ToInt64(value).ToString("X");

2. Explicit option - script function

Parameters and execution flow:

  • Field source: bridge.LastAttack. The command does not select, use, or attack the object.
return  RunScenario();
 object? RunScenario()
{
    var id = UO.WarTargetID();
    if (Truth(id != 0) && Truth(UO.Exists(id)))
    {
        UO.Print(UO.GetName(id));
    }

    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. Full Helper Function - Script Class

Parameters and execution flow:

  • Reads the current local state. There is no package, target or automatic update; individual reads may see different states.
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.WarTargetID();
        UO.Wait(500);
        var after = UO.WarTargetID();
        UO.Print(before == after);
        return null;
    }
}

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

Parameters: No parameters.

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "lastattack":

                case "wartargetid": return new InjectionValue(bridge.LastAttack);

Clone this wiki locally