nielsie95
2007-05-03 04:24:17
Hey,
I was reading through some threads (Junior VW Clay miner, Cows and FGM by Fakawi (and Wizzup?)) and I noticed that they use a specific dark treecolor that you need to set yourself.
I think that with SRL you don't have to set your own colors :p. So I thought of a way that might work: GetUniqueColor. It scans through the whole MM and gets all similar looking colors and stores them in an array. After that, it will count how many colors there are on the MM (for each color) and compare those stats to a given value (HowManyOnMM). The result will be the count that's the most close to HowManyOnMM.
GetUniqueColor2 –> At the request of Freddy. This uses rs_FindMMColors, no need to set Tolerance in this one.
Example:
This will work for FGM-spot (stand near the tree) + FE and VW bank. So that means Junior's VW Clay Banker + FGM + Cows :D
If you want to test this or get the CountValues I made a little script which I added (Set DebugCount True and fill in the color you want to count).
For now this needs Divi, but if there are people who want/need this in 2.03 I will make it :).
Tell me what you think,
Nielsie95
I was reading through some threads (Junior VW Clay miner, Cows and FGM by Fakawi (and Wizzup?)) and I noticed that they use a specific dark treecolor that you need to set yourself.
I think that with SRL you don't have to set your own colors :p. So I thought of a way that might work: GetUniqueColor. It scans through the whole MM and gets all similar looking colors and stores them in an array. After that, it will count how many colors there are on the MM (for each color) and compare those stats to a given value (HowManyOnMM). The result will be the count that's the most close to HowManyOnMM.
type ColorMatch = Record //Set this as a type at the start of your script
Color, Pixels: Integer;
end;
{*******************************************************************************
function GetUniqueColor(var Color: integer; RefColor, Tol, HowManyOnMM, Range: integer): Boolean;
By: Nielsie95
Description: Will get a similar color with the closest count.
How to use:
-Color: Will result the color that's found
-RefColor: The color that will be used as a refenceColor
-Tol: Tolerance added to RefColor
-HowManyOnMM: A reference count of the colors
-Range: The range that will be added to the count
*******************************************************************************}
function GetUniqueColor(var Color: integer; RefColor, Tol, HowManyOnMM, Range: integer): Boolean;
var
ColorArray: Array of ColorMatch;
Colors: Array of integer;
TempCount, TempCount2, TempColor, i, j: integer;
begin
SetArrayLength(Colors, 0);
for i := MMX1 to MMX2 do
for j := MMY1 to MMY2 do
if Rs_OnMinimap(i, j) then
begin
TempColor := GetColor(i, j);
if SimilarColors(RefColor, TempColor, Tol) then
begin
SetArrayLength(Colors, Length(Colors) +1);
Colors[(Length(Colors)) -1] := TempColor;
end
end
SetArrayLength(ColorArray, 0);
for i := 0 to Length(Colors) -1 do
begin
TempCount := CountColor(Colors[i], MMX1, MMY1, MMX2, MMY2);
if TempCount = HowManyOnMM then
begin
if Colors[i] > 0 then
begin
Color := Colors[i];
Result := True;
WriteLn('Found color with range 0');
Exit;
end
end else
begin
if Colors[i] > 0 then
begin
TempCount2 := HowManyOnMM - TempCount;
if TempCount2 < 0 then TempCount2 := TempCount - HowManyOnMM;
if (TempCount2 < Range) then
begin
SetArrayLength(ColorArray, Length(ColorArray) +1);
ColorArray[(Length(ColorArray)) -1].Color := Colors[i];
ColorArray[(Length(ColorArray)) -1].Pixels := TempCount2;
end
end;
end;
end;
if Length(ColorArray) = 1 then
begin
Color := ColorArray[0].Color;
Result := True;
WriteLn('Found color with range '+IntTostr(ColorArray[0].Pixels));
Exit;
end
try
begin
TempCount := Min(ColorArray[0].Pixels, ColorArray[1].Pixels)
for i := 1 to Length(ColorArray) -2 do TempCount := Min(TempCount, ColorArray[i +1].Pixels);
for i := 0 to Length(ColorArray) -1 do if TempCount = ColorArray[i].Pixels then
begin
Color := ColorArray[i].Color;
Result := True;
WriteLn('Found color with range '+IntTostr(ColorArray[i].Pixels));
Exit;
end
end
except
Result := False;
end;
if not Result then WriteLn('Unique Color NOT found! Please set it yourself.');
end;GetUniqueColor2 –> At the request of Freddy. This uses rs_FindMMColors, no need to set Tolerance in this one.
function GetUniqueColor2(var Color: integer; RefColor, Count, Range: integer): Boolean;
var Colors: TIntegerArray; i, TempCount, TempCount2: integer; ColorArray: Array of ColorMatch;
begin
ColorToleranceSpeed(2);
Colors := rs_FindMMColors(RefColor);
SetArrayLength(ColorArray, 0);
for i := 0 to Length(Colors) -1 do
begin
TempCount := CountColor(Colors[i], MMX1, MMY1, MMX2, MMY2);
if TempCount = Count then
begin
if Colors[i] > 0 then
begin
Color := Colors[i];
Result := True;
WriteLn('Found color with range 0');
Exit;
end
end else
begin
if Colors[i] > 0 then
begin
TempCount2 := Count - TempCount;
if TempCount2 < 0 then TempCount2 := TempCount - Count;
if (TempCount2 < Range) then
begin
SetArrayLength(ColorArray, Length(ColorArray) +1);
ColorArray[(Length(ColorArray)) -1].Color := Colors[i];
ColorArray[(Length(ColorArray)) -1].Pixels := TempCount2;
end
end;
end;
end;
if Length(ColorArray) = 1 then
begin
Color := ColorArray[0].Color;
Result := True;
WriteLn('Found color with range '+IntTostr(ColorArray[0].Pixels));
Exit;
end
try
begin
TempCount := Min(ColorArray[0].Pixels, ColorArray[1].Pixels)
for i := 1 to Length(ColorArray) -2 do TempCount := Min(TempCount, ColorArray[i +1].Pixels);
for i := 0 to Length(ColorArray) -1 do if TempCount = ColorArray[i].Pixels then
begin
Color := ColorArray[i].Color;
Result := True;
WriteLn('Found color with range '+IntTostr(ColorArray[i].Pixels));
Exit;
end
end
except
Result := False;
end;
if not Result then WriteLn('Unique Color NOT found! Please set it yourself.');
ColorToleranceSpeed(1);
end; Example:
This will work for FGM-spot (stand near the tree) + FE and VW bank. So that means Junior's VW Clay Banker + FGM + Cows :D
program GetTreePixel;
{.Include SRL/SRL.SCAR}
var TreePixel: integer;
type ColorMatch = Record
Color, Pixels: Integer;
end;
function GetUniqueColor(var Color: integer; RefColor, Tol, HowManyOnMM, Range: integer): Boolean;
var
ColorArray: Array of ColorMatch;
Colors: Array of integer;
TempCount, TempCount2, TempColor, i, j: integer;
begin
SetArrayLength(Colors, 0);
for i := MMX1 to MMX2 do
for j := MMY1 to MMY2 do
if Rs_OnMinimap(i, j) then
begin
TempColor := GetColor(i, j);
if SimilarColors(RefColor, TempColor, Tol) then
begin
SetArrayLength(Colors, Length(Colors) +1);
Colors[(Length(Colors)) -1] := TempColor;
end
end
SetArrayLength(ColorArray, 0);
for i := 0 to Length(Colors) -1 do
begin
TempCount := CountColor(Colors[i], MMX1, MMY1, MMX2, MMY2);
if TempCount = HowManyOnMM then
begin
if Colors[i] > 0 then
begin
Color := Colors[i];
Result := True;
WriteLn('Found color with range 0');
Exit;
end
end else
begin
if Colors[i] > 0 then
begin
TempCount2 := HowManyOnMM - TempCount;
if TempCount2 < 0 then TempCount2 := TempCount - HowManyOnMM;
if (TempCount2 < Range) then
begin
SetArrayLength(ColorArray, Length(ColorArray) +1);
ColorArray[(Length(ColorArray)) -1].Color := Colors[i];
ColorArray[(Length(ColorArray)) -1].Pixels := TempCount2;
end
end;
end;
end;
if Length(ColorArray) = 1 then
begin
Color := ColorArray[0].Color;
Result := True;
WriteLn('Found color with range '+IntTostr(ColorArray[0].Pixels));
Exit;
end
try
begin
TempCount := Min(ColorArray[0].Pixels, ColorArray[1].Pixels)
for i := 1 to Length(ColorArray) -2 do TempCount := Min(TempCount, ColorArray[i +1].Pixels);
for i := 0 to Length(ColorArray) -1 do if TempCount = ColorArray[i].Pixels then
begin
Color := ColorArray[i].Color;
Result := True;
WriteLn('Found color with range '+IntTostr(ColorArray[i].Pixels));
Exit;
end
end
except
Result := False;
end;
if not Result then WriteLn('Unique Color NOT found! Please set it yourself.');
end;
begin
SetupSRl;
ActivateClient;
if GetUniqueColor(TreePixel, 1587244, 15, 30, 15) then WriteLn('Color: '+IntTostr(TreePixel));
end.
If you want to test this or get the CountValues I made a little script which I added (Set DebugCount True and fill in the color you want to count).
For now this needs Divi, but if there are people who want/need this in 2.03 I will make it :).
Tell me what you think,
Nielsie95