SRL Archive - OSR Help

Dark colors and light colors?


bud_wis_er_420

2013-04-05 18:05:10

How would I go about telling whether a pixel was a dark color or light color. I don't know a whole lot about the color spectrum but I assume you could just use something like this…
if InRange(Color, MinLightColor, MaxLightColor) then
writeln('Light Color')
else if InRange(Color, MinDarkColor, MaxDarkColor) then
writeln('Dark Color');

…and if so, I have no idea what MinLightColor, MaxLightColor, MinDarkColor, and MaxDarkColor would be?

Can someone shed some light on this for me, thank you?

Basicly what I'm trying to do is take a bmp and check each pixel in that bmp for light or dark color. If more are dark then light, then its a dark bmp or vis versa.

Ian

2013-04-05 18:08:39

Maybe upload a picture of what you want to use it for, I'm not sure I understand what you want to do.

bud_wis_er_420

2013-04-05 18:34:41

I'm building a script that will assist with the EOC abilities. My idea for this script is that it can work in any resolution with no setting up. You will just be able to press play and your abilities will be automatic.

My first atemp was using bmp tols. When a player presses run on the script and is engaged in combat it will start atempting to press the ability hot keys. It will be easier to list what the script does than explain it so I'm gona do that

1. It takes a bmp of say tab 10.
2. Presses tab 10 hot key.
3. looks for any change using the above bmp.
4. If there is change, the ability was used and it stores the first bmp to be used, to know when the ability is ready to be used in the future.

It repeats this until all abilities are stored and then all it has to do is when one of the bmps is seen it activates that ability.

The script below is the one I built this way. But the problem with this way that I don't like it it will have to loop threw each ability, even the inactive ones until adrenaline gets to 100% for each 100% ability you have in your bar. Which may or may not get you noticed by jagex. Continuously clicking on a useless button over and over might get noticed.

So I want to take a picture of the ability tab and if it's dark it's not an active ability. If it is bright in color it is an active ability.

program new;
{$I SRL/SRL.Simba}

const

//SetActionBar = True;
BarMax = 7;


var
AblBmp, AbCk: TIntegerArray;


function ActionBarSlotToBox_Custom(Slot: Integer): TBox;
var
W, H: Integer;
begin
if InRange(Slot, 1, 12) then
begin
GetClientDimensions(W, H);
with Result do
begin
X1 := 47 + (Slot - 1) * 36;
Y1 := H - 209;
X2 := X1 + 29;
Y2 := Y1 + 29;
end;
end else
writeln('ActionBarSlotToBox, Slot must be within 1-12!');
end;


procedure CheckActionSlotReady(abs: Integer);
var
x, y, c, rev, TempBmp: Integer;
Box: TBox;
begin
Box := ActionBarSlotToBox_Custom(abs);
if (AbCk[abs] = 0) then
begin
writeln('Taking a temp bmp from slot ' + IntToStr(abs));
TempBmp := BitmapFromClient(Box.x1 + 5, Box.y1 + 5, Box.x2 - 5, Box.y2 - 5);
SetBitmapName(TempBmp, 'TempBmp.bmp');
end else
begin
writeln('Getting stored bmp' + IntToStr(abs));
TempBmp := AblBmp[abs];
end;

if FindBitmapToleranceIn(TempBmp, x, y, Box.x1, Box.y1, Box.x2, Box.y2, 10) then
begin
writeln('Found bmp, using ability slot ' + IntToStr(abs));
TypeSendEx(IntToStr(abs), False);
end else Exit;

c := 0;
repeat
wait(RandomRange(100, 200));
Inc(c);
if (c > 5) then break;
writeln('c := ' + IntToStr(c));
until not FindBitmapToleranceIn(TempBmp, x, y, Box.x1, Box.y1, Box.x2, Box.y2, 10)
// Bitmap not found. Used ability
if (c >= 5) then
begin
if (AbCk[abs] = 1) then
begin
AbCk[abs] := 0;
writeln('Freeing bmp' + IntToStr(abs));
FreeBitmap(AblBmp[abs]);
end;
end else
begin
writeln('Slot ' + IntTosTR(abs) + ' set')
wait(5000);////////////////////////////
AbCk[abs] := 1;
writeln('Storeing bmp' + IntToStr(abs));
AblBmp[abs] := TempBmp;
SetBitmapName(AblBmp[abs], 'AblBmp[' + IntToStr(abs) + '].bmp');
end;
FreeBitmap(TempBmp);
end;

function GetTargetText: string;
var
W, H: Integer;
TPA: TPointArray;
Box: TBox;
begin
GetClientDimensions(W, H);
Box := IntToBox(W - 190, H - 360, W - 80, H - 270);
if FindColors(TPA, 3111603, Box.X1, Box.Y1, Box.X2, Box.Y2) then
begin
Box := GetTPABounds(TPA);
Result := GetTextAtExWrap(Box.X1, Box.Y1, Box.X2, Box.Y2, 0, 3, 4, 3111603, 0, UpChars);
end;
end;

function HaveTarget: Boolean;
var
x, y, W, H, TargetTxtBmp: Integer;
str: string;
TSA: TStringArray;
TPA: TPointArray;
Box: TBox;
begin
Result := False;
GetClientDimensions(W, H);
Box := IntToBox(W - 190, H - 360, W - 80, H - 270);
if FindColors(TPA, 3111603, Box.X1, Box.Y1, Box.X2, Box.Y2) then
Box := GetTPABounds(TPA);

MMouse(box.x1, box.y2, 0, 0);
wait(2000);
MMouse(box.x2, box.y2 + 20, 0, 0);
wait(2000);

if FindColorTolerance(x, y, 2657624, box.x1, box.y2,box.x2, box.y2 + 20, 36) then
begin
writeln('No Target Found');
end else
begin
writeln('Target Found');
if FindColorTolerance(x, y, 2657624, box.x1, box.y2,box.x2, box.y2 + 20, 36) then
result := True;
end;
end;


procedure MainLoop;
var
i, slot: Integer;
begin
//Checks health

// Checks Action bar
if HaveTarget then
begin
for i:= 0 to BarMax do
begin
case i of
0 : slot := BarMax;
1 : slot := BarMax - 1;
3 : slot := BarMax - 2;
4 : slot := BarMax - 3;
5 : slot := BarMax - 4;
6 : slot := BarMax - 5;
7 : slot := BarMax - 6;
8 : slot := BarMax - 7;
9 : slot := BarMax - 8;
10 : slot := BarMax - 9;
end;
writeln('Checking slot: ' + IntToStr(slot));
CheckActionSlotReady(slot);
if HaveTarget then Continue;
end;
end;
end;

procedure Setup;
var
i: Integer;
begin
setLength(AbCk, BarMax + 17);
setLength(AblBmp, BarMax + 1);
for i := 0 to High(AbCk) do
begin
AbCk[i] := 0;
end;
end;
var
W, H: Integer;

Begin
SetUpSRL;
Setup;
ClearDebug;
wait(2000);
repeat
MainLoop;
//writeln(GetTargetText);
wait(RandomRange(2000, 2200));
until(false)

End.

superuser

2013-04-05 18:34:49

You could use

procedure ColorToHSL(Color: integer; var h, s, l: extended);

From those three parameters, look l (luminance). Basically it should be higher the brighter the color is.

bud_wis_er_420

2013-04-05 18:45:42

cool I will try that. I will loop thou ea color and get the avg lum and can compare it that way. Thx. Will report back if it works.

superuser

2013-04-05 18:52:54

From: bud_wis_er_420
cool I will try that. I will loop thou ea color and get the avg lum and can compare it that way. Thx. Will report back if it works.


I used a similar technique to find out if a slot is empty or not:

function IsFreeActionBarSlot(s: integer): boolean;
var
ti: TIntegerArray;
i: integer;
h, s_, l: extended;
e: extended;
begin
ti := GetColorsBox(48 + s * 35, 300, 48 + s * 35 + 28, 326, false);
e := 0.0;

for i := 0 to High(ti) do begin
ColorToHSL(ti[i], h, s_, l);

e := e + (l * (0.1 * h));
end;

e := e / High(ti);
result := e < 5.0;

SetLength(ti, 0);
end;

bud_wis_er_420

2013-04-05 19:33:30

Worked like a charm thx very much.


program new;
{$I SRL/SRL.Simba}


function ActionBarSlotToBox_Custom(Slot: Integer): TBox;
var
W, H: Integer;
begin
if InRange(Slot, 1, 12) then
begin
GetClientDimensions(W, H);
with Result do
begin
X1 := 56 + (Slot - 1) * 36;
Y1 := H - 205;
X2 := X1 + 16;
Y2 := Y1 + 21;
end;
end else
writeln('ActionBarSlotToBox, Slot must be within 1-12!');
end;


function IsAbilityReady(Slot: Integer): Boolean;
var
i,x,y: Integer;
h, s, l, Avg: Extended;
TIA: TIntegerArray;
TIALum: TExtendedArray;
Box: TBox;
begin
Result := False;
Box := ActionBarSlotToBox_Custom(Slot);
TIA := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
setLength(TIALum, High(TIA)+1);
for i := 0 to High(TIA) do
begin
ColorToHSL(TIA[i], h, s, l);
TIALum[i] := l;
//writeln(FloatToStr(l));
end;
Avg := AverageExtended(TIALum);
Result := (Avg > 10);
end;



begin
SetUpSRL;

if IsAbilityReady(4) then
writeln('Ready');
End.