Repository navigation
EN API UO TargetToObject
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
void UO.TargetToObject(object? objID);Immediately responds to an already active server target serial object.
-
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.
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.
- 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.
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 command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.
UO.Print("Calling UO.TargetToObject");
UO.TargetToObject("self");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;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 RunScenario();
object? RunScenario()
{
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;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 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.CancelTarget();
UO.TargetToObject("self");
UO.Print("Queued: " + Convert.ToString(UO.IsWaitTargetActive()));
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: objID (Any)
Result: void / Unit.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility. -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.TargetToObject:bridge.TargetToObject(Arg(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility::Arg:Arg(0).
Internal implementation code; this is not a standalone script.
case "targettoobject": bridge.TargetToObject(Arg(0)); return InjectionValue.Unit;ClassicUO — Bad Newbie & C# Scripts IDE