SRL Archive - SRL Archives

GetUniqueSymbolColor, Symbol.scar


Blumblebee

2009-11-22 19:27:04

I thought this might be useful, pretty much it finds a unique color on or around (like 3 pixels away) a given symbol. It first autocolors the symbol, then searches for the black around the symbol creating a Tbox, then gets all the colors in the Tbox and finds a unique color inside the box.

I found it works really well with Tree Symbols, and on symbols like Smithing that do not have one unique color, it gets a color right near it. Anyways, here's code (for some reasons its negating the spaces between Functions):

{*******************************************************************************
Function GetSymbolArea(Color: Integer; Hue, Sat: Extended; Tol: Integer): TPointArray;
By: Blumblebee
Description: Gathers Points of a particular color into a TPA Dependant on the Color,
Hue, Sat, and Tol provided.
*******************************************************************************}

Function GetSymbolArea(Color: Integer; Hue, Sat: Extended; Tol: Integer): TPointArray;
var TPA: TPointArray; ATPA: T2DPointArray; P: TPoint; l, i: integer;
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hue, Sat);
FindColorsSpiralTolerance(MMcx, MMcy, TPA, Color, MMx1, MMy1, MMx2, MMy2, Tol);
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
if Length(TPA) <= 0 then Exit;
ATPA := SplitTPAEx(TPA, 5, 5);
for i := 0 to High(ATPA) do
begin
P := MiddleTPA(ATPA[i]);
if rs_OnMiniMap(P.x,P.y) then
begin
l := getarraylength(Result);
SetArrayLength(Result, l+1);
Result[l] := P;
end;
end;
end;

{*******************************************************************************
Function CreateSymbolBox(TPA: TPointArray; TP: TPoint): TBox;
By: Blumblebee
Description: Creates a TBox around a cluster in a TPA. The TBox is created in
reference to the Black outside of the Symbol.
*******************************************************************************}

Function CreateSymbolBox(TPA: TPointArray; TP: TPoint): TBox;
var nTPA, oTPA: TPointArray;
begin
oTPA := TPA;
sortTPAFrom(oTPA, Point(TP.x, TP.y));
FindColorsTolerance(nTPA, 65536, oTPA[0].x-7, oTPA[0].y-7, oTPA[0].x+7, oTPA[0].y+7, 10);
if Length(nTPA) > 0 then
Result := GetTPABounds(nTPA);
end;

{*******************************************************************************
Function FindUniqueColors(Col: Integer; rTPA: TPointArray; Area: TPoint): Integer;
By: Blumblebee
Description: Gathers all Colors inside the "symbol box", and sorts for the most
unique color that is closest to the given color.
*******************************************************************************}

Function FindUniqueColors(Col: Integer; rTPA: TPointArray; Area: TPoint): Integer;
var SymBox: TBox; TPA: TPointArray; List1, List2, List3 : TIntegerArray; i, ii, Tol, L: integer;
begin
SymBox := CreateSymbolBox(rTPA, Area);
FindColorsTolerance(TPA, 0, SymBox.x1, SymBox.y1, SymBox.x2, SymBox.y2, 225);
List1 := GetColors(TPA);
List2 := List1;
ClearSameIntegers(List1);
for i := 0 to High(List2) do
begin
for ii := 0 to High(List1) do
begin
if List1[ii] = List2[i] then
begin
L := getarraylength(List3);
SetArrayLength(List3, L+1);
List3[L] := List1[ii];
end;
end;
end;
Tol := 5;
while Result = 0 do
begin
for i := 0 to High(List3) do
begin
if SimilarColors(List3[i], Col, Tol) then
begin
Result := List3[i];
WriteLn('Unique Symbol Color = '+IntToStr(Result));
Exit;
end;
end;
IncEx(Tol, 1);
end;
end;

{*******************************************************************************
GetUniqueSymbolColor(x, y: Integer; Color: Integer; Hue, Sat: Extended; Tol: Integer): Integer;
By: Blumblebee
Description: Finds the most unique symbol color with the information given.
*******************************************************************************}

Function GetUniqueSymbolColor(x, y: Integer; Color: Integer; Hue, Sat: Extended; Tol: Integer): Integer;
begin
Result := FindUniqueColors(Color, GetSymbolArea(Color, Hue, Sat, Tol), Point(x, y));
end;

an example of using this would be as so:

var r, x, y: Integer;

begin
SetUpSRL;
r := GetUniqueSymbolColor(MMcx, MMy2, 229638, 0.17, 0.45, 15);
FindColor(x, y, r, MMx1, MMy1, MMx2, MMy2);
MMouse(x, y, 3, 3);
end.

debug reads:

Successfully compiled (3571 ms)
SRL Compiled in 16 msec
Unique Symbol Color = 494860


This works for the Tree Symbol in edgeville (as viewed from the bank).

There is an Area parameter (x, y) which allows the user to choose where the script searches from, so that if there is more than one of the same symbol on the MM, it will find the the closest to the point specified.

@Wizzup: I tried to impliment the sorting idea you showed me, but I found I recieved identical results to this one, so I left be.

Gu3st...

2009-11-23 08:09:15

Cool to see you released it :)
Only thing that bugs me is that you have to insert Hue and Sat… :/
EDIT: I found a problem, if the color is the same as the colors around the minimap (brown-ish) then it will click outside the minimap and the script wouldn't work..
EDIT2: I tried finding the "log" symbol in GE, it found a color but the color was the same as the floor in the GE resulting is scar clicking the ground
EDIT3: If there is symbols with the same colors then it will sometime click the wrong symbol.

Naike

2009-11-23 09:28:28

You should add function info on top of all your functions.

Blumblebee

2009-11-23 10:50:34

From: Zyt3x
Cool to see you released it :)
Only thing that bugs me is that you have to insert Hue and Sat… :/
EDIT: I found a problem, if the color is the same as the colors around the minimap (brown-ish) then it will click outside the minimap and the script wouldn't work..
EDIT2: I tried finding the "log" symbol in GE, it found a color but the color was the same as the floor in the GE resulting is scar clicking the ground
EDIT3: If there is symbols with the same colors then it will sometime click the wrong symbol.


Ok, well the MM problem can be fixed by how the player chooses to click I suppose. I may as well write a clicking function too, but I figured that would be overkill. You would simplly have to do something like
FindColorSkipBox()
or just make a more specific area in clicking, I'm not sure how else I could make it more accurate in that respect. an RS_OnMiniMap() check might also be useful for the minimap border problem I'll look into.

From: N1ke!
You should add function info on top of all your functions.


:redface: yeah I'll get on that sorry. edit: Done, I'm really bad at explaining stuff though haha

Nava2

2009-11-23 11:04:18

I don't really see what the point of this is?

Blumblebee

2009-11-23 11:17:20

From: Nava2
I don't really see what the point of this is?


I don't find FindSymbol very accurate, and so when I walk via a symbol I prefer using a TPA. This is pretty much an autocolor for every Symbol allowing you to use it for walking, or a reference color to see if your in a certain area or not.