Objects

This page is about Objects which are an interface for interacting with game objects.


TGObject

Main type to handle Objects.


TGObjectArray

Array of TGObject.


TGObject.Create

function TGObject.Create(var walker: TWalker; size: TVector3; coordinates: TPointArray; uptext: TStringArray = []): TGObject; static;
function TGObject.Create(var walker: TWalker; json: TJSONObject): TGObject; static; overload;

Create function to create your TGObject.

Assuming you create the RSObject manually, the create function will provide you with a fully built TGObject without a finder.

You may optionally assign one later if you want:

{$I WaspLib/main.simba}
var
  obj: TGObject;
begin
  Map.Setup([EChunk.VARROCK]);
  obj := TGObject.Create(Map.Walker, [1,1,7], [[8648,36686]], ['Bank booth']);
  //obj.Finder.Colors += $FFFFFF;
end;

The json version of the function expects a specific json structure which is the one that Map JSONs provide:

{$I WaspLib/main.simba}
var
  obj: TGObject;
begin
  Map.Setup([EChunk.VARROCK]);
  //Item[0] because this returns a JSON array. For more info read Map JSONs documentation.
  obj := TGObject.Create(Map.Walker, ObjectsJSON.GetByName('bank', 1).Item[0]);
end;

TGObjectArray.Create

function TGObjectArray.Create(var walker: TWalker; json: TJSONArray): TGObjectArray; static; overload;

Create function to build your TGObjectArray.

This only accepts a json array and it expects a specific json structure which is the one that Map JSONs provide.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(Map.Walker, ObjectsJSON.GetByName('Bank booth'));
end;

RSObject.Rotation

TGObject.Rotations: TIntegerArray;

Rotations allows you to customize the rotation of a TGObject. By default unless you used ObjectsJSON to create your object they will no rotation set, AKA 0.

It’s very important that Rotations is the same length as Coordinates as they complement each other, each coordinate needs to have a rotation value.

The rotation you want o set should be the respective angle of the object rotated on it’s center:

{$I WaspLib/main.simba}
var
  furnace: TGObject;
begin
  Map.Setup([EChunk.FALADOR]);
  furnace := TGObject.Create(@Map.Walker, [2, 3, 6], [[7810, 36954]], ['Furnace']);
  while True do
  begin
    furnace.Rotations[0] += 1;
    ShowOnTarget(furnace);
  end;
end.
../../images/obj_rotation.gif

RSObject._GetBounds

function TGObject._GetBounds(me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid;

Internal helper function for TGObject.GetBoundsArray.


RSObject.GetBoundsArray

function TGObject.GetBoundsArray(me: TPoint; angle: Single = $FFFF): TCuboidArray;

Internal function that returns an array of cuboids of the object if it’s coordinates are visible on the MainScreen.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  cuboids: TCuboidArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  cuboids := objs[1].GetBoundsArray(Map.Position());
  ShowOnTarget(cuboids);
end.
../../images/objs_cuboids.png

RSObject.FindOnMainScreen

function TGObject.FindOnMainScreen(cuboidArray: TCuboidArray): T2DPointArray;

Internal TGObject method responsible for filtering a TCuboidArray by what’s visible in the mainscren.

This is meant to filter TGObject.GetBoundsArray so targets that are outside of the mainscreen are filtered out.

You will probably never need to use this directly.


RSObject.FindEx

function TGObject.FindEx(me: TPoint; out boundsArray: TPolygonArray; out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;

Internal TGObject method used to find a RSObject. If found returns true, if not returns false.

You also have RSObject.Find to find objects, this version of the method is internal because it returns extra information about the found objects for internal use, like it’s cuboids for example.

This also returns an atpa containing the colors of the object that were found assuming the object has a TColorFinder setup. If not, the cuboids area are returned as the match.

This extra information is easy to see when you debug your object with ShowOnTarget(TGObject):

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  ShowOnTarget(objs[1]);
end.
../../images/objs_showontarget.png

As you can see, this image is very similar to the one in RSObject.GetBoundsArray, they differ however in the fact that this one, aside from the cuboids also shows the object colors that were found within the cuboids.

This object colors is what’s returned through the atpa and is what would be clicked if you use RSObject.Click for example.

Assuming your RSObjectdoes not have a TColorFinder setup, this is what it would look like:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].Finder := []; //removing the finder for this example.
  ShowOnTarget(objs[1]);
end.
../../images/objs_nofinder.png

RSObject.Find

function TGObject.Find(out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
function TGObject.Find(out atpa: T2DPointArray): Boolean; overload;

TGObject method used to find a RSObject. This returns True/False if the object was found and it’s atpa which cointains the colors of it that were found.

For more information on this refer to RSObject.FindEx, it’s an internal function but is used within this one and will go into more detail.


RSObject.IsVisible

function TGObject.IsVisible(): Boolean;

Returns a boolean whether the object is currently visible or not.


RSObject.FindFrom

function TGObject.FindFrom(position: TPoint; out atpa: T2DPointArray): Boolean;

This is similar to RSObject.Find but differs from it in that you can set your position.

This is only useful when you want to predict an object position as if you were somewhere else you are not.

What you use this for is up to you but an example use case is to pre-hover objects before you reach a position you know you will be at in the future.

For example, imagine a slow agility obstacle on an agility course. Imagine you want to click the obstacle and hover the next. You know where you will be after you get through the current obstacle so you can use this to set your position to where you will be after the current obstacle and hover the next one:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].Finder := [];

  while True do
  begin
    ShowOnTarget(atpa);
    objs[1].FindFrom([8912,36742], atpa);
  end;
end.
../../images/obj_findfrom.gif

As you can see on the gif above, the objects debug match the object exactly when you are at the right coordinate.

For this I also recommend to not have a TColorFinder setup because it will only match when you are at the right position.


RSObject._UpTextCheck

function TGObject._UpTextCheck(out shouldExit: Boolean; action: TStringArray): Boolean;

Internal TGObject helper method that is used by all hovering methods.

You probably don’t need to use this directly.


RSObject.PreHover

function TGObject.PreHover(me: TPoint; attempts: Integer = 2): Boolean;

To understand what this does it’s recommended to read RSObject.FindFrom.

This method basically uses RSObject.FindFrom and moves the mouse to one of the matches.


RSObject._HoverHelper

function TGObject._HoverHelper(strings: TStringArray; attempt, attempts: Integer): Boolean; static;

Internal TGObject helper method that is used by both TGObject.Hover and TEntity.Hover. You probably don’t need to use this directly.


RSObject._WalkHoverHelper

function TGObject._WalkHoverHelper(strings: TStringArray; walker: PRSWalker; dist, attempt, attempts: Integer; coordinates: TPointArray): Boolean; static;

Internal TGObject helper method that is used by both TGObject.WalkHover and TEntity.WalkHover. You probably don’t need to use this directly.


RSObject._ClickHelper

function TGObject._ClickHelper(leftClick: Boolean): Boolean;

Internal TGObject helper method that is used by other clicking methods. You probably don’t need to use this directly.

This is what’s responsible for deciding if we click a target we are hovering or not.


RSObject._SelectHelper

function TGObject._SelectHelper(action: TStringArray): Boolean;

Internal TGObject helper method that is used by other select methods.

You probably don’t need to use this directly.

This is what is responsible for deciding if we just left click a target we are hovering or right click it and choose an option.


RSObject.Hover

function TGObject.Hover(action: TStringArray = []; attempts: Integer = 2): Boolean;

Method used to hover a TGObject target if it’s found on the mainscreen.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].Hover();
end.
../../images/obj_hover.gif

RSObject.WalkHover

function TGObject.WalkHover(action: TStringArray = []; attempts: Integer = 2): Boolean;

Method used to walk towards and hover a TGObject target if it’s found on the mainscreen.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].WalkHover();
end.
../../images/obj_walkhover.gif

In the gif above the function exited true before we finished walking which is why it’s not hovering the bank after we finished walking.

The way this works is that if we successfully hover the bank while walking it returns true.


RSObject.Click

function TGObject.Click(leftClick: Boolean = True; attempts: Integer = 2): Boolean;

Method used to click a TGObject target if it’s found on the mainscreen.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].Click();
end.
../../images/obj_click.gif

RSObject.Interact

function TGObject.Interact(action: TStringArray; attempts: Integer = 2): Boolean;

Method used to select an option on a TGObject target if it’s found on the mainscreen.

Through action you can specify the interaction you are looking for. If this interaction is the uptext when you hover the object WaspLib will simply left click it.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].Interact(['Collect']);
end.
../../images/obj_select.gif

RSObject.WalkClick

function TGObject.WalkClick(leftClick: Boolean = True; attempts: Integer = 2): Boolean;

Method used to walk towards and click a TGObject target if it’s found on the mainscreen.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].WalkClick();
end.
../../images/obj_walkclick.gif

RSObject.WalkInteract

function TGObject.WalkInteract(action: TStringArray; attempts: Integer = 2): Boolean;

Method used to walk towards and select an option on a TGObject target if it’s found on the mainscreen.

Through action you can specify the interaction you are looking for. If this interaction is the uptext when you hover the object WaspLib will simply left click it.

Example:

{$I WaspLib/main.simba}

var
  objs: TGObjectArray;
  atpa: T2DPointArray;
begin
  Map.Setup([EChunk.VARROCK]);
  objs := TGObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
  objs[1].WalkInteract(['Collect']);
end.
../../images/obj_walkselect.gif

RSObject.DistanceTo

function TGObject.DistanceTo(pt: TPoint): Double;

Returns the distance of an object to you. Because Objects can have multiple coordinates, only the closest one is considered for the calculation.

This is useful to for example, compared which of 2 objects are closest to you.

Example:

me := Map.Position();

if bankBooth.DistanceTo(me) < bankChest.DistanceTo(me) then
  bankBooth.WalkClick()
else
  bankChest.WalkClick();

RSObjectArray.ClosestIndex

function TGObjectArray.ClosestIndex(pt: TPoint): Integer;

Returns the index of the TGObjectArray which is closest to you.

Uses RSObject.DistanceTo on each of the indices of the current TGObjectArray and returns the closest index.


DrawObject

procedure TImage.DrawObject(const obj: TGObject; alpha: Byte = $C8);
procedure TExternalCanvas.DrawObject(const obj: TGObject; alpha: Byte = $C8);

Helper methods to debug TGObjects.


ShowOnTarget TGObject

procedure ShowOnTarget(obj: TGObject); overload;

Shows an image of the target with the TGObject drawn on it.


ShowOnTarget TGObjectArray

procedure ShowOnTarget(objs: TGObjectArray); overload;

Shows an image of the target with the TGObjectArray drawn on it.