ok, dont get confused on me, im going to put the function in the thread under this line, and will explain it afterwards.
SCAR Code:
{.include srl/srl.scar}
Function FindSpotFrom2Colors(color1,color2,x1,y1,x2,y2,offX,OffY,Tol:integer;
Way2Search,spot2click:string):tpoint;
var g,i:integer;Coords:Array of Tpoint;Length2:integer;
begin
Way2Search:=LowerCase(Way2Search);
Spot2Click:=LowerCase(Spot2Click);
if color1=0 then begin writeln('color1 = 0'); exit; end;
if color2=0 then begin writeln('color2 = 0'); exit; end;
if (way2Search='center/right') then
begin
g:=Round((x2-x1)/2);
Coords:=GetPixelsD(color1,g,y1,x2,y2,Tol);
Length2:=GetArrayLength(Coords);
repeat
x:=Coords[i].x;
y:=Coords[i].y;
if (getcolor(x+OffX,y+OffY) = color2) then
begin
// SPOT CLICKING
if (Spot2Click = 'color2') then
begin
result.x:=x+OffX;
result.y:=y+OffY;
end
else if (Spot2Click='color1') then
begin
result.x:=x;
result.y:=y;
end
else if (Spot2Click='middle') then
begin
if x+OffX > x then
result.x:=Round(((X+OffX)-x)/2)
else if x>X+OffX then
result.x:=Round((x-(x+offx))/2);
if y+offy > y then
result.y:=Round(((y+Offy)-y)/2)
else if y>y+Offy then
result.y:=Round((y-(y+offy))/2);
end;
// END SPOT CLICKING
exit;
end;
I:=i+1;
Until(i=Length2);
end;
if (way2Search='center/left') then
begin
g:=Round((x2-x1)/2);
Coords:=GetPixelsD(color1,x1,y1,g,y2,Tol);
Length2:=GetArrayLength(Coords);
repeat
x:=Coords[i].x;
y:=Coords[i].y;
if (getcolor(x+OffX,y+OffY) = color2) then
begin
// SPOT CLICKING
if (Spot2Click = 'color2') then
begin
result.x:=x+OffX;
result.y:=y+OffY;
end
else if (Spot2Click='color1') then
begin
result.x:=x;
result.y:=y;
end
else if (Spot2Click='middle') then
begin
if x+OffX > x then
result.x:=Round(((X+OffX)-x)/2)
else if x>X+OffX then
result.x:=Round((x-(x+offx))/2);
if y+offy > y then
result.y:=Round(((y+Offy)-y)/2)
else if y>y+Offy then
result.y:=Round((y-(y+offy))/2);
end;
// END SPOT CLICKING
exit;
end;
I:=i+1;
Until(i=Length2);
end;
if (Way2Search='center/up') then
begin
g:=Round((y2-y1)/2);
Coords:=GetPixelsD(color1,x1,y1,x2,g,Tol);
Length2:=GetArrayLength(Coords);
repeat
x:=Coords[i].x;
y:=Coords[i].y;
if (getcolor(x+OffX,y+OffY) = color2) then
begin
// SPOT CLICKING
if (Spot2Click = 'color2') then
begin
result.x:=x+OffX;
result.y:=y+OffY;
end
else if (Spot2Click='color1') then
begin
result.x:=x;
result.y:=y;
end
else if (Spot2Click='middle') then
begin
if x+OffX > x then
result.x:=Round(((X+OffX)-x)/2)
else if x>X+OffX then
result.x:=Round((x-(x+offx))/2);
if y+offy > y then
result.y:=Round(((y+Offy)-y)/2)
else if y>y+Offy then
result.y:=Round((y-(y+offy))/2);
end;
// END SPOT CLICKING
exit;
end;
I:=i+1;
Until(i=Length2);
end;
if (way2Search='center/down') then
begin
g:=Round((y2-y1)/2);
Coords:=GetPixelsD(color1,x1,g,x2,y2,Tol);
Length2:=GetArrayLength(Coords);
repeat
x:=Coords[i].x;
y:=Coords[i].y;
if (getcolor(x+OffX,y+OffY) = color2) then
begin
// SPOT CLICKING
if (Spot2Click = 'color2') then
begin
result.x:=x+OffX;
result.y:=y+OffY;
end
else if (Spot2Click='color1') then
begin
result.x:=x;
result.y:=y;
end
else if (Spot2Click='middle') then
begin
if x+OffX > x then
result.x:=Round(((X+OffX)-x)/2)
else if x>X+OffX then
result.x:=Round((x-(x+offx))/2);
if y+offy > y then
result.y:=Round(((y+Offy)-y)/2)
else if y>y+Offy then
result.y:=Round((y-(y+offy))/2);
end;
// END SPOT CLICKING
exit;
end;
I:=i+1;
Until(i=Length2);
end;
if (way2Search='All') then
begin
Coords:=GetPixelsD(color1,x1,y1,x2,y2,Tol);
Length2:=GetArrayLength(Coords);
repeat
x:=Coords[i].x;
y:=Coords[i].y;
if (getcolor(x+OffX,y+OffY) = color2) then
begin
// SPOT CLICKING
if (Spot2Click = 'color2') then
begin
result.x:=x+OffX;
result.y:=y+OffY;
end
else if (Spot2Click='color1') then
begin
result.x:=x;
result.y:=y;
end
else if (Spot2Click='middle') then
begin
if x+OffX > x then
result.x:=Round(((X+OffX)-x)/2)
else if x>X+OffX then
result.x:=Round((x-(x+offx))/2);
if y+offy > y then
result.y:=Round(((y+Offy)-y)/2)
else if y>y+Offy then
result.y:=Round((y-(y+offy))/2);
end;
// END SPOT CLICKING
exit;
end;
I:=i+1;
Until(i=Length2);
end;
end;
well now that uve seen it ill explain why i created this.
well i was stuck for a while trying to figure out how i could get a sample of this mountain side, without having to go through huge color ranges of rgb or scar colors, and today it finally struck me, i could get the dirtroad color then the regular road color, and find where the 2 colors meet, and it would put me in a spot that is exact, and i would be able to color pick from it. there is many other uses for this also as u will find out and i will explain later
instructions for use
parameters: (color1,color2,x1,y1,x2,y2,offX,OffY,Tol:integer;W ay2Search,spot2click:string):tpoint;
ok, color1 is the first color you will be looking for
color2 is the color u will be looking for based from the coordinates of color1,
x1,y1,x2,y2 this should be all to familiar with you if you know how to use findcolor
offx,offy, these are the values of the distance from color1 to color2
example: color1 is at coordinate 41,52 color2 is at coordinate 45,70 offx would = the higher x coordinate minus the lower x coordinate so, offx=4 same thing goes for offy, so it would = 18, but when your using this i would add 1 to this value just for tolerance and camera angle changes
when both coordinates in color2 arent both higher then color1's then u have to use negative numbers,
example:color1(41,52), color2(42,40), since your looking for color 2 from color 1's coordinates you want to do color2-color1(not the color numbers, the coords) so u would end up with offx=1, offy=-12 and when ur adding tolerance to a negative number remember to subract 1, so -12 would become -13.
as of right now Tol is only the Tolerance of Color1, later today maybe tommorrow i will add tolerance for color2, if you have used findcolor before, tol is the same as tolerance.
ok, Way2Search, remember that this is a string, the only things u can put in this spot are, 'center/right', 'center/left', 'center/up', 'center/down', 'all'
ok how this works is, if in ur area, u might have some color confusion, but you arent sure because of camera angle or compass direction, its better safe then sorry to search the safer area first, or if nothing can be confused, the more common area to find it in first,
center/left means it searchs from center of your area to the left side of your area.
center/right same thing except center to right side
center/up this searchs from center to top side of your area, or north
center/down this searchs from center to bottom side of your area, or south
all this searchs the entire area, but it starts from left to right, then goes top to bottom.
ok onto Spot2Click, this variable is also a string, what this does is, when it finds the 2 colors, this decides what the x and y coordinates that are outputed by this function is going to be
right now there is only 3 choices, 'center', 'color1', 'color2'
center what it does is finds the center point between the two colors and outputs it to the function
color1 takes the final coord value of color1 and outputs to the function
color2 does the same as color1 except for color2
(if you need an example, just ask)
ok, this function outputs its answers, as a TPoint Variable
since i dont think a Tpoint variable is understanded by alot of beginners i will tell you what it is,
tpoint is a type which outputs 2 answers to a variable, x and y,
how you get these answers are
example:
SCAR Code:
program new;
variable MyCoordinatesForTheFunction:Tpoint;
function FindSpotFrom2Colors(color1,color2,x1,y1,x2,y2,OffX,OffY,Way2Search,Spot2Click):Tpoint;
begin
blah blah blah
end;
begin
MyCoordinatesForTheFunction:=FindSpotFrom2Colors(blah,blah,blah);
writeln(IntToStr(MyCoordinatesForTheFunction.x) + ' = X value | ' + IntToStr(MyCoordinatesForTheFunction.y) + ' = Y value');
end.
ok short answer, its YourTpointVariable.x = x, and YourTpointVariable.y = y.
Now i will give you an example of where to use this, or where i used this

ok what im trying to do is, be able to click at the edge of the dirt road where it meets the Real Road on the bottom side of my minimap

ok, now how i would do it using this function in scar is,
SCAR Code:
program New;
{.include srl/srl.scar}
var mountain,DirtRoadColor,RoadColor:integer;TpointVar:Tpoint;
Function FindSpotFrom2Colors(color1,color2,x1,y1,x2,y2,offX,OffY,Tol:integer;
Way2Search,spot2click:string):tpoint;
var g,i:integer;Coords:Array of Tpoint;Length2:integer;
begin
blah blah
end;
function getmountainsample:integer;
var xx,yy,cmax,cmin,ccolor:integer;
begin
xx:=mmcx;
yy:=mmy1+10;
cmax:=5500000;
cmin:=4000000;
if (mountain=0) or not(findcolorspiral(x,y,mountain,mmx1,mmy1,mmx2,mmy2)) then
begin
repeat
ccolor:=getcolor(xx,yy);
if (ccolor>=cmin) and (ccolor<=cmax) then
begin
result:=ccolor;
exit;
end
else
begin
repeat
xx:=xx+1;
ccolor:=getcolor(xx,yy);
if (ccolor>=cmin) and (ccolor<=cmax) then
begin
result:=ccolor;
exit;
end;
until (xx=(mmx2-mmcx)/2)
end;
if result > 0 then exit;
yy:=yy+1;
until (yy=36);
end;
end;
begin
setupsrl;
activateclient;
wait(500);
makecompass('w');
wait(500);
RoadColor:=FindRoadColor;
DirtRoadColor:=FindDirtRoadColor;
TpointVar:= FindSpotFrom2Colors(DirtRoadColor,RoadColor,mmx1,mmy1,mmx2,mmy2,0,-10,0,'center/down','color1');
flag;
mouse(TpointVar.x,TpointVar.y,0,0,true);
wait(500);
makecompass('n');
mountain:=getmountainsample;
writeln(inttostr(mountain));
if findcolor(x,y,mountain,mmcx,mmy1,mmx2,36) then
mmouse(x,y,0,0);
end.
thats it, hope u enjoyed, have fun using this :-)