Log in

View Full Version : FindFallyRoadColor Failing



Fizzi
07-09-2007, 07:40 PM
I'm trying to use this in my script and it's failing often. Maybe it's just me?

Wondering if anyone else is having this problem.

Here
07-09-2007, 07:43 PM
Maybe you can show how you're using it, so we can see WHAT's failing.

nielsie95
07-09-2007, 07:45 PM
Yes, it isn't always working.. Post the color it's missing and Tara should be able to see what's wrong :)

If you want to find the color now; try the procedure FindFaladorRoadColor. Make sure you add {.Include SRL/SRL/Misc/FaladorColorFinder.SCAR} though :)

Sumilion
07-09-2007, 07:48 PM
Or try my function :) (*cough* does require you to login + out once!!! *coug*)

function SumFindRoadColor(FalaColor: Boolean): Integer;
var
arRoadPoints: TPointArray;
GenericColor, a, b: Integer;
arRoughRoadColors, arRoadColors: array of Integer;
WeGotIt: Boolean;
ResultString: string;
begin
if(FalaColor)then
GenericColor := 6057843
else
GenericColor := 5921377;
if(FalaColor)then
ResultString := 'Fala';
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(10.0, 0.03);
FindColorsTolerance(arRoadPoints, GenericColor, MMX1, MMY1, MMX2, MMY2, 50);
ColorToleranceSpeed(1);
arRoughRoadColors := GetColors(arRoadPoints);
for a := 0 to GetArrayLength(arRoughRoadColors) - 1 do
begin
WeGotIt := False;
if(arRoughRoadColors[a] > 5000000)and(arRoughRoadColors[a] < 8000000)then
begin
for b := 0 to GetArrayLength(arRoadColors) - 1 do
begin
if(arRoadColors[b] = arRoughRoadColors[a])then
WeGotIt := True;
end;
if not(WeGotIt)then
begin
if(CountColor(arRoughRoadColors[a], MMX1, MMY1, MMX2, MMY2) > 200)then
begin
if(rs_OnMinimap(arRoadPoints[a].x, arRoadPoints[a].y))then
begin
//Writeln(IntToStr(arRoughRoadColors[a]));
SetArrayLength(arRoadColors, GetArrayLength(arRoadColors) + 1);
arRoadColors[GetArrayLength(arRoadColors) - 1] := arRoughRoadColors[a];
end;
end;
end;
end;
end;
if not(GetArrayLength(arRoadColors) = 1)then
begin
Writeln('Failed to find the road using SumFindRoadColor.');
Writeln('Trying default autocoloring.');
if(FalaColor)then
Result := FindFallyRoadColor
else
Result := FindRoadColor;
end else
Result := arRoadColors[0];
Writeln('RoadColor = '+IntToStr(Result));
if(Result = 0)then
begin
Writeln('Failed to find the road color.');
Writeln('Leaving it what it was.');
if(FalaColor)then
Result := FalaRoadColor
else
Result := RoadColor;
end;
end;

stuckman
07-09-2007, 08:07 PM
yeah i found that too
it quite often picks the colour of the compass point so to make it work i have to tilt the compass a bit

tarajunky
07-09-2007, 08:09 PM
Yes, I've noticed this too. It's because it sometimes picks a color on the client surrounding the minimap rather than the Fally roadcolor. This happens because the search begins from the top left, so the first colors it picks up are the ones on the client.

I fixed that by starting the search from the center of the minimap. You can replace the AutoColor.scar with this updated version I've attached to fix that problem.

It should work fine in fally, but it may pick up the wrong color again if there isn't a fally road on the screen. There is a new function in Divi that checks if a point is on the minimap that could be used to solve this as well, but I need to find out how to use it first. :)

Edit: See my next post below for the updated AutoColor.scar

stuckman
07-09-2007, 08:18 PM
thanks tarajunky
just replaced my autocolour with your newer one and now i am off to test my walking out

nielsie95
07-09-2007, 08:19 PM
There is a new function in Divi that checks if a point is on the minimap that could be used to solve this as well, but I need to find out how to use it first. :)


for a:= 0 to l-1 do
if rs_OnMiniMap(P[a].x, P[a].y) then
begin
TestColor := GetColor(P[a].x, P[a].y);


:)

Sumilion
07-09-2007, 08:24 PM
Hmmm...

In your AutoColor.scar, we see this :


x:=MMCX;
y:=MMCY;
FindColorsSpiralTolerance(x, y, P, GC, MMX1, MMY1, MMX2, MMY2, 50);

However FindColorsSpiralTolerance doesnt request 2 var parameters, they can be constant ... so :


FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 50);

And i took the liberty of adding the function your talking about, rs_OnMinimap();

Here we go :

*REMOVED*

tarajunky
07-09-2007, 08:42 PM
Thanks to everyone for the help. :) I updated all my Autocolor functions to search from the center of the minimap and to use rs_OnMiniMap. This should fix FindFallyRoadColor completely, and will be an added failsafe for the others.

I'll remove my earlier attached file, and if everyone else could remove their attached files as well, we can hopefully reduce any confusion. Thanks!

I'll post this on the SRL 3.81 download section as well.

Sumilion
07-09-2007, 08:46 PM
Thanks to everyone for the help. :) I updated all my Autocolor functions to search from the center of the minimap and to use rs_OnMiniMap. This should fix FindFallyRoadColor completely, and will be an added failsafe for the others.

I'll remove my earlier attached file, and if everyone else could remove their attached files as well, we can hopefully reduce any confusion. Thanks!

I'll post this on the SRL 3.81 download section as well.

No problem!
Always glad when i can help a noobie out :) :stirthepot:

3Garrett3
07-09-2007, 08:50 PM
Thanks tara, do you know if FindDirtRoadColor works anymore? I tested it with 3.6, and it didnt. I was thinking of updating my script though, but I cant get any other autocolor methods to work for it either.

tarajunky
07-09-2007, 08:57 PM
Thanks tara, do you know if FindDirtRoadColor works anymore? I tested it with 3.6, and it didnt. I was thinking of updating my script though, but I cant get any other autocolor methods to work for it either.

I think it works, but I haven't tested it lately. It's not designed to detect the new dirt roads in Varrock. It should work in Barb village and between Draynor and Lumby though.

Fizzi
07-09-2007, 09:36 PM
Thank you very much everyone :). The new AutoColor is working perfectly.

Sumilion
07-09-2007, 09:55 PM
Thanks tara, do you know if FindDirtRoadColor works anymore? I tested it with 3.6, and it didnt. I was thinking of updating my script though, but I cant get any other autocolor methods to work for it either.

Need one for varrock ?

SKy Scripter
07-10-2007, 05:45 AM
* cough * :)


program New;


{.include srl/srl.scar}

procedure XYZtoLab(X, Y, Z : Extended; var L, A, B : Extended);
begin
try
L := 10 * Sqrt(Y);
A := 17.5 * (((1.02 * x)-y) / Sqrt(Y));
B := 7 * ((Y-(0.847 * Z)) / Sqrt(Y));
except
end;
end;

procedure LabToXYZ(L, A, B : Extended; var X, Y, Z : Extended);
begin
try
Y := Pow(L / 10, 2);
X := ((A / 17.5 * L / 10) + Y) / 1.02;
Z := -((B / 7 * L / 10) - Y) / 0.847;
except
end;
end;

procedure ColorToLab(color :integer; var L, A, B : Extended);
var
X,Y,Z: Extended;
begin
ColortoXYZ(color, X, Y, Z);
XYZtoLab(X, Y, Z, L, A, B);
end;

function AMin(Data : TIntegerArray) : integer;
var
i : integer;
begin
if (GetArrayLength(Data) = 0) then exit;
Result := Data[0];
for i:= 1 to GetArrayLength(Data)-1 do
if (Data[i] < Result) then
Result := Data[i];
end;

function AMostColor(DataColor : TIntegerArray; x1, y1, x2, y2 : Integer) : Integer;
var
i, most, index, L, count: integer;
begin
L := GetArrayLength(DataColor);
if (L = 0) then Exit;
Most := CountColor(DataColor[0], x1, y1, x2, y2);
for i := 0 to L-1 do
begin
Count := CountColor(DataColor[i], x1, y1, x2, y2);
if (Count > Most) then
begin
Index := i;
Most := Count;
end;
end;
Result := DataColor[index];
end;

procedure RGBToHSV(R, G, B : Integer; var H, S, V : Extended);
var
Delta, MaxRGB, MinRGB : Extended;
begin
try
MaxRGB := AMax([R, G, B]);
MinRGB := AMin([R, G, B]);
Delta := (MaxRGB - MinRGB);
V := MaxRGB;
H := -1.0;
if (MaxRGB <> 0) then S := 255 * Delta / MaxRGB;
if (S <> 0) then
if (R = Trunc(MaxRGB)) then H := (G - B) / Delta else
if (G = Trunc(MaxRGB)) then H := 2 + (B - R) / Delta else
if (B = Trunc(MaxRGB)) then H := 4 + (r - g) / Delta;
H := H * 60;
if ( H < 0) then H := H + 360;
S := S * 100 / 255;
V := V * 100 / 255;
except
Writeln('[RunTime ERROR] : Found Math ERROR');
end;
end;

procedure ColorToHSV(Color : Integer; var H, S, V : Extended);
var
R, G, B : Integer;
begin
ColortoRGB(Color, R, G, B);
RGBToHSV(R, G, B, H, S, V);
end;


function GetFallyRoadColor : Integer;
var
P : TPointArray;
Data : TIntegerArray;
Color, i : integer;
L, A, B, H, S, V : Extended;
begin
if (not(LoggedIn)) then exit;
Flag;
Color := 6187637;
x := MMCX;
y := MMCY;
FindColorsSpiralTolerance(x, y, P, Color, MMX1, MMY1, MMX2, MMY2, 50);
Data := GetColors(P);
for i := 0 to GetArrayLength(Data)-1 do
begin
if (rs_OnMinimap(P[i].x, P[i].y)) then
begin
ColorToHSV(Data[i], H, S, V);
ColorToLab(Data[i], L, A, B);
if (V > 30) and (V < 60) then
if (S > 15) and (S < 35) then
if (H > 30) and (H < 60) then
if (CountColor(Data[i], MMX1, MMY1, MMX2, MMY2) > 100) then
if (B < 0.0) and (B > -10.0) and (A < 30) then
begin
Color := Data[i];
Result := Color;
Writeln('Fally RoadColor = ' + inttostr(Result));
MMouse(P[i].x, P[i].y, 0, 0);
Exit;
end;
end;
end;
Result := AMostColor(Data, MMX1, MMY1, MMX2, MMY2);
if (CountColor(Result, MMX1, MMY1, MMX2, MMY2) < 300) then
Result := 0;
end;

begin
SetUpSrl;
FindRS;
ActivateClient;
Wait(1000);
GetFallyRoadColor;
end.

Wizzup?
07-10-2007, 07:06 AM
Or try my function :) (*cough* does require you to login + out once!!! *coug*)

function SumFindRoadColor(FalaColor: Boolean): Integer;
var
arRoadPoints: TPointArray;
GenericColor, a, b: Integer;
arRoughRoadColors, arRoadColors: array of Integer;
WeGotIt: Boolean;
ResultString: string;
begin
if(FalaColor)then
GenericColor := 6057843
else
GenericColor := 5921377;
if(FalaColor)then
ResultString := 'Fala';
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(10.0, 0.03);
FindColorsTolerance(arRoadPoints, GenericColor, MMX1, MMY1, MMX2, MMY2, 50);
ColorToleranceSpeed(1);
arRoughRoadColors := GetColors(arRoadPoints);
for a := 0 to GetArrayLength(arRoughRoadColors) - 1 do
begin
WeGotIt := False;
if(arRoughRoadColors[a] > 5000000)and(arRoughRoadColors[a] < 8000000)then
begin
for b := 0 to GetArrayLength(arRoadColors) - 1 do
begin
if(arRoadColors[b] = arRoughRoadColors[a])then
WeGotIt := True;
end;
if not(WeGotIt)then
begin
if(CountColor(arRoughRoadColors[a], MMX1, MMY1, MMX2, MMY2) > 200)then
begin
if(rs_OnMinimap(arRoadPoints[a].x, arRoadPoints[a].y))then
begin
//Writeln(IntToStr(arRoughRoadColors[a]));
SetArrayLength(arRoadColors, GetArrayLength(arRoadColors) + 1);
arRoadColors[GetArrayLength(arRoadColors) - 1] := arRoughRoadColors[a];
end;
end;
end;
end;
end;
if not(GetArrayLength(arRoadColors) = 1)then
begin
Writeln('Failed to find the road using SumFindRoadColor.');
Writeln('Trying default autocoloring.');
if(FalaColor)then
Result := FindFallyRoadColor
else
Result := FindRoadColor;
end else
Result := arRoadColors[0];
Writeln('RoadColor = '+IntToStr(Result));
if(Result = 0)then
begin
Writeln('Failed to find the road color.');
Writeln('Leaving it what it was.');
if(FalaColor)then
Result := FalaRoadColor
else
Result := RoadColor;
end;
end;

Familiar code.... ;)

Sumilion
07-10-2007, 08:58 AM
Familiar code.... ;)

Really? Only place i used it in was in my rimmington miner. Care to elaborate ?

tarajunky
07-10-2007, 05:19 PM
He must use your Rimmington miner a lot?? :D

Sumilion
07-10-2007, 05:28 PM
He must use your Rimmington miner a lot?? :D

Apparently :p