Repository navigation
EN API UO LastAttack
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
dynamic UO.LastAttack();Reads the serial of the last attack target.
There are no parameters.
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.
- 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.
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.
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.LastAttack();
UO.Print(result is Array values ? "Count: " + values.Length : Convert.ToString(result));Parameters and execution flow:
- Reads the serial of the last attack target.
var id = UO.LastAttack();
UO.Print(Hex(id));
string Hex(object? value) => Convert.ToInt64(value).ToString("X");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.LastAttack();
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;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.LastAttack();
UO.Wait(500);
var after = UO.LastAttack();
UO.Print(before == after);
return null;
}
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: No parameters.
Result: dynamic / Any.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.LastAttack:bridge.LastAttack.
Internal implementation code; this is not a standalone script.
case "lastattack":
case "wartargetid": return new InjectionValue(bridge.LastAttack);ClassicUO — Bad Newbie & C# Scripts IDE