[OSR][AeroLib][OSBuddy] Item Overlay Location Finder/Looter
Description:
OSBuddy, a popular client for OSRS, has a feature which will paint ground items onto the screen in the form of a text overlay. This function will search for any overlay text matching the specified text. If found it'll return the on-screen coordinates of the item (not the text) for easy looting.
Features:
- Finds and returns specified item location
- Will return the correct location of the item even if it's in a stack of items, no matter it's location in the stack:
http://i.imgur.com/1J68XKT.png
(searching for any of these items texts would return the coordinates for the item pile below them).
Useful For:
- Adding item finding & looting to a non-reflection script.
- Those who don't want to use SMART
- Those who want to take advantage of reflection in the safest form possible.
Requirements:
- AeroLib
- OSBuddy
- OSBuddy Item Overlay feature set to 'on' AND go into the feature settings and change font to 'Runescape'
Limitations:
- Will not be able to match text that is overlayed with other text. For example when a large amount of items are spread across a small space the text will often overlap.
- Will not be able to correctly get the X coordinate if another item text is within a couple pixels to the right of your item on the same X plane.
- Will not be able to correctly get the Y coordinate if another item text is within a few pixels below your item on the Y plane. It will think your item is in a stack and return the non-existent stacks location (See below for fix. Params: Stack)
Code:
Simba Code:
function GetDropCoordX(Color: Integer; StartPoint: TPoint): TPoint;
var
MPs: TPointArray;
MP: TPoint;
tCol: TColEx;
SB: TBox;
Found: Boolean;
begin
SB := ToBox(StartPoint.x, StartPoint.y-1, StartPoint.x+6, StartPoint.y+7);
tCol.create(Color, 0);
Found := tCol.FindIn(SB, MP);
while Found do
begin
tCol.FindAllIn(SB, MPs);
SB.X1 := SB.X2;
SB.X2 := SB.X2+6;
Found := tCol.FindIn(SB, MP);
end;
SortTPAByX(MPs, False);
MP := Point(MPs[0].x, MPs[0].y);
MP.x := StartPoint.x+(5+((MP.x-StartPoint.x) shr 1));
Result := MP;
end;
function GetDropCoordY(Color: Integer; StartPoint: TPoint): TPoint;
var
MPs: TPointArray;
MP: TPoint;
tCol: TColEx;
SB: TBox;
Found: Boolean;
begin
SB := ToBox(StartPoint.x-4, StartPoint.y-1, StartPoint.x+4, StartPoint.y);
tCol.create(Color, 0);
Found := tCol.FindIn(SB, MP);
while Found do
begin
tCol.FindAllIn(SB, MPs);
SB.Y1 := SB.Y2;
SB.Y2 := SB.Y2+11;
Found := tCol.FindIn(SB, MP);
end;
SortTPAByY(MPs, False);
MP := Point(StartPoint.x, MPs[0].y+20);
Result := MP;
end;
function OSB_FindItem(var ItemPoint: TPoint; ItemText: String; Area: TBox; Stack: Boolean): Boolean;
var
TextTPA, SearchTPA, Matches: TPointArray;
Height: Integer;
tCol: TColEx;
begin
tCol.autoCreate([16777215,16448764,16316664]);
if not tCol.findAllIn(Area, SearchTPA) then
Exit(False);
TextTPA := loadTextTPA(ItemText, 'SmallChars07', Height);
Result := FindTextTPAinTPA(Height, TextTPA, SearchTPA, Matches);
if not Result then
Exit;
ItemPoint := GetDropCoordX(16777215, Matches[0]);
case Stack of
True : ItemPoint := GetDropCoordY(16777215, ItemPoint);
False: ItemPoint.y += 23;
end;
end;
Params:
- ItemPoint: Function will fill this referenced variable with the TPoint of the item.
- ItemText: Text matching the item you want to find on screen. You do not need to provide the full item name for a match, but you will need to provide the start of it. For example to find a cabbage, "Cab" will work but "bage" will not. Be wary as any items with the same chars will match. CASE SENSITIVE
- Area: TBox of the area you want to look for the item in.
- Stack: Tells the function if it should look to see if the item is in a stack of items. Leave this to True to start with as it's most accurate and will match perfectly fine even if the item is by itself. Set to False if the item wasn't in the location specified when Stack = True.
Example usage:
Like most finder functions, this function only returns the TPoint it believes the item you specified is at. It's up to the scripter to make the correct fail safes with that information to ensure smooth looting.
A basic example with a fail safe covering the Stack paramater mentioned above:
Simba Code:
var
ItemLoc: TPoint;
begin
InitAL;
if OSB_FindItem(ItemLoc, 'Cabbage', AREA_MS, True) then
begin
accurateMMouse(ItemLoc, 0,0);
if waitUptext('Cabbage',600) then
FastClick(Mouse_Left)
else
if OSB_FindItem(ItemLoc, 'Cabbage', AREA_MS, False) then
begin
accurateMMouse(ItemLoc, 0,0);
if waitUptext('Cabbage',600) then
FastClick(Mouse_Left);
end;
end;
end.
I don't imagine this will be used by too many as I believe the number of people who match the 'useful for' section isn't that high, but it's here if anyone needs it. There's a few improvements I can make if some Simba-side issues can be resolved, if they can't I'll eventually get round to rewriting the heavy lifting function that makes the above code work.