Repository navigation
EN API UO WaitForTarget
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
dynamic UO.WaitForTarget(object? arg0);Waits for the active target cursor to appear within the timeout.
-
MaxWaitTimeMS— Maximum wait in milliseconds. Zero and negative values give one immediate check; It's not an endless wait.
int 1 — the cursor was active during verification; 0 - timeout without cursor. The local callback target also satisfies this test. This is not confirmation of the use of the prepared WaitTarget: the automatic response may already have used up the cursor before checking.
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.
- The check is performed with pauses of up to 25 ms in the script thread and can be interrupted by stopping it.
- The method itself does not create a crosshair or select a target.
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.
Parameters and execution flow:
- MaxWaitTimeMS=3000, then self is selected.
- WaitTargetSelf is not preset: this example answers explicitly.
UO.UseSkill("Anatomy");
if (Truth(UO.WaitForTarget(3000)))
{
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:
- MaxWaitTimeMS=0.
- ready - 1 or 0; There is no long pause.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
var ready = UO.WaitForTarget(0);
UO.Print(Convert.ToString(ready));
return null;
}Parameters and execution flow:
- 500 - half a second.
- The absence of a sight may mean that the action has failed or is being processed automatically: check the game log.
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()
{
if (Truth(UO.WaitForTarget(500) == 0))
{
UO.CancelWaitTarget();
UO.Print("Cursor did not arrive");
}
return null;
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}ClassicUO — Bad Newbie & C# Scripts IDE