Repository navigation
EN API UO WaitingForMenu
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
int UO.WaitingForMenu(object? delay);
int UO.WaitingForMenu(object? delay, object? menuCount);
int UO.WaitingForMenu(object? delay, object? menuCount, object? blockMenu);
int UO.WaitingForMenu(object? delay, object? menuCount, object? blockMenu, object? menuName);
int UO.WaitingForMenu(object? delayValue, object? menuCountValue, object? blockMenuValue, object? menuNameValue, object? skillOrSerial);The required number of server menu appearances is limited.
-
delay— int timeout in milliseconds, negative becomes 0. Even with 0 one check is performed. -
delayValue— int timeout in milliseconds, negative becomes 0. Even with 0 one check is performed. -
menuCount— Optional number of appearances, minimum 1; default is 1. This is not the number of menu items. -
menuCountValue— Optional number of appearances, minimum 1; default is 1. This is not the number of menu items. -
blockMenu— An optional non-zero number closes the menu when the condition is met; 0 leaves him. -
blockMenuValue— An optional non-zero number closes the menu when the condition is met; 0 leaves him. -
menuName- Optional exact title, case sensitive; empty allows anyone. -
menuNameValue- Optional exact title, case sensitive; empty allows anyone. -
skillOrSerial- Optional last argument: TriggerWaitAction can first use a skill by name or an object by serial. By default 0 - no action.
Numeric flag int: 1 - at least menuCount different occurrences are noticed and the last one has the desired title; 0 - timeout. The existing menu can be counted immediately.
- After TriggerWaitAction reads GetLastMenuIdentity; the new identity increases the counter. An empty identity resets the memory of the previous one, so the same menu can be counted again after closing/reopening.
- The count boundary is checked only with a new identity. If and matches, blockMenu closes the menu. Between checks UO.Wait until 25 ms; the header is checked by Ordinal, not substring.
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.
var result = UO.WaitingForMenu(3000);
UO.Print("WaitingForMenu: " + Convert.ToString(result));Parameters and execution flow:
- The required number of server menu appearances is limited.
UO.Print(UO.WaitingForMenu(3000));Parameters and execution flow:
- After TriggerWaitAction reads GetLastMenuIdentity; the new identity increases the counter. An empty identity resets the memory of the previous one, so the same menu can be counted again after closing/reopening.
return RunScenario();
object? RunScenario()
{
UO.Print(UO.WaitingForMenu(3000, 1, 1, "Craft"));
return null;
}Parameters and execution flow:
- The count boundary is checked only with a new identity. If and matches, blockMenu closes the menu. Between checks UO.Wait until 25 ms; the header is checked by Ordinal, not substring.
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 found = UO.WaitingForMenu(3000, 1, 0, "Craft", "lasttarget");
if (Truth(found))
{
UO.Print(UO.GetLastMenuItems());
}
return null;
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: delay (Any)
Result: int / Integer.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu. -
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu:WaitingForMenu(delay, InjectionValue.Zero, InjectionValue.Zero, new InjectionValue(string.Empty), InjectionValue.Zero).
Internal implementation code; this is not a standalone script.
public int WaitingForMenu(InjectionValue delay) => WaitingForMenu(delay, InjectionValue.Zero, InjectionValue.Zero, new InjectionValue(string.Empty), InjectionValue.Zero);Parameters: delay (Any), menuCount (Any)
Result: int / Integer.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu. -
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu:WaitingForMenu(delay, menuCount, InjectionValue.Zero, new InjectionValue(string.Empty), InjectionValue.Zero).
Internal implementation code; this is not a standalone script.
public int WaitingForMenu(InjectionValue delay, InjectionValue menuCount) => WaitingForMenu(delay, menuCount, InjectionValue.Zero, new InjectionValue(string.Empty), InjectionValue.Zero);Parameters: delay (Any), menuCount (Any), blockMenu (Any)
Result: int / Integer.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu. -
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu:WaitingForMenu(delay, menuCount, blockMenu, new InjectionValue(string.Empty), InjectionValue.Zero).
Internal implementation code; this is not a standalone script.
public int WaitingForMenu(InjectionValue delay, InjectionValue menuCount, InjectionValue blockMenu) => WaitingForMenu(delay, menuCount, blockMenu, new InjectionValue(string.Empty), InjectionValue.Zero);Parameters: delay (Any), menuCount (Any), blockMenu (Any), menuName (Any)
Result: int / Integer.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu. -
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu:WaitingForMenu(delay, menuCount, blockMenu, menuName, InjectionValue.Zero).
Internal implementation code; this is not a standalone script.
public int WaitingForMenu(InjectionValue delay, InjectionValue menuCount, InjectionValue blockMenu, InjectionValue menuName) => WaitingForMenu(delay, menuCount, blockMenu, menuName, InjectionValue.Zero);
UO.WaitingForMenu(delayValue, menuCountValue, blockMenuValue, menuNameValue, skillOrSerial) — UO.WaitingForMenu(Any,Any,Any,Any,Any)
Parameters: delayValue (Any), menuCountValue (Any), blockMenuValue (Any), menuNameValue (Any), skillOrSerial (Any)
Result: int / Integer.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.WaitingForMenu. -
InjectionScript.Runtime.NumberConversions.ToInt:NumberConversions.ToInt(delayValue). -
InjectionScript.Runtime.InjectionValue.ToString:menuNameValue.ToString(). -
InjectionScript.Runtime.InjectionApiUO.TriggerWaitAction:TriggerWaitAction(skillOrSerial). -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.GetLastMenuIdentity:bridge.GetLastMenuIdentity(). -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.GetLastMenuCaption:bridge.GetLastMenuCaption(). -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.CloseMenu:bridge.CloseMenu(). -
ClassicUO.Game.Managers.ClassicUOInjectionApiBridge.Wait:bridge.Wait(Math.Min(25, Math.Max(1, delay))).
Internal implementation code; this is not a standalone script.
public int WaitingForMenu(InjectionValue delayValue, InjectionValue menuCountValue, InjectionValue blockMenuValue, InjectionValue menuNameValue, InjectionValue skillOrSerial)
{
int delay = Math.Max(0, NumberConversions.ToInt(delayValue));
int requiredMenuCount = Math.Max(1, NumberConversions.ToInt(menuCountValue));
bool blockMenu = NumberConversions.ToInt(blockMenuValue) != 0;
string expectedName = menuNameValue.ToString() ?? string.Empty;
DateTime deadline = timeSource.Now.AddMilliseconds(delay);
string previousIdentity = string.Empty;
int observedMenuCount = 0;
TriggerWaitAction(skillOrSerial);
do
{
string identity = bridge.GetLastMenuIdentity() ?? string.Empty;
if (identity.Length == 0)
{
// Reset between server menus so an identical menu opened again
// still counts as a new appearance.
previousIdentity = string.Empty;
}
else if (!identity.Equals(previousIdentity, StringComparison.Ordinal))
{
previousIdentity = identity;
observedMenuCount++;
string caption = bridge.GetLastMenuCaption() ?? string.Empty;
bool nameMatches = expectedName.Length == 0
|| caption.Equals(expectedName, StringComparison.Ordinal);
if (observedMenuCount >= requiredMenuCount && nameMatches)
{
if (blockMenu)
bridge.CloseMenu();
return 1;
}
}
if (timeSource.Now >= deadline)
break;
bridge.Wait(Math.Min(25, Math.Max(1, delay)));
}
while (true);
return 0;
}ClassicUO — Bad Newbie & C# Scripts IDE