Skip to content

EN UO Topic trade

Codex edited this page Oct 12, 2026 · 4 revisions

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

Trade

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

Window for secure exchange between players: participant, container, status, confirmation and cancellation.

Sections

Topic Commands and explanations
IsTrade UO.IsTrade
Trade Opponent UO.GetTradeOpponent · UO.GetTradeOpponentName
Trade Container UO.GetTradeContainer
ConfirmTrade UO.ConfirmTrade
CancelTrade UO.CancelTrade

All theme commands

Secure Trade

UO.IsTrade · UO.TradeCount · UO.TradeCheck · UO.TradeContainer · UO.GetTradeContainer · UO.TradeOpponent · UO.GetTradeOpponent · UO.TradeName · UO.GetTradeOpponentName · UO.ConfirmTrade · UO.CancelTrade

Examples on the topic

Each command card has several independent scenarios: direct code, functions and classes. Below are selected short scenarios; restrictions and full analysis are in the cards.

UO.GetTradeContainer

Parameters, result and all scenarios

var value = UO.GetTradeContainer(1, 1);
UO.Print(Hex(value));

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

UO.ConfirmTrade

Parameters, result and all scenarios

var result = UO.ConfirmTrade(1);
if (Truth(Truth(result) == true))
{
    UO.Print("Local request processed");
}

bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;

Complete command reference


UO.CancelTrade

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

C# signatures

dynamic UO.CancelTrade(object? tradeNum);

Cancels the selected exchange and closes its window.

Parameters

  • tradeNum — Integer: current window number from 1 to TradeCount(). 0 and negative values ​​are not allowed. This is not serial.

Return value

int: 1 (condition met) - the window is found, closed and a cancellation request is sent via closing; 0 (condition not met) - no window. This is not waiting for a server response. Canceling the closed window again does not send the second packet.

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.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var result = UO.CancelTrade(1);
if (Truth(Truth(result) == true))
{
    UO.Print("Local request processed");
}

bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;

2. Other Script and Options - Script Function

Parameters and execution flow:

  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.
return  RunScenario();
 object? RunScenario()
{
    var tradeNumber = 2;
    if (Truth(UO.TradeCount() >= tradeNumber))
    {
        var result = UO.CancelTrade(tradeNumber);
        UO.Print(Convert.ToString(result));
    }

    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. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 expectedPartner = UO.GetTradeOpponent(1);
        var result = ApplyToPartner(1, expectedPartner);
        UO.Print(Convert.ToString(result));
        return null;
    }

    dynamic ApplyToPartner(dynamic tradeNumber, dynamic expectedPartner)
    {
        if (Truth(expectedPartner == 0))
        {
            return false;
        }

        if (Truth(UO.GetTradeOpponent(tradeNumber) != expectedPartner))
        {
            return false;
        }

        return UO.CancelTrade(tradeNumber);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.CancelTrade(tradeNum) — UO.CancelTrade(Any)

Parameters: tradeNum (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "canceltrade": return new InjectionValue(bridge.CancelTrade(Arg(0)));

UO.ConfirmTrade

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

C# signatures

dynamic UO.ConfirmTrade(object? tradeNum);

Sets the custom consent flag on the selected exchange.

Parameters

  • tradeNum — Integer: current window number from 1 to TradeCount(). 0 and negative values ​​are not allowed. This is not serial.

Return value

int: 1 (condition met) - the window is found and its own agreement is turned on (or has already been turned on); 0 (condition not met) - no window. Does not confirm the transfer of items by the server. Calling again does not remove consent.

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.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var result = UO.ConfirmTrade(1);
if (Truth(Truth(result) == true))
{
    UO.Print("Local request processed");
}

bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;

2. Other Script and Options - Script Function

Parameters and execution flow:

  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.
return  RunScenario();
 object? RunScenario()
{
    var tradeNumber = 2;
    if (Truth(UO.TradeCount() >= tradeNumber))
    {
        var result = UO.ConfirmTrade(tradeNumber);
        UO.Print(Convert.ToString(result));
    }

    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. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 expectedPartner = UO.GetTradeOpponent(1);
        var result = ApplyToPartner(1, expectedPartner);
        UO.Print(Convert.ToString(result));
        return null;
    }

    dynamic ApplyToPartner(dynamic tradeNumber, dynamic expectedPartner)
    {
        if (Truth(expectedPartner == 0))
        {
            return false;
        }

        if (Truth(UO.GetTradeOpponent(tradeNumber) != expectedPartner))
        {
            return false;
        }

        return UO.ConfirmTrade(tradeNumber);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.ConfirmTrade(tradeNum) — UO.ConfirmTrade(Any)

Parameters: tradeNum (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "confirmtrade": return new InjectionValue(bridge.ConfirmTrade(Arg(0)));

UO.GetTradeContainer

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

C# signatures

dynamic UO.GetTradeContainer(object? tradeNum, object? num);

Returns the numeric serial of one of the two exchange containers.

Parameters

  • tradeNum — Integer: current window number from 1 to TradeCount(). 0 and negative values ​​are not allowed. This is not serial.
  • num - 1 - own container, 2 - partner’s container. The remaining values ​​return 0.

Return value

int: 32 bit serial container; 0 if there is no window or incorrect Num. This is not type. The most significant bit is preserved: check != 0, not > 0 or == true.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.GetTradeContainer(1, 1);
UO.Print(Hex(value));

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

2. Other Script and Options - Script Function

Parameters and execution flow:

  • total — snapshot of the number of windows; index - current index/number. The enumeration example does not confirm anything. In GetTradeContainer two calls read their container (1) and someone else's (2) of the first window (1).
return  RunScenario();
 object? RunScenario()
{
    var ours = UO.GetTradeContainer(1, 1);
    var theirs = UO.GetTradeContainer(1, 2);
    UO.Print(Hex(ours) + " / " + Hex(theirs));
    return null;
}

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

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeValue(1);
        UO.Print(Hex(value));
        return null;
    }

    dynamic ReadTradeValue(dynamic index)
    {
        var total = UO.TradeCount();
        if (Truth(index < 1) || Truth(index >= total + 1))
        {
            return 0;
        }

        return UO.GetTradeContainer(index, 1);
    }

    string Hex(object? value) => Convert.ToInt64(value).ToString("X");
    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.GetTradeContainer(tradeNum, num) — UO.GetTradeContainer(Any,Any)

Parameters: tradeNum (Any), num (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "gettradecontainer": return new InjectionValue(bridge.GetTradeContainer(Arg(0), Arg(1)));

UO.GetTradeOpponent

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

C# signatures

dynamic UO.GetTradeOpponent(object? tradeNum);

Returns the numeric serial of the partner character.

Parameters

  • tradeNum — Integer: current window number from 1 to TradeCount(). 0 and negative values ​​are not allowed. This is not serial.

Return value

int: serial character from LocalSerial window; 0 if there is no window. Not a container and not a bool; check != 0.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.GetTradeOpponent(1);
UO.Print(Hex(value));

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

2. Other Script and Options - Script Function

Parameters and execution flow:

  • total — snapshot of the number of windows; index - current index/number. The enumeration example does not confirm anything. In GetTradeContainer two calls read their container (1) and someone else's (2) of the first window (1).
return  RunScenario();
 object? RunScenario()
{
    var total = UO.TradeCount();
    for (int index = (int)(1); index <= total - 0; index += (int)(1))
    {
        var value = UO.GetTradeOpponent(index);
        UO.Print(Convert.ToString(index) + ": " + Hex(value));
    }

    return null;
}

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

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeValue(1);
        UO.Print(Hex(value));
        return null;
    }

    dynamic ReadTradeValue(dynamic index)
    {
        var total = UO.TradeCount();
        if (Truth(index < 1) || Truth(index >= total + 1))
        {
            return 0;
        }

        return UO.GetTradeOpponent(index);
    }

    string Hex(object? value) => Convert.ToInt64(value).ToString("X");
    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.GetTradeOpponent(tradeNum) — UO.GetTradeOpponent(Any)

Parameters: tradeNum (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "gettradeopponent": return new InjectionValue(bridge.GetTradeOpponent(Arg(0)));

UO.GetTradeOpponentName

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

C# signatures

dynamic UO.GetTradeOpponentName(object? tradeNum);

Returns the partner name received along with the exchange window.

Parameters

  • tradeNum — Integer: current window number from 1 to TradeCount(). 0 and negative values ​​are not allowed. This is not serial.

Return value

string: name from the exchange opening package; empty string if there is no window or name. Doesn't ask for the name again.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.GetTradeOpponentName(1);
UO.Print(Convert.ToString(value));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • total — snapshot of the number of windows; index - current index/number. The enumeration example does not confirm anything. In GetTradeContainer two calls read their container (1) and someone else's (2) of the first window (1).
return  RunScenario();
 object? RunScenario()
{
    var total = UO.TradeCount();
    for (int index = (int)(1); index <= total - 0; index += (int)(1))
    {
        var value = UO.GetTradeOpponentName(index);
        UO.Print(Convert.ToString(index) + ": " + Convert.ToString(value));
    }

    return null;
}

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeValue(1);
        UO.Print(Convert.ToString(value));
        return null;
    }

    dynamic ReadTradeValue(dynamic index)
    {
        var total = UO.TradeCount();
        if (Truth(index < 1) || Truth(index >= total + 1))
        {
            return "";
        }

        return UO.GetTradeOpponentName(index);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.GetTradeOpponentName(tradeNum) — UO.GetTradeOpponentName(Any)

Parameters: tradeNum (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "gettradeopponentname": return new InjectionValue(bridge.GetTradeOpponentName(Arg(0)));

UO.IsTrade

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

C# signatures

int UO.IsTrade();

Checks for an open secure exchange window.

Parameters

There are no parameters.

Return value

int: 1 (condition met) - there is an open exchange; 0 (condition not met) - no.

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.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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.

var result = UO.IsTrade();
UO.Print("IsTrade: " + Convert.ToString(result));

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.IsTrade();
UO.Print(Convert.ToString(value));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • before/after - two separate snapshots with an interval of 500 milliseconds. The pause does not wait for a specific exchange; Between readings the state may change several times.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
    var before = UO.IsTrade();
    await Delay(500);
    var after = UO.IsTrade();
    UO.Print(Convert.ToString(before) + " -> " + Convert.ToString(after));
    return null;
}

Task Delay(object? milliseconds) => WaitAsync(checked((int)Convert.ToDouble(milliseconds)));

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeState();
        UO.Print(Convert.ToString(value));
        return null;
    }

    dynamic ReadTradeState()
    {
        return UO.IsTrade();
    }
}

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

Parameters: No parameters.

Result: int / Integer.

During a call:

Internal implementation code; this is not a standalone script.

case "istrade": return new InjectionValue(bridge.IsTrade());

UO.TradeCheck

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

C# signatures

int UO.TradeCheck(object? windowIndex);
dynamic UO.TradeCheck(object? tradeNum, object? num);
int UO.TradeCheck(object? windowIndex, object? checkbox, object? stateValue);

Reads consent flags; the three-parameter form also modifies its own checkbox.

Parameters

  • windowIndex — Integer: current window index from 0 to TradeCount()-1. A negative or missing index produces a blank result. This is not serial.
  • tradeNum — Integer: current window index from 0 to TradeCount()-1. A negative or missing index produces a blank result. This is not serial.
  • num — Two-parameter form only: 1 — own flag, 2 — partner’s flag; other meanings give 0. TradeNum here starts with 0.
  • checkbox — Three-parameter form only: 0 — your own flag, 1 — your partner’s. Someone else's flag is only read; another meaning is given by 0.
  • stateValue — Only with checkbox=0: 0/false removes consent, any non-zero number/true includes. If checkbox=1 the value is ignored.

Return value

int: 1 (condition met) - the selected checkbox is selected; 0 (condition not met) - removed, the window is missing or the side is incorrect. The record form returns the status rather than the indication of a successful transaction: clearing the checkbox returns 0.

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.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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.

var result = UO.TradeCheck(0);
UO.Print("TradeCheck: " + Convert.ToString(result));

1. Direct reading or action - direct script

Parameters and execution flow:

  • UO.TradeCheck(0) and UO.TradeCheck(0,1) read their agreement of the first window; UO.TradeCheck(0,2) - someone else's. There is no recording and no automatic confirmation.
var own = UO.TradeCheck(0);
var sameOwn = UO.TradeCheck(0, 1);
var other = UO.TradeCheck(0, 2);
UO.Print(Convert.ToString(own) + "/" + Convert.ToString(sameOwn) + "/" + Convert.ToString(other));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • UO.TradeCheck(0,0,false) withdraws his consent. UO.TradeCheck(0,1,false) only reads the partner's consent: false cannot change someone else's side. We expect the result 0 after withdrawal.
return  RunScenario();
 object? RunScenario()
{
    var cleared = UO.TradeCheck(0, 0, false);
    var other = UO.TradeCheck(0, 1, false);
    UO.Print(Convert.ToString(cleared) + "/" + Convert.ToString(other));
    return null;
}

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 accepted = BothAccepted(0);
        if (Truth(Truth(accepted) == true))
        {
            UO.Print("Both boxes are checked; server completion is not known");
        }

        return null;
    }

    dynamic BothAccepted(dynamic index)
    {
        if (Truth(index < 0) || Truth(index >= UO.TradeCount()))
        {
            return false;
        }

        var own = UO.TradeCheck(index, 1);
        var other = UO.TradeCheck(index, 2);
        return Truth(Truth(own) == true) && Truth(Truth(other) == true);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.TradeCheck(windowIndex) — UO.TradeCheck(Any)

Parameters: windowIndex (Any)

Result: int / Integer.

During a call:

Internal implementation code; this is not a standalone script.

public int TradeCheck(InjectionValue windowIndex)

            => bridge.TradeCheck(NumberConversions.ToInt(windowIndex), 0, 0, false);

UO.TradeCheck(tradeNum, num) — UO.TradeCheck(Any,Any)

Parameters: tradeNum (Any), num (Any)

Result: dynamic / Any.

During a call:

Internal implementation code; this is not a standalone script.

case "tradecheck":

                    // The compatibility reader uses participants 1/2; the legacy

                    // one/three-argument forms use checkbox indices 0/1.

                    int tradeSide = Arg(1);

                    return new InjectionValue(tradeSide is 1 or 2

                        ? bridge.TradeCheck(Arg(0), tradeSide - 1, 0, false) : 0);

UO.TradeCheck(windowIndex, checkbox, stateValue) — UO.TradeCheck(Any,Any,Any)

Parameters: windowIndex (Any), checkbox (Any), stateValue (Any)

Result: int / Integer.

During a call:

Internal implementation code; this is not a standalone script.

public int TradeCheck(InjectionValue windowIndex, InjectionValue checkbox, InjectionValue stateValue)

            => bridge.TradeCheck(NumberConversions.ToInt(windowIndex), NumberConversions.ToInt(checkbox), NumberConversions.ToInt(stateValue), true);

UO.TradeContainer

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

C# signatures

string UO.TradeContainer(object? windowIndex);

Returns serial of its exchange container as a hex string.

Parameters

  • windowIndex — Integer: current window index from 0 to TradeCount()-1. A negative or missing index produces a blank result. This is not serial.

Return value

string: hex of the form "0x40000011"; "0x00000000" if there is no window. This is the ID of its container, not bool and not the empty string.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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.

var result = UO.TradeContainer(0);
UO.Print("TradeContainer: " + Convert.ToString(result));

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.TradeContainer(0);
UO.Print(Convert.ToString(value));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • total — snapshot of the number of windows; index - current index/number. The enumeration example does not confirm anything. In GetTradeContainer two calls read their container (1) and someone else's (2) of the first window (1).
return  RunScenario();
 object? RunScenario()
{
    var total = UO.TradeCount();
    for (int index = (int)(0); index <= total - 1; index += (int)(1))
    {
        var value = UO.TradeContainer(index);
        UO.Print(Convert.ToString(index) + ": " + Convert.ToString(value));
    }

    return null;
}

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeValue(0);
        UO.Print(Convert.ToString(value));
        return null;
    }

    dynamic ReadTradeValue(dynamic index)
    {
        var total = UO.TradeCount();
        if (Truth(index < 0) || Truth(index >= total + 0))
        {
            return "0x00000000";
        }

        return UO.TradeContainer(index);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.TradeContainer(windowIndex) — UO.TradeContainer(Any)

Parameters: windowIndex (Any)

Result: string / String.

During a call:

Internal implementation code; this is not a standalone script.

public string TradeContainer(InjectionValue windowIndex) => NumberConversions.ToHex(bridge.TradeContainer(NumberConversions.ToInt(windowIndex)));

UO.TradeCount

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

C# signatures

int UO.TradeCount();

Returns the number of open exchange windows.

Parameters

There are no parameters.

Return value

int: number of windows from 0. This is a quantity, not a bool; to check availability use > 0.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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.

var result = UO.TradeCount();
UO.Print("TradeCount: " + Convert.ToString(result));

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.TradeCount();
UO.Print(Convert.ToString(value));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • before/after - two separate snapshots with an interval of 500 milliseconds. The pause does not wait for a specific exchange; Between readings the state may change several times.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
    var before = UO.TradeCount();
    await Delay(500);
    var after = UO.TradeCount();
    UO.Print(Convert.ToString(before) + " -> " + Convert.ToString(after));
    return null;
}

Task Delay(object? milliseconds) => WaitAsync(checked((int)Convert.ToDouble(milliseconds)));

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeState();
        UO.Print(Convert.ToString(value));
        return null;
    }

    dynamic ReadTradeState()
    {
        return UO.TradeCount();
    }
}

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

Parameters: No parameters.

Result: int / Integer.

During a call:

Internal implementation code; this is not a standalone script.

public int TradeCount() => bridge.TradeCount();

UO.TradeName

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

C# signatures

string UO.TradeName(object? windowIndex);

Returns the partner's name from the exchange window by index from zero.

Parameters

  • windowIndex — Integer: current window index from 0 to TradeCount()-1. A negative or missing index produces a blank result. This is not serial.

Return value

string: saved partner name; empty string if there is no window/name. The container item name is not used.

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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.

var result = UO.TradeName(0);
UO.Print("TradeName: " + Convert.ToString(result));

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.TradeName(0);
UO.Print(Convert.ToString(value));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • total — snapshot of the number of windows; index - current index/number. The enumeration example does not confirm anything. In GetTradeContainer two calls read their container (1) and someone else's (2) of the first window (1).
return  RunScenario();
 object? RunScenario()
{
    var total = UO.TradeCount();
    for (int index = (int)(0); index <= total - 1; index += (int)(1))
    {
        var value = UO.TradeName(index);
        UO.Print(Convert.ToString(index) + ": " + Convert.ToString(value));
    }

    return null;
}

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeValue(0);
        UO.Print(Convert.ToString(value));
        return null;
    }

    dynamic ReadTradeValue(dynamic index)
    {
        var total = UO.TradeCount();
        if (Truth(index < 0) || Truth(index >= total + 0))
        {
            return "";
        }

        return UO.TradeName(index);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.TradeName(windowIndex) — UO.TradeName(Any)

Parameters: windowIndex (Any)

Result: string / String.

During a call:

Internal implementation code; this is not a standalone script.

public string TradeName(InjectionValue windowIndex) => bridge.TradeName(NumberConversions.ToInt(windowIndex));

UO.TradeOpponent

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

C# signatures

string UO.TradeOpponent(object? windowIndex);

Returns serial of the partner container as a hex string; this is not a ID character.

Parameters

  • windowIndex — Integer: current window index from 0 to TradeCount()-1. A negative or missing index produces a blank result. This is not serial.

Return value

string: hex serial of someone else's container ID2; "0x00000000" if there is no window. For a ID character use GetTradeOpponent(index + 1).

Behavior

  • GetTradeContainer/GetTradeOpponent/GetTradeOpponentName/ConfirmTrade/CancelTrade number windows with 1; TradeContainer/TradeOpponent/TradeName and all forms of TradeCheck - from 0. This is an obvious compatibility of this client: external reference books for different engines use different reference points.
  • Reading is performed on the game thread using live windows of the current world. Closed windows do not count. Read calls do not send packets and do not wait for a response. The order of UI can change when opening, closing and moving the window to the top; the number is not a permanent identifier.
  • ConfirmTrade and its TradeCheck record send the packet only when consent changes. Someone else's consent is determined by the server. CancelTrade sends the cancellation once. 1/true is local state/processing and not a guarantee of completion of the exchange. Names and both agreements do not prove that the composition of the items has not changed.

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.

var result = UO.TradeOpponent(0);
UO.Print("TradeOpponent: " + Convert.ToString(result));

1. Direct reading or action - direct script

Parameters and execution flow:

  • The call is made once, the result is stored in value/result. 0 is the first index, 1 is the first number (see the syntax of this command). HEX shows numeric serial; Convert.ToString — number or string.
var value = UO.TradeOpponent(0);
UO.Print(Convert.ToString(value));

2. Other Script and Options - Script Function

Parameters and execution flow:

  • total — snapshot of the number of windows; index - current index/number. The enumeration example does not confirm anything. In GetTradeContainer two calls read their container (1) and someone else's (2) of the first window (1).
return  RunScenario();
 object? RunScenario()
{
    var total = UO.TradeCount();
    for (int index = (int)(0); index <= total - 1; index += (int)(1))
    {
        var value = UO.TradeOpponent(index);
        UO.Print(Convert.ToString(index) + ": " + Convert.ToString(value));
    }

    return null;
}

3. Complete Helper with All Features - Script Class

Parameters and execution flow:

  • The helper is given in full and is actually called from Main. Range/ID checks reduce the risk of error, but multiple calls are not atomic: the window can change between them. For action expectedPartner — saved serial character; this is not a review of the price or content of the exchange.
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 value = ReadTradeValue(0);
        UO.Print(Convert.ToString(value));
        return null;
    }

    dynamic ReadTradeValue(dynamic index)
    {
        var total = UO.TradeCount();
        if (Truth(index < 0) || Truth(index >= total + 0))
        {
            return "0x00000000";
        }

        return UO.TradeOpponent(index);
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

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.TradeOpponent(windowIndex) — UO.TradeOpponent(Any)

Parameters: windowIndex (Any)

Result: string / String.

During a call:

Internal implementation code; this is not a standalone script.

public string TradeOpponent(InjectionValue windowIndex) => NumberConversions.ToHex(bridge.TradeOpponent(NumberConversions.ToInt(windowIndex)));

Clone this wiki locally