MainScreen

Methods to interact with the game mainscreen.


TRSObjectFinder

TRSObjectFinder is the record used in MainScreen.FindObject.

  • TRSObjectFinder.Zoom

    When designing a object finder you must be at default zoom(50) in the fixed client mode. This allows SRL to convert the finder to work at any zoom and client mode once made.

    _images/zoom.png

    A finder working at different zoom levels producing similar results.

  • TRSObjectFinder.Colors

    An color array which will searched for. Use ACA to acquire color(s).

    Finder.Colors += CTS2(2503237, 20, 0.10, 0.14); // brown
    Finder.Colors += CTS2(5526875, 15, 0.19, 0.06); // grey
    
    _images/color_array.png

    The two colors above found and merged together.

  • TRSObjectFinder.ColorClusters

    An array of “color clusters” which will be merged together. Use ACA to acquire color(s).

    A “color cluster” consists of a primary and secondary color and a distance value. When searched for only primary colors within distance of secondary colors are returned.

Finder.ColorClusters += [
CTS2(2503237, 20, 0.10, 0.14), // brown
CTS2(5526875, 15, 0.19, 0.06), // grey
2                              // distance
];
_images/color_cluster.png

The above color cluster found where “brown” is within 2 pixels of “grey”.

  • TRSObjectFinder.Erode

    The amount to erode before clustering. This is useful for removing small amounts of noise.

    Finder.Erode := 2;
    
    _images/erode.png

    Erode before and after.

  • TRSObjectFinder.Grow

    The amount to grow before eroding. This is useful for filling gaps.

    Finder.Grow := 2;
    
    _images/grow.png

    Grow before and after.

    Grow can also be paired with erode which is quite powerful.

    Finder.Grow := 3;
    Finder.Erode := 4;
    
    _images/grow_erode.png

    Grow paired with Erode.

  • TRSObjectFinder.ClusterDistance

    The distance to pass to ClusterTPA, this is how multiple objects are grouped up. Distance=5 would mean that points that are closer than or equal to 5 pixels away are considered close enough to merge into a singular group.

    Finder.ClusterDistance := 5;
    
    _images/cluster_5.png

    Cluster distance 5 produces four individual chairs

    Finder.ClusterDistance := 20;
    
    _images/cluster_20.png

    Cluster distance 20 produces two sets of chairs

  • TRSObjectFinder.MinLongSide, TRSObjectFinder.MaxLongSide, TRSObjectFinder.MinShortSide, TRSObjectFinder.MaxShortSide

Any match that exceeds these values will be removed. The bounding rectangle is used which has a long and a short side measured in pixels.

// Removes matches where the short side isn't within 10 and 20 pixels
Finder.MinShortSide := 10;
Finder.MaxShortSide := 20;
// Removes matches where the long side isn't within 20 and 40 pixels
Finder.MinLongSide := 20;
Finder.MaxLongSide := 40;
_images/bounding_rect.png

Example bounding rectangle with a long and short side.


MainScreen.Setup

procedure TRSMainScreen.Setup(ClientMode: ERSClientMode);

Setups the mainscreen.

Note

This is automatically called on the MainScreen variable.


MainScreen.GetUpText

function TRSMainScreen.GetUpText(): String;

Returns the current uptext. Uptext is the top left which appears when moving the mouse over a object.

Example:

WriteLn(MainScreen.GetUpText());

MainScreen.IsUpText()

function TRSMainScreen.IsUpText(Text: TStringArray; Timeout: Int32 = -1): Boolean;
function TRSMainScreen.IsUpText(Text: String; Timeout: Int32 = -1): Boolean; overload;

Returns true if the uptext is found anywhere. If a TStringArrayis passed as Text, any match will result true.

Example:

WriteLn(MainScreen.MainScreen.IsUpText(['Chicken', 'Wolf']));

MainScreen.SetHighestPitch

procedure TRSMainScreen.SetHighestPitch();

Moves the camera to the highest pitch. There is no way to detect the camera pitch reliably using color, this is why SRL only provides this method.

Example:

MainScreen.SetHighestPitch();

MainScreen.NormalizeDistance

function TRSMainScreen.NormalizeDistance(Dist: Int32; Accuracy: Single = 1.05): Int32;

Converts a distance acquired from the *fixed client and default zoom to the current mainscreen.

Example:

// 20 pixels on the fixed client and default zoom(50) is currently x pixels at the current zoom & client size.
WriteLn(MainScreen.TranslateDistance(20));

MainScreen.GetPlayerBox()

function TRSMainScreen.GetPlayerBox(): TBox;

Returns a box surrounding our player. Works at any zoom level. Implemented in MM2MS: MainScreen.GetPlayerBox() override


MainScreen.FacePoint

function TRSMainScreen.FacePoint(P: TPoint; Randomness: Int32 = 0): Boolean;

Rotates the camera to face point P. Implemented in MM2MS: MainScreen.FacePoint() override


Mainscreen.PointToMM

function TRSMainScreen.PointToMM(MS: TPoint; Height: Int32 = 0; Accuracy:Double = 0.2): Vector3;

Takes a mainscreen point and converts it to a point on the minimap. Implemented in MM2MS: MainScreen.PointToMM() override


Mainscreen.FindObject()

function TRSMainScreen.FindObject(Finder: TRSObjectFinder; area: TBox): T2DPointArray;
function TRSMainScreen.FindObject(Finder: TRSObjectFinder): T2DPointArray; overload;

Returns all matches of an TRSObjectFinder in the desired area. If no area is specified, the whole mainscreen is used.

See the top of this page page for documentation about the TRSObjectFinder record.

Example:

var MyFinder: TRSObjectFinder;
begin
  // Some chairs in varrock west bank
  MyFinder.Colors += CTS2(1328725, 6, 0.06, 0.69);
  MyFinder.ClusterDistance := 5;
  MyFinder.Erode := 2;
  MyFinder.MinLongSide := 10;
  MyFinder.MaxLongSide := 15;

  Debug(MainScreen.FindObject(MyFinder, MainScreen.Bounds()));
end;

Mainscreen.IsVisible

function TRSMainScreen.IsVisible(p: TPoint): Boolean;
function TRSMainScreen.IsVisible(tpa: TPointArray; useCenter: Boolean = True): Boolean; override;
function TRSMainScreen.IsVisible(b: TBox; useCenter: Boolean = True): Boolean; overload;
function TRSMainScreen.IsVisible(rect: TRectangle; useCenter: Boolean = True): Boolean; overload;
function TRSMainScreen.IsVisible(cuboid: TCuboidEx; useCenter: Boolean = True): Boolean; overload;

Returns true if the TPoint, TPointArray, TBox, TRectangle or TCuboid is visible (not hidden by any other interfaces) on the mainscreen.

This is only useful in resizable mode. The interfaces checked are Chatbox, Minimap and Gametabs.

Example:

if MainScreen.IsVisible([100, 100]) then
  WriteLn('The point is not behind Chatbox, Minimap or Gametabs.');

MainScreen.Filter

function TRSMainScreen.Filter(arr: TPointArray): TPointArray;
function TRSMainScreen.Filter(arr: TBoxArray): TBoxArray; overload;
function TRSMainScreen.Filter(arr: TRectArray): TRectArray; overload;
function TRSMainScreen.Filter(arr: TPolyArray): TPolyArray; overload;

Filters the given TPointArray, TBoxArray, TRectArray or TCuboidArray and returns only those that are visible in the MainScreen.


type TRSHitsplat

TRSHitsplat = record
  Position: TPoint;  // Middle of the found hitsplat
  Hit: Int32;        // Hit amount
  Red: Boolean;      // True if red, false if blue.
end;

TRSHitsplatArray = array of TRSHitsplat;

Mainscreen.FindHitsplats

function TRSMainScreen.FindHitsplats(area: TBox): TRSHitsplatArray;
function TRSMainScreen.FindHitsplats(): TRSHitsplatArray; overload;

Finds hitsplats in the desired area if specified or the entire mainscreen. Returns an array of TRSHitsplat.

Example:

var
  splat: TRSHitsplat;
begin
  for splat in MainScreen.FindHitsplats() do
  begin
    Debug(splat);
    WriteLn(splat.Hit);
    Wait(2000);
  end;
end;

type TRSHPBar

TRSHPBar = record
  Bounds: TBox;       // Bounds of the bar
  Percent: Double;  // Green percent of the bar.
end;

Mainscreen.FindHPBars()

function TRSMainScreen.FindHPBars(area: TBox): TRSHPBarArray;
function TRSMainScreen.FindHPBars(): TRSHPBarArray; overload;

Finds hitpoints bars in the desired area. Returns an array of TRSHPBar. If no area is specified the whole mainscreen is used.

Example:

var Bars: TRSHPBarArray;
var I: Int32;
begin
  Bars := MainScreen.FindHPBars(MainScreen.Bounds());
  for I := 0 to High(Bars) do
    WriteLn(Bars[I].Percent, ' @ ', Bars[I].Bounds);
end;

Mainscreen.FindClick

function TRSMainScreen.FindClick(Area: TBox): ERSClickType;

Finds a click type in the desired area. Will return either:

  • RS_CLICK_NONE

  • RS_CLICK_RED

  • RS_CLICK_YELLOW

Example:

if MainScreen.FindClick([50,50,100,100]) = RS_CLICK_RED then
  WriteLn('Found a red click in 50,50,100,100');

Mainscreen.DidRedClick

function TRSMainScreen.DidRedClick(time: UInt32 = 250): Boolean;

Returns true if a red click happened at the current mouse position.

Example:

Mouse.Move(100, 100);
Mouse.Click(MOUSE_LEFT);
if MainScreen.DidRedClick() then
  WriteLn('Red click!');

Mainscreen.DidYellowClick


Returns true if a yellow click happened at the current mouse position.

Example:

Mouse.Move(100, 100);
Mouse.Click(MOUSE_LEFT);
if MainScreen.DidYellowClick() then
  WriteLn('Yellow click!');