SRL Archive - OSR Help

how tolerant are tolorence's


elementalelf

2007-09-06 07:37:53

line is:
FindColorTolerance(lulx,luly,528685,100,60,40,500,400)
the number "100" is the tolerance value, does that mean that the color value(528685) will look 100 either side?(i.e. 528585-528785) or is it figured out some other way?

Santa_Clause

2007-09-06 07:43:24

It's figured out some other way…

Try finding TOB's Tolerance Finder…it'll help you.

100 Tolerance is too much…we usually use about 5-10 tolerance.

elementalelf

2007-09-06 07:57:29

google search reveals
http://www.villavu.com/forum/showthread.php?t=15494
but i cant access that yet.
edit, on another note,

repeat
FindColorTolerance(lulx,luly,528685,1000,60,40,500,400);
if(lulx>20)then mmouse(lulx,luly,1,1);
wait(5);
until(isuptext('talk'));

returns nothing, i.e. 1000 tolerance is NOT enough to find any colors from 528685 :/
note: 528685 = the red color on the tut island guy's hat.

it SHOULD find the exact color 528685 because i can see the color on the screen, but for some reason it doesnt.
the if/then statement works fine, i took it out, and the mouse moves to the top left corner(i.e. lulx and luly stay as 0 because it hasnt found a color)

Santa_Clause

2007-09-06 08:03:22

Hmmm…do you mind posting the whole thing you have in SCAR…in SCAR tags…it'll make it easier for me.

Anyways, for FindColorTolerance, we use an if/then statement too because we don't always know if the colour will be found or not. Try this:

repeat
if FindColorTolerance(lulx,luly,528685,10,MSX1,MSY1,MSX2 ,MSY2) then
MMouse(lulx,luly,3,3);
until(isuptext('talk'));

I changed the tolerance to 10. MSX1, MSY1, MSX2, MSY2 are the coordinates of the main-screen…and it was moving to the top left corner because the maximum tolerance you can have is 255, so if the tolerance is 1000 then it finds any colour. SCAR searches from the top left to bottom right so it just moved the mouse to the top left pixel…

If you need a better explanation then tell me ;)

Starblaster100

2007-09-06 08:16:25

What has happened to you all?!?!?!?!?!?

[php]
function FindColorTolerance(var x, y: Integer; Color, x1, y1, x2, y2, Tol: Integer): Boolean;
[/php]

Tolerance is the end parameter!!!

Santa_Clause

2007-09-06 08:21:15

My bad…I always get confused because there's so many parameters with FindColorCircle/FindDTM/FindBMP…

repeat
if FindColorTolerance(lulx,luly,528685,MSX1,MSY1,MSX2,MSY2,10) then
MMouse(lulx,luly,3,3);
until(isuptext('talk'));

elementalelf

2007-09-06 08:24:57

From: SantaClause
Hmmm…do you mind posting the whole thing you have in SCAR…in SCAR tags…it'll make it easier for me.

Anyways, for FindColorTolerance, we use an if/then statement too because we don't always know if the colour will be found or not. Try this:

repeat
if FindColorTolerance(lulx,luly,528685,10,MSX1,MSY1,MSX2 ,MSY2) then
MMouse(lulx,luly,3,3);
until(isuptext('talk'));

I changed the tolerance to 10. MSX1, MSY1, MSX2, MSY2 are the coordinates of the main-screen…and it was moving to the top left corner because the maximum tolerance you can have is 255, so if the tolerance is 1000 then it finds any colour. SCAR searches from the top left to bottom right so it just moved the mouse to the top left pixel…

If you need a better explanation then tell me ;)

so its RGB based, wierd.

note: i havnt scripted in more then a year, so im not doing anything fancy, also, please ignore the writeln's i use them for debugging when im scripting
when i have completed the script, i will go back and fancify it with more efficient syntax etc etc.
the entire script so far is:
EDIT: fixed the tolerance thing, it finds the guy, but it seems isuptext is not working.
any help?
edit: look down for updated version.

Santa_Clause

2007-09-06 08:29:36

Seems good. For the arrow-finding, you could probably use a DTM…

Starblaster100

2007-09-06 08:30:53

As for your question on how tolerance works, there are 3 versions.

The default one is using RGB, however you can change that using the procedure
[php]ColorToleranceSpeed(x: Integer);[/php]

Default x = 1 (Thats RGB)
x = 0 uses the Long numbers (i've forgotten what they are called… 528685 in your example)
x = 2 uses HSL.

0 is the fastest, 2 is the slowest.

So you are basically balancing speed with accuracy.

Sumilion

2007-09-06 08:34:55

From: elementalelf
…please ignore the writeln's i use them for debugging when im scripting


Dont worry, i do that too all the time :p

I searched the net for freddys old site, he had the (or a) source of FindColorTolerance and you can exactly see how it works then, didnt find it though.

What I remember was that it indeed used RGB and then some.

n3ss3s

2007-09-06 08:35:57

Any ideas SB how could I combine the 0 and 2? Lol, Id be written in history :D

elementalelf

2007-09-06 08:36:56

i see
im quite proud of my flashing button function actually, fairly simple and it works a treat.

im making this script as foolproof as possible, i could just make it so it clicks specific colors, but then you would have to do a full tut island run just to get all the colors for the script, this way takes longer, but ensures the script will run well, potentially for quite a few updates.

starblaster: how am i doing so far? i understand that its gunna take alot of time to get back to my old scripting standards, but is this enough to warrant entry into SRL dev team? :P
NEW!!!
it now works all the way up to opening the door, i think im gunna have to learn DTM's :(
do DTM's work if the arrow changes size? i.e. would the same DTM work on an arrow that is 3/4 the size?

edit: new update below

Starblaster100

2007-09-06 08:47:17

From: Sumilion
Dont worry, i do that too all the time :p

I searched the net for freddys old site, he had the (or a) source of FindColorTolerance and you can exactly see how it works then, didnt find it though.

What I remember was that it indeed used RGB and then some.


Actually i don't think thats the true source of FindColorTolerance… it used ScanLines if i am correct. The one in SCAR is much faster. However, it may have been the true source, and i am just wrong :p

N3ss3s, however much you try and combine them, you won't get the speed of HSL faster than the default SCAR one (I think its Hex???), simply because thats how they work.

Default one is like

[php]
Result := (Abs(Color1.hex - Color2.hex) <= Tol);
[/php]

whereas RGB one is like:

[php]
function SimilarColors(Color1, Color2, Tolerance: Integer): Boolean;
begin
Result := ((Abs((Color1 and $ff) - (Color2 and $ff)) <= Tolerance) and
(Abs(((Color1 and $ff00) shr 8) - ((Color2 and $ff00) shr 8)) <= Tolerance) and
(Abs(((Color1 and $ff0000) shr 16) - ((Color2 and $ff0000) shr 16)) <= Tolerance));
end;
[/php]

This was the ScanLines FindColorTolerance procedure:

[php]
function FindColor(var x, y: Integer; Color, xs, ys, xe, ye, Tolerance: Integer; Window: Hwnd): Boolean; stdcall;
var
Bmp: TBitmap; // Bitmap of the client
tmpDC: HDC; // Device context of the client's window handle
Size: TRect; // Rect(angle) of the client's window
cx, cy: Integer; // For-loop vars
Line: PRGB32Array; // The scanline
begin
Result := False; // In case the color isn't found => Result = False
x := -1; // In case the color isn't found => x = -1
y := -1; // In case the color isn't found => y = -1
Bmp := TBitmap.Create; // We create our bitmap instance
tmpDC := GetWindowDC(Window); // We get the device context of the client's window handle
GetWindowRect(Window, Size); // We get the rect(angle) of the client's window
Bmp.Width := Size.Right - Size.Left; // We set the width of our bitmap
Bmp.Height := Size.Bottom - Size.Top; // We set the height of our bitmap
BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, tmpDC, 0, 0, SRCCOPY);
// ^^^ We copy the client's canvas onto the bitmap
Bmp.PixelFormat := pf32bit; // We set the bitmap to 32bits
DeleteDC(tmpDC); // We delete the device context to avoid memory leakage
for cy := ys to ye do // Loop for the rows of pixels (y)
begin
if cy >= Bmp.Height then Break; // Break the loop if you reach the end of the bitmap
Line := Bmp.ScanLine[cy]; // We retrieve the scanline (line of pixels) from the bitmap for the current y
for cx := xs to xe do // Loop for the colums of pixels (x)
begin
if cx >= Bmp.Width then Break; // Break the loop if you reach the end of the bitmap
if (SimilarColors(RGB(Line[cx].R, Line[cx].G, Line[cx].B), Color, Tolerance)) then
// ^^^ We convert the RGB values of the current pixel to a color and compare it with the tolerance to the entered color
begin // If the color is similar (or for tol 0 the same) then…
Result := True; // Result of the function
x := cx; // Returned x-value
y := cy; // Returned y-value
Line := nil; // Free the scanline to avoid memory leaks
Bmp.Free; // Free the bitmap to avoid memory leaks
Exit; // Exit the function
end;
end;
end;
Line := nil; // Free the scanline to avoid memory leaks
Bmp.Free; // Free the bitmap to avoid memory leaks
end;
[/php]

EDIT: No offense dude, but you have a while to climb yet ;)

elementalelf

2007-09-06 09:14:13

From: Starblaster100

EDIT: No offense dude, but you have a while to climb yet ;)


none taken, i can barely remember most of the handy procedures…

new update:

as you can see, because i made my procedures carefully during the beggining, i can adapt them over and over again during the script, instead of having to make a new procedure for every person.

next day edit:
been scripting for 2 hours straight, and ive hit the half way mark in the script(the little bar for tutorial island is about half full)
note: this doesnt mean the script will be done in about the same amount of time it has taken me to get here, coz after i finish the initial run through, i have to go back with another account and start fixing all the errors… fun fun.
so far: gets up to the rats, i may need some help making a script to attack the rats if anyone is interested in helping me

ALSO: if at all possible can some friendly forum members please make new chars, and test out the script, noting where it fails(which it will inevitably)
thanks, i posted a link to this thread in general news to attract testers.

program New;
var sparkle,lulx,luly,lulbmp,mini:integer;
ggg:boolean;
textin:string;

{.include SRL/SRL.scar}

procedure lulsetup;
begin
mousespeed:= 30;
lulbmp := BitmapFromString2(False, 'a67FF878DAC5CC310E00210' +
'804C02F712802A5A2FCFF490716575B5C6233D9B01B0000B40420' +
'3D68B8D2BA3349885243224BBDED4DCE19F3C2465F6E920597997' +
'26E1ECECFD8CCA79B8E8B76BEA779A7F5BFD58E1CAE454F7C0100' +
'2');
mini := BitmapFromString2(False, 'a3201478DA6DCB310E80300C4' +
'3D12B59A5A4614C9AFAFE476A03A8626079FA830D00A60B9C3DA1' +
'A43E9682BABBE8DD9F8D943CB523B27965D7B11B62299583E1E53' +
'568CD7FECB4CAC7099EE');
ggg:=false;
textin:='tutorial';
sparkle:=15000000;
end;



procedure findguy;
var clll:integer;
heheheheh:boolean;
begin
heheheheh:=false;
repeat
findbitmapin(lulbmp,lulx,luly,15,16,500,297);
wait(25);
luly:=luly+10;
lulx:=lulx-5;
mmouse(lulx,luly,20,15);
until(IsUpTextMulti('talk', 'to', 'lk to')) or (isuptextmulti('open', 'pen', 'ope')) or (isuptextmulti('use', 'read', 'ange')) or (isuptextmulti('cli','imb','dow')) or (isuptextmulti('net', 'et', 'ne'));
getmousepos(lulx,luly);
mouse(lulx,luly,1,1,true);
repeat
wait(300);
clll:=clll+1;
if(findnpcchattext('tinue')) or (findnpcchattext('cook'))then heheheheh:=true;
until(heheheheh=true) or (clll=10);
if(heheheheh=false)
then
begin
wait(500);
findguy;
end;
end;

procedure talkguy;
begin
repeat;
if(findnpcchattext('tinue'))
then
begin
writeln('chatted to npc');
ClickNpcChatText('k here to',true);
wait(100);
mmouse(150,150,120,120);
repeat
wait(10);
until(findnpcchattext('ait')=false);
end;
until(findnpcchattext('inue')=false);
if(findnpcchattext('flashin')) and (not(findnpcchattext('shrimp')))then
begin
mouse(675,485,1,1,true);
wait(50);
if(findnpcchattext('flashin'))then
begin
mouse(640,186,1,1,true);
wait(50);
end;
if(findnpcchattext('flashin'))then
begin
mouse(577,187,1,1,true);
wait(50);
end;
if(findnpcchattext('flashin'))then
begin
mouse(609,187,1,1,true);
wait(50);
end;
if(findnpcchattext('flashin'))then
begin
mouse(679,187,1,1,true);
wait(50);
end;
end;
if(findnpcchattext('st loaf'))then mouse(741,485,1,1,true);
end;

procedure findnoarrow;
var gude:integer;
begin
gude:=397187
repeat
if(FindColorTolerance(lulx,luly,397187,30,30,512,295,15))then
begin
luly:=luly+15;
MMouse(lulx,luly,3,3);
end;
until(IsUpTextMulti('talk', 'to', 'alk'));
mouse(lulx,luly,1,1,true);
repeat
wait(200);
until(findnpcchattext('here to'));
end;

procedure miniwalk;
var fund:boolean;
begin
fund:=false;
repeat
if(findbitmapin(mini,lulx,luly,539,6,729,148))then
begin
mouse(lulx,luly+10,1,1,true);
fund:=true;
end else
wait(5);
until(fund=true);
flag;
wait(500);
end;

procedure genericclickheretocontinue;
begin
repeat
wait(100);
until(findnpcchattext('here to'));
clicknpcchattext('here to', true);
end;

procedure makefire;
var joke:integer;
begin
joke:=0;
mouse(645,185,1,1,true);
wait(10);
mouse(622,230,2,2,true);
wait(100);
if(joke=0)then
begin
mouse(661,229,2,2,true);
joke:=joke+1;
end else
mouse(577, 266,1,1,true);
repeat
wait(100);
until(findnpcchattext('gained so')) or (findnpcchattext('just lit')) or (findnpcchattext('burnt'));
wait(1000);
end;

procedure findtrees;
begin
if(FindColorspiralTolerance(lulx,luly,1581877,30,30,512,295,5))then
wait(10);
mmouse(lulx,luly,1,1);
if(isuptextmulti('chop', 'op d', 'hop')) and (not(isuptextmulti('oa', 'ak', 'oak')))then mouse(lulx,luly,1,1,true);
repeat;
wait(200);
until(findnpcchattext('here to'));
end;

procedure cookshrimp;
begin
repeat
wait(20);
until(findcolorspiraltolerance(lulx,luly,3650275,206,117,317,228,10));
wait(10);
mouse(705,229,1,1,true);
wait(50);
mouse(lulx,luly,1,1,true);
end;

function burnshrimp:boolean;
begin
wait(100);
if(findnpcchattext('burnt'))then result:=true;
result:=true;
end;

procedure findfish;
var count:integer;
begin
repeat
wait(10);
count:=count+1;
until(findcolorspiraltolerance(lulx,luly,sparkle,0,193,336,336,8)) or (count=10);
if(count=10)
then
begin
mouse(278,250,5,5,true);
flag;
wait(10);
findfish;
end else
begin
luly:=174+luly/2;
mouse(lulx,luly,1,1,true);
end;
flag;
wait(500);
end;

procedure fishh;
begin
repeat
wait(10);
until(findcolorspiraltolerance(lulx,luly,sparkle,0,193,336,336,8));
mmouse(lulx,luly,1,1);
wait(10);
if(isuptextmulti('Net', 'et f', 'fish'))then
begin
mouse(lulx,luly,1,1,true);
repeat
wait(200);
until(findnpcchattext('ease wa'));
repeat
wait(100);
until(not(findnpcchattext('should on')));
mmouse(1,1,1,1);
end else fishh;
end;

procedure walkbank;
begin
if(findcolortolerance(lulx,luly,243,567,10,631,65,15))then
begin
lulx:=lulx+5;
luly:=luly+15;
mouse(lulx,luly,1,1,true);
flag;
end;
end;

procedure dough;
begin
mouse(577,268,1,1,true);
wait(10);
mouse(621,268,1,1,true);
repeat
wait(50);
until(not(findnpcchattext('base')));
end;

procedure selectdough;
begin
mouse(664,267,1,1,true);
wait(10);
end;

procedure emo;
begin
mouse(709,480,1,1,true);
wait(50);
mouse(614,280,1,1,true);
wait(50);
end;

procedure walkup;
begin
mouse(675,483,1,1,true);
wait(10);
mouse(640,432,2,2,true);
wait(50);
mouse(641,20,2,2,true);
flag;
mouse(661,25,2,2,true);
flag;
if FindSymbol(lulx, luly, 'quest')then
begin
Mouse(lulx,luly,4,4,true);
wait(150+random(250));
Flag;
end;
end;

procedure prospect;
var clll:integer;
heheheheh:boolean;
begin
heheheheh:=false;
repeat
findbitmapin(lulbmp,lulx,luly,15,16,500,297);
wait(25);
luly:=luly+10;
mmouse(lulx,luly,15,15);
until(isuptextmulti('mi', 'min', 'ine'));
getmousepos(lulx,luly);
mouse(lulx,luly,1,1,false);
chooseoption('Prospect');
wait(3000);
end;

procedure minedd;
var clll,gr:integer;
heheheheh:boolean;
begin
heheheheh:=false;
repeat
findbitmapin(lulbmp,lulx,luly,15,16,500,297);
wait(25);
luly:=luly+10;
mmouse(lulx,luly,15,15);
gr:=getcolor(580,301);
until(IsUpTextMulti('Mi', 'Min', 'Mine')) or (isuptextmulti('Fur', 'urn', 'ace'));
getmousepos(lulx,luly);
mouse(lulx,luly,1,1,true);
repeat
wait(300);
clll:=clll+1;
if(findnpcchattext('tinue')) or (findnpcchattext('cook'))then heheheheh:=true;
until(heheheheh=true) or (clll=10);
if(gr<>getcolor(580,301))then heheheheh:=true;
if(heheheheh=false)
then
begin
wait(500);
minedd;
end;
end;

procedure selectore;
begin
mouse(645,188,1,1,true);
wait(10);
mouse(580,301,1,1,true);
wait(10);
end;

procedure smithd;
var clll,gr:integer;
heheheheh:boolean;
begin
heheheheh:=false;
repeat
findbitmapin(lulbmp,lulx,luly,15,16,500,297);
wait(25);
luly:=luly+10;
mmouse(lulx,luly,15,15);
gr:=getcolor(580,301);
until(IsUpTextMulti('An', 'vil', 'Anv'));
getmousepos(lulx,luly);
mouse(lulx,luly,1,1,true);
repeat
wait(300);
clll:=clll+1;
if(findnpcchattext('tinue')) or (findnpcchattext('cook'))then heheheheh:=true;
until(heheheheh=true) or (clll=10);
if(gr<>getcolor(580,301))then heheheheh:=true;
if(heheheheh=false)
then
begin
wait(500);
minedd;
end;
end;

procedure daga;
begin
mouse(32,69,1,1,true);
wait(2500);
end;

procedure attk;
var kl,kll,kkl:integer;
begin
findobj(lulx,luly,'ttack',5397083,15);
mouse(lulx,luly,1,1,true);
repeat
wait(500);
until(findcolortolerance(kl,kkl,65280,227,133,277,186,5));
kll:=getcolor(kl,kkl);
repeat
wait(1000);
until(getcolor(kl,kkl)<>kll);
end;

begin
lulsetup;
findguy;
talkguy;
findnoarrow;
talkguy;
findguy;
miniwalk;
findguy;
talkguy;
findguy;
genericclickheretocontinue;
makefire;
talkguy;
findguy;
talkguy;
miniwalk;
findguy;
findtrees;
talkguy;
makefire;
cookshrimp;
if(burnshrimp=true)then
begin
findfish;
fishh;
findtrees;
makefire;
cookshrimp;
end;
wait(100);
miniwalk;
findguy;
miniwalk;
findguy;
findguy;
talkguy;
dough;
selectdough;
findguy;
repeat
wait(200);
until(isuptextmulti('el','l d','one'));
talkguy;
miniwalk;
findguy;
emo;
makecompass('N');
walkup;
makecompass('s');
findguy;
wait(500);
miniwalk;
findguy;
talkguy;
makecompass('n');
findguy;
talkguy;
makecompass('s');
findguy;
wait(2500);
mouse(683,61,1,1,true);
flag;
miniwalk;
findguy;
talkguy;
miniwalk;
prospect;
miniwalk;
prospect;
miniwalk;
findguy;
talkguy;
miniwalk;
minedd;
talkguy;
miniwalk;
minedd;
talkguy;
miniwalk;
selectore;
minedd;
miniwalk;
findguy;
talkguy;
miniwalk;
selectore;
smithd;
daga;
miniwalk;
findguy;
flag;
miniwalk;
findguy;
talkguy;
mouse(604,432,1,1,true);
wait(100);
selectore;
miniwalk;
findguy;
talkguy;
selectore;
wait(10);
mouse(664,302,1,1,true);
wait(10);
mouse(542,185,1,1,true);
wait(5);
miniwalk;
findguy;
attk;
end.

Synthroids

2007-09-07 13:26:32

Hopefully, I will be aiding you through this development with testing.

Looking forward to it.

mat_de_b

2007-09-07 13:28:04

As for attacking the rats, get it to find the color or arrow depending on how your doing it repeat that until it finds the text in the chat window Sit back and watch, and then repeat wait until that dissperas if you need anyhelp Pm me, of look at my tut island

elementalelf

2007-09-07 13:28:36

From: Synthroids
Hopefully, I will be aiding you through this development with testing.

Looking forward to it.


check SRL members for a completed version :)
ill work on it to get it more stable in the morning, its 3:30am right now

mat_de_b

2007-09-07 13:36:31

Tried it out, it semi-screwed up the 2nd time it had to talk to the frist person and then it opened the door, and then opened it again and went back inside :D

elementalelf

2007-09-07 13:50:18

hmm… thats one part i never had a problem with.

ShowerThoughts

2007-09-08 08:55:39

From: Starblaster100
What has happened to you all?!?!?!?!?!?

[php]
function FindColorTolerance(var x, y: Integer; Color, x1, y1, x2, y2, Tol: Integer): Boolean;
[/php]

Tolerance is the end parameter!!!


man i was confused to i thought wow thats many bugs in my scripts wow.
not good not good really not good