# RSObjects This page is about {ref}`RSObjects` which are an interface for interacting with game objects. - - - ## TRSObject Main type to handle {ref}`RSObjects`. - - - ## TRSObjectArray Array of {ref}`TRSObject`. - - - ## RSObject.Create ```pascal function TRSObject.Create(walker: PRSWalker; size: TVector3; coordinates: TPointArray; uptext: TStringArray = []): TRSObject; static; function TRSObject.Create(json: TJSONObject): TRSObject; static; overload; ``` Createors to create your {ref}`TRSObject`. Assuming you create the `RSObject` manually, the Createor will provide you with a fully built `TRSObject` without a finder. You may optionally assign one later if you want: ```pascal {$I WaspLib/osrs.simba} var obj: TRSObject; begin Map.Setup([ERSChunk.VARROCK]); obj := TRSObject.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 {ref}`Map JSONs` provide: ```pascal {$I WaspLib/osrs.simba} var obj: TRSObject; begin Map.Setup([ERSChunk.VARROCK]); //Item[0] because this returns a JSON array. For more info read Map JSONs documentation. obj := TRSObject.Create(ObjectsJSON.GetByName('bank', 1).Item[0]); end; ``` - - - ## RSObjectArray.Create ```pascal function TRSObjectArray.Create(json: TJSONArray): TRSObjectArray; static; overload; ``` Create function to build your {ref}`TRSObjectArray`. This only accepts a `json` array and it expects a specific json structure which is the one that {ref}`Map JSONs` provide. Example: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByName('Bank booth')); end; ``` - - - ## RSObject.Rotation ```pascal TRSObject.Rotations: TIntegerArray; ``` `Rotations` allows you to customize the rotation of a `TRSObject`. By default unless you used {ref}`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: ```pascal {$I WaspLib/osrs.simba} var furnace: TRSObject; begin Map.Setup([ERSChunk.FALADOR]); furnace := TRSObject.Create(@Map.Walker, [2, 3, 6], [[7810, 36954]], ['Furnace']); while True do begin furnace.Rotations[0] += 1; ShowOnTarget(furnace); end; end. ``` ```{figure} ../../images/obj_rotation.gif ``` - - - ## RSObject._GetBounds ```pascal function TRSObject._GetBounds(me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid; ``` Internal helper function for {ref}`TRSObject.GetBoundsArray`. - - - ## RSObject.GetBoundsArray ```pascal function TRSObject.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 {ref}`MainScreen`. Example: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; cuboids: TCuboidArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); cuboids := objs[1].GetBoundsArray(Map.Position()); ShowOnTarget(cuboids); end. ``` ```{figure} ../../images/objs_cuboids.png ``` - - - ## RSObject.FindOnMainScreen ```pascal function TRSObject.FindOnMainScreen(cuboidArray: TCuboidArray): T2DPointArray; ``` Internal TRSObject method responsible for filtering a TCuboidArray by what's visible in the mainscren. This is meant to filter {ref}`TRSObject.GetBoundsArray` so targets that are outside of the mainscreen are filtered out. You will probably never need to use this directly. - - - ## RSObject.FindEx ```pascal function TRSObject.FindEx(me: TPoint; out boundsArray: TPolygonArray; out coordinates: TPointArray; out atpa: T2DPointArray): Boolean; ``` Internal {ref}`TRSObject` method used to find a {ref}`RSObject`. If found returns true, if not returns false. You also have {ref}`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 {ref}`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(TRSObject)`: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); ShowOnTarget(objs[1]); end. ``` ```{figure} ../../images/objs_showontarget.png ``` As you can see, this image is very similar to the one in {ref}`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 {ref}`RSObject.Click` for example. Assuming your `RSObject`does not have a {ref}`TColorFinder` setup, this is what it would look like: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].Finder := []; //removing the finder for this example. ShowOnTarget(objs[1]); end. ``` ```{figure} ../../images/objs_nofinder.png ``` - - - ## RSObject.Find ```pascal function TRSObject.Find(out coordinates: TPointArray; out atpa: T2DPointArray): Boolean; function TRSObject.Find(out atpa: T2DPointArray): Boolean; overload; ``` {ref}`TRSObject` method used to find a {ref}`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 {ref}`RSObject.FindEx`, it's an internal function but is used within this one and will go into more detail. - - - ## RSObject.FindFrom ```pascal function TRSObject.FindFrom(position: TPoint; out atpa: T2DPointArray): Boolean; ``` This is similar to {ref}`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: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].Finder := []; while True do begin ShowOnTarget(atpa); objs[1].FindFrom([8912,36742], atpa); end; end. ``` ```{figure} ../../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 ```pascal function TRSObject._UpTextCheck(out shouldExit: Boolean; action: TStringArray): Boolean; ``` Internal `TRSObject` helper method that is used by all hovering methods. You probably don't need to use this directly. - - - ## RSObject.PreHover ```pascal function TRSObject.PreHover(me: TPoint; attempts: Integer = 2): Boolean; ``` To understand what this does it's recommended to read {ref}`RSObject.FindFrom`. This method basically uses {ref}`RSObject.FindFrom` and moves the mouse to one of the matches. - - - ## RSObject._ClickHelper ```pascal function TRSObject._ClickHelper(leftClick: Boolean): Boolean; ``` Internal `TRSObject` 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 ```pascal function TRSObject._SelectHelper(action: TStringArray): Boolean; ``` Internal TRSObject 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 ```pascal function TRSObject.Hover(action: TStringArray = []; attempts: Integer = 2): Boolean; ``` Method used to hover a TRSObject target if it's found on the mainscreen. Example: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].Hover(); end. ``` ```{figure} ../../images/obj_hover.gif ``` - - - ## RSObject.WalkHover ```pascal function TRSObject.WalkHover(action: TStringArray = []; attempts: Integer = 2): Boolean; ``` Method used to walk towards and hover a `TRSObject` target if it's found on the mainscreen. Example: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].WalkHover(); end. ``` ```{figure} ../../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 ```pascal function TRSObject.Click(leftClick: Boolean = True; attempts: Integer = 2): Boolean; ``` Method used to click a `TRSObject` target if it's found on the mainscreen. Example: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].Click(); end. ``` ```{figure} ../../images/obj_click.gif ``` - - - ## RSObject.Interact ```pascal function TRSObject.Interact(action: TStringArray; attempts: Integer = 2): Boolean; ``` Method used to select an option on a `TRSObject` 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: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].Interact(['Collect']); end. ``` ```{figure} ../../images/obj_select.gif ``` - - - ## RSObject.WalkClick ```pascal function TRSObject.WalkClick(leftClick: Boolean = True; attempts: Integer = 2): Boolean; ``` Method used to walk towards and click a `TRSObject` target if it's found on the mainscreen. Example: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].WalkClick(); end. ``` ```{figure} ../../images/obj_walkclick.gif ``` - - - ## RSObject.WalkInteract ```pascal function TRSObject.WalkInteract(action: TStringArray; attempts: Integer = 2): Boolean; ``` Method used to walk towards and select an option on a `TRSObject` 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: ```pascal {$I WaspLib/osrs.simba} var objs: TRSObjectArray; atpa: T2DPointArray; begin Map.Setup([ERSChunk.VARROCK]); objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank')); objs[1].WalkInteract(['Collect']); end. ``` ```{figure} ../../images/obj_walkselect.gif ``` - - - ## RSObject.DistanceTo ```pascal function TRSObject.DistanceTo(pt: TPoint): Double; ``` Returns the distance of an object to you. Because {ref}`RSObjects` 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: ```pascal me := Map.Position(); if bankBooth.DistanceTo(me) < bankChest.DistanceTo(me) then bankBooth.WalkClick() else bankChest.WalkClick(); ``` - - - ## RSObjectArray.ClosestIndex ```pascal function TRSObjectArray.ClosestIndex(pt: TPoint): Integer; ``` Returns the index of the `TRSObjectArray` which is closest to you. Uses {ref}`RSObject.DistanceTo` on each of the indices of the current `TRSObjectArray` and returns the closest index. - - - ## TImage.DrawObject ```pascal procedure TImage.DrawObject(obj: TRSObject); ``` Helper method to debug TRSObjects. - - - ## ShowOnTarget TRSObject ```pascal procedure ShowOnTarget(obj: TRSObject); overload; ``` Shows an image of the target with the `TRSObject` drawn on it. - - - ## ShowOnTarget TRSObjectArray ```pascal procedure ShowOnTarget(objs: TRSObjectArray); overload; ``` Shows an image of the target with the `TRSObjectArray` drawn on it.