SRL Archive - Test corner

GetBestColorNPC - Test it!


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.


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.

pwnaz0r

2007-09-03 19:37:12

I understand what your trying to do. let me explain it clearer for others ( correct me if i'm wrong). It will "Update" the colors of an NPC by finding a color(with tolerance) and looking around that color to find a new updated color?

Anyways wouldn't this be easier without HSL?

R0b0t1

2007-09-03 20:17:06

Eh? Oh…

Well, it gets an array of colors from a box arround the NPC within a tolerance. It then does some magic math to make that color "better". If dotol is true, it returns the difference of the base color and the "better" color, if its not, it returns the "better" color.

I'm not sure if it will improve finding, but it may… Lol, I didn't create this right, in my opinion, to do what I invision.

n3ss3s

2007-09-04 08:27:09

It then does some magic math
Love that.

But to get the best color, couldnt you just FindColor and GetColor(x, y) ? :D

:p maybe I missed something but..

Tim0suprem0

2007-09-04 10:26:50

From: n3ss3s
Love that.

But to get the best color, couldnt you just FindColor and GetColor(x, y) ? :D

:p maybe I missed something but..


R0b0t loves his HSL though… :p

n3ss3s

2007-09-04 10:29:32

Yeh, but still gj robot, and it looks leet :D

R0b0t1

2007-09-04 18:24:20

GetColor(x,y) wouldn't work, because it would add an extra step.


It just adds points it already found to a Tpointarray and uses FindColorSkipCoordsTolerance. (Long name, huh?)

Thanks for the "feed back" though.

Rune Hacker

2007-09-05 21:20:06

Why not just use findcolortolerance and move mouse to it and then if there is the correct uptext, then getcolor. But if it doesn't find the color it originally found using findcolor, then it looks for the tolerance color and re-gets the exact color?

R0b0t1

2007-09-07 22:55:50

Uh, yes and no.

This simply gets all of the colors from a box around the first color it finds (BColor) and makes those into a median of all those collected, or returns the tolerance of the greatest and lowest.

It simply improves the chances of hovering over an NPC, but uptext should always be used.

Using my skipcoord method, you could, in effect, find ever color with a certain tolerance and check the up text until you find a match.