Sir R. M8gic1an
2008-04-24 01:54:23
hey, i'm quite new to autocoloring and i was wondering if this should, in theory, work:
here's the whole procedure if you wanna see how it fits in there:
thx,
~RM
if not Find[k].AutoColor then
begin
for i:=0 to High(Find[k].Colors) do
begin
ColorToRGB(Find[k].Colors[i], j, l, m)
IncEx(Find[k].RG, (j-l));
IncEx(Find[k].RB, (j-m));
IncEx(Find[k].GB, (l-m));
end;
Find[k].RG := (Find[k].RG/Length(Find[k].Colors))
Find[k].RB := (Find[k].RB/Length(Find[k].Colors))
Find[k].GB := (Find[k].GB/Length(Find[k].Colors))
Find[k].Autocolor := True;
end;
red:=(TestColor mod 256);
green:=((TestColor/256) mod 256);
blue:=((TestColor/256) / 256);
{comparing colors}
if ((green-blue)<=(Find[k].GB+20)) then if ((green-blue)>=(Find[k].GB-20)) then
if ((red-green)>=(Find[k].RG-20)) then if ((red-green)<=(Find[k].RG+20)) then
if ((red-blue)>=(Find[k].RB-20)) then if ((red-blue)<=(Find[k].RB+20)) then
here's the whole procedure if you wanna see how it fits in there:
type
Monster = record
Name: string;
UpText: TStringArray;
Colors: TIntegerArray;
AutoColor: boolean;
RG, RB, GB: integer;
end;
var
Find: Array of Monster;
//Smart Colors By Tarajunky, Custom by Rasta Magician
Function SmartColorsCustom(name:string; UpText:TStringArray; colors:TIntegerArray):boolean;
var
j, k:integer;
b, Found:boolean;
var RMInt, RMx, RMy:integer;
var x,y,TestColor,a,l,m,i,red,green,blue, ClickColor:integer;
var p: array of Tpoint;
begin
if not LoggedIn then exit;
for i:=0 to High(Find) do
begin
if lowercase(name) = Find[i].Name then
begin
b := True;
k := i;
end;
end;
if not b then //we have to add it.
begin
k:=GetArrayLength(Find);
SetArrayLength(Find, k+1);
Find[k].Name:= lowercase(name);
Find[k].UpText := UpText;
Find[k].Colors := colors;
end;
{autocoloring}
if not Find[k].AutoColor then
begin
for i:=0 to High(Find[k].Colors) do
begin
ColorToRGB(Find[k].Colors[i], j, l, m)
IncEx(Find[k].RG, (j-l));
IncEx(Find[k].RB, (j-m));
IncEx(Find[k].GB, (l-m));
end;
Find[k].RG := (Find[k].RG/Length(Find[k].Colors))
Find[k].RB := (Find[k].RB/Length(Find[k].Colors))
Find[k].GB := (Find[k].GB/Length(Find[k].Colors))
Find[k].Autocolor := True;
end;
FFlag(0);
Wait(50);
if RMDebug then writeln('Finding '+name);
l:=GetArrayLength(Find[k].Colors); //Checks known colors first
if l>0 then
begin
for i:= 0 to l-1 do
begin
if RMDebug then writeln('finding color: '+IntToStr(Find[k].Colors[i]));
FindColorsSpiralTolerance(MSCX,MSCY,p,Find[k].Colors[i],MSX1,MSY1,MSX2,MSY2,0);
m:=GetArrayLength(p);
if m>0 then
begin
if m > 30 then exit;
for a:= 0 to m-1 do
begin
if CheckAndClick(p[a].x,p[a].y, Find[k].UpText) then //Moves mouse to position, checks uptext and clicks if correct.
begin
result:=true;
if i>0 then //if the color is not in the first position of the array...
Swap(Find[k].Colors[i], Find[k].Colors[i-1]);
// Swap found color with the one ahead of it in the array
exit; // We found our color, so we exit the function completely.
end;
end;
end;
end;
end;
//We didn't find any known colors, so continue on to the tolerance search
for j:=0 to High(Find[k].Colors) do
begin
if j >= 3 then break; //only wanna look for 3 colors with tol
if RMDebug then writeln('finding color '+IntToStr(Find[k].Colors[j])+' with tol ');
FindColorsSpiralTolerance(MSCX, MSCY, p, Find[k].Colors[j],MSX1,MSY1,MSX2,MSY2,25);
l:=GetArrayLength(p);
if (l>0)and(not l>30) then
begin
for i:= 0 to l-1 do
begin
TestColor:=GetColor(p[i].x,p[i].y); //Additional autocoloring to reduce wrong points. (Optional)
{turning it to RGB}
red:=(TestColor mod 256);
green:=((TestColor/256) mod 256);
blue:=((TestColor/256) / 256);
{comparing colors}
if ((green-blue)<=(Find[k].GB+20)) then if ((green-blue)>=(Find[k].GB-20)) then
if ((red-green)>=(Find[k].RG-20)) then if ((red-green)<=(Find[k].RG+20)) then
if ((red-blue)>=(Find[k].RB-20)) then if ((red-blue)<=(Find[k].RB+20)) then
begin
Wait(20);
ClickColor:=GetColor(p[i].x,p[i].y);
for RMInt:=0 to High(Find[k].Colors) do
begin
if RMInt <> j then
if FindColorSpiralTolerance(RMx, RMy, Find[k].Colors[RMInt],x-5,y-5,x+5,y+5, 20) then
begin
Found:=True;
break;
end;
end;
If Found then
if CheckAndClick(p[a].x,p[a].y, Find[k].UpText) then //Move mouse, check uptext and click
begin
result:=true;
FindColorsSpiralTolerance(x,y,p,ClickColor,MSX1,MSY1,MSX2,MSY2,0);
if GetArrayLength(p)<20 then //Make sure that the color is somewhat rare, and doesn't take up half the screen
begin
a:=GetArrayLength(Find[k].Colors);
for i:= 0 to a-1 do
begin
if ClickColor=Find[k].Colors[i] then //If color is already in the array...
begin
if i>0 then
begin // Move it up one spot in the array search priority
Swap(Find[k].Colors[i], Find[k].Colors[i-1]);
end;
exit;
end;
end;
// if it's not in the array yet, then add it to the end of the array
SetArrayLength(Find[k].Colors,a+1);
Find[k].Colors[a]:=ClickColor;
if RMDebug then Writeln(IntToStr(ClickColor)+' added to '+name+' array');
end;
exit;
end;
end;
end;
end;
end;
end;
thx,
~RM