R0b0t1
2007-09-03 19:21:12
Yes, I have no idea what so ever if it will work at all, but help me!
Read the little top thingy for the discription, but if thats confusing, I could try to explain.
Cred. to Fakawi for the idea.
Read the little top thingy for the discription, but if thats confusing, I could try to explain.
Cred. to Fakawi for the idea.
program GetBestColor;
{.Include SRL/SRL.scar}
{-------------------------------------------------------------------]
[ Function GetBestColorNPC ]
[ Creator: R0b0t1 ]
[ Credits: Wizzup? for formulas. ]
[ Category: AutoColoring/NPCFinding ]
[ Description: Finds an NPC, gets colors within an tolerance ]
[ on that NPC, compares them with cols on the MS ]
[ and then either gets a better color, or changes ]
[ the tolerance. The RS screen must be in view, and ]
[ the mouse must be available to the Function under ]
[ certain cercumstances ]
[-------------------------------------------------------------------}
Function GetBestColorNPC(UpText, NSize: String; BColor, Tol: Integer; DoTol: Boolean): Integer;
Var
I, x, y, x1, y1, BX1, BY1, BX2, BY2: Integer;
ColorArr: Array [0..5] of Integer;
H, S, L: Array of Extended;
bH, bS, bL: Extended;
SkipArr: Array [0..6] of TPoint;
begin;
GetMousePos(x1, y1);
FindColorTolerance(x, y, BColor, MSX1, MSY1, MSX2, MSY2, Tol);
If not (X = x1) and (Y = y1) Then
MMouse(x1, y1, 2, 2);
Wait(150+Random(100));
Case LowerCase(NSize) of
'small': begin;
BX1:= x1 - 25;
BY1:= y1 - 25;
BX2:= x1 + 25;
BY2:= y1 + 25;
If (BX1 < 0) Then BX1:= 0;
If (BY1 < 0) Then BY1:= 0;
If (BX2 > MSX2) Then BX2:= MSX2;
If (BX1 > MSY2) Then BY2:= MSY2;
end;
'medium': begin;
BX1:= x1 - 50;
BY1:= y1 - 50;
BX2:= x1 + 50;
BY2:= y1 + 50;
If (BX1 < 0) Then BX1:= 0;
If (BY1 < 0) Then BY1:= 0;
If (BX2 > MSX2) Then BX2:= MSX2;
If (BX1 > MSY2) Then BY2:= MSY2;
end;
'large': begin;
BX1:= x1 - 100;
BY1:= y1 - 100;
BX2:= x1 + 100;
BY2:= y1 + 100;
If (BX1 < 0) Then BX1:= 0;
If (BY1 < 0) Then BY1:= 0;
If (BX2 > MSX2) Then BX2:= MSX2;
If (BX1 > MSY2) Then BY2:= MSY2;
end;
end;
For I:= 0 to 5 do
begin;
FindColorSkipCoordsTolerance(x, y, BColor, BX1, BY1, BX2, BY2, Tol, SkipArr);
ColorArr[I]:= GetColor(x, y);
SkipArr[I].x:= x;
SkipArr[I].y:= y;
end;
SetArrayLength(H, GetArrayLength(ColorArr));
SetArrayLength(S, GetArrayLength(ColorArr));
SetArrayLength(L, GetArrayLength(ColorArr));
For I:= 0 to GetArrayLength(ColorArr) - 1 do
begin;
ColorToHSL(ColorArr[I], H[I], S[I], L[I]);
bH:= bH + H[I];
bS:= bS + S[I];
bL:= bL + L[I];
end;
If GetArrayLength(ColorArr) > 0 Then
begin;
bH:= bH div GetArrayLength(ColorArr);
bS:= bS div GetArrayLength(ColorArr);
bL:= bL div GetArrayLength(ColorArr);
end;
If not (DoTol) Then
Result:= HSLToColor(bH, bS, bL);
else
begin;
bH:= bH - Round(bH/2);
bS:= bS - Round(bS/2);
bL:= bL - Round(bS/2);
bH:= bH + bH;
bS:= bS + bS;
bL:= bL + bL;
I:= HSLToColor(bH, bS, bL);
If (I > BColor) Then Result:= I - BColor;
If (I < BColor) Then Result:= BColor - I;
end;
end;
begin;
end.