SRL Archive - SRL Archives

function findcentreroad(Rcolor : integer; x1,y1,x2,y2:integer; tol :integer):boolean;


solemn wishes

2006-03-25 08:26:52

hi,
im not sure why i made this but it should find the centre of a road or any object and the click it (it should :D)

*edit* i remember why i made it know :D, im going to make some walking procedures :D

[FONT="Courier New"]
program findcentreroad;
{.include SRL\SRL.scar}


function findcentreroad(Rcolor : integer; x1,y1,x2,y2:integer; tol :integer):boolean;
var
spaces ,x, y, ys, xs :integer;
a, b, c ,cent ,back :integer;
n, e , s, w :integer;
dir:string;
begin
c:=0;
ys:=0;
xs:=0;
if (FindColorTolerance(x, y, RColor, x1, y1, x2, y2, tol)) then
begin
Mmouse(x,y,3,4)
getmousepos(a,b)
cent:=a; back:=b;
begin
dir:='North';
spaces:=0;
repeat
c:=c-1;
movemousesmooth(a,b + c) Getmousepos(x,y)
wait(250+random(50))
spaces:=spaces+1;
until(not(getcolor(x,y) =Rcolor)or(spaces=20))
n:=spaces;
begin
Mmouse(cent,back,0,0)
dir:='South';
spaces:=0;
c:=1;
repeat
c:=c+1;
movemousesmooth(a,b + c) Getmousepos(x,y)
wait(250+random(50))
spaces:=spaces+1;
until(not(getcolor(x,y) =Rcolor)or(spaces=20))
s:=spaces;
begin
Mmouse(cent,back,0,0)
dir:='East';
spaces:=0;
c:=1;
repeat
c:=c+1;
movemousesmooth(a -c, b) Getmousepos(x,y)
wait(250+random(50))
spaces:=spaces+1;
until(not(getcolor(x,y) =Rcolor)or(spaces=20))
e:=spaces;
begin
Mmouse(cent,back,0,0)
dir:='west';
spaces:=0;
c:=0;
repeat
c:=c-1;
movemousesmooth(c, b) Getmousepos(x,y)
wait(250+random(50))
spaces:=spaces+1;
until(not(getcolor(x,y) =Rcolor)or(spaces=20))
w:=spaces;
begin
cent:=n/s
back:=e/w
a:=a+cent;
b:=b+back;
mouse(a,b,0,0,true)
flag;
end;
end;
end;
end;
end;
end;
end;[/FONT]

Lorax

2006-03-25 11:16:08

From: solemn wishes
hi,
im not sure why i made this but it should find the centre of a road or any object and the click it (it should :D)

*edit* i remember why i made it know :D, im going to make some walking procedures :D

............

I must say that is some pretty detectable procedure- does it need to move the mouse every time or is it on dev status ?

Wizzup?

2006-03-25 11:51:25

Thanks, always good to have people post their stuff here.

WT-Fakawi

2006-03-25 12:10:45

Hey man,

I think you are doing a great job, really, like I said before, both public and private :)
However, I think you will need to climb out of your Ivory Tower and start learning from others. I hardly ever script anymore, I just borrow from my own library or from other scripters!

You will need to learn a couple of concepts:
1. Vars are ALWAYS FALSE or 0, unless you assign them true or a value.
so, dont do s:=0; or Result:=False; in the beginning of a procedure, because it already is 0 and False.
2. Work on identing, it makes reading so much more comfortable. Regret to say, but I am having a hard time reading your code, please, please reformat
3. Understand the concept of a function returning values: var.
4. Work longer on one Function. Before I design a function or script, I first try to make a clear picture of it's logic before I start coding. Remember: it is not the Quantity, but the Quality that counts.
5. If you want to be a DemiGod of the Scripting society, you really should start working on the abovementioned!

General Tips:

If have access to a Printer, please print out every major script you can get your hands on.
Study them hard, take a Marker, mark thing you do or dont understand. try to understand the scripters logic.
Think about programmatic problems during daily routines: while biking to school for instance….
You will do fine!

Ow, and try to understand SRL, try to work with it. It is really easy to work with once you get the feeling for it :)

Keep 'm up!, and redo your functions :)

P.S.

Don't be sad, Solemn Wishes, I greatly appreciate your presence here and I admire your persistence!

[FONT="Courier New"]program New;
{.include SRL/SRL.scar}

//----------------------------------------------------------------------------//
// FindMonsterTol will Scan box for a Monster with Name, Color and Tolerance.
// Outputs True if found + the coordinates of the monster.
//----------------------------------------------------------------------------//

Function FindMonsterTol(var Mx,My:integer; MonsterName: String; monstercolor, x1, y1, x2, y2, tol:integer):boolean;
var
c:integer;

begin
if(FindColorSpiralTolerance(x,y,monstercolor,x1,y1,x2,y2,tol))Then
begin
if IsUpText(MonsterName) then
begin
Mmouse(x,y,5,4);
Mx:=x;
My:=y;
Result:=true;
Exit;
end;
end
else
begin
repeat
wait(500+random(500))
c:=c+1;
if(FindColorSpiralTolerance(x,y,monstercolor,x1,y1,x2,y2,c))then
begin
if IsUpText(MonsterName) then
begin
Mmouse(x,y,5,4);
Mx:=x;
My:=y;
Result:=true;
Exit;
end;
end;
until Result or(c>=tol);
end;
if not Result then
Writeln('Monster NOT Found');
end;

//-----Main Loop----//

begin
SetupSRL;
FindMonsterTol(x,y,'Name',1345684,MSX1,MSY1,MSX2,MSY2,50);
end.[/FONT]

This is your original code:
[FONT="Courier New"]function monstertolerance(xcord1,ycord1,xcord2,ycord2:integer):boolean;
var c,tolmonster,tol:integer;
begin
tol:=0;
c:=0;
if(FindColorSpiralTolerance(x,y,monster,xcord1,ycord1,xcord2,ycord2,tol))Then
begin
Mmouse(x,y,5,4)
writeln('//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
writeln(' Monster visable on screen, no tolerance needed')
writeln('//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
found:=true;
end;
if(found=false)then
begin
writeln('//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
writeln(' No monster is visable on the screen')
writeln(' Creating a monster tolerance')
writeln('//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
monsterfound:=false;
tolmonster:=monster;
repeat
wait(500+random(500))
tol:=tol+1;
c:=c+1;
writeln('monster color :'+inttostr(tolmonster))
if(FindColorSpiralTolerance(x,y,tolmonster,xcord1,ycord1,xcord2,ycord2,tol))then
begin
monsterfound:=true;
Mmouse(x,y,5,4)
end;
until(monsterfound=true)or(c=30)
if(c=30)then
writeln('')
writeln('//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
writeln('')
writeln('Increased tolerance to 30, monster is still not visable')
writeln(' Unable to find the monster, color may be wrong')
writeln('')
writeln('//////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
result:=false;
end;
end;[/FONT]

Renax

2006-03-25 13:13:57

or, you just use FindColorSpiral2 for finding the center of a color. and you don't need a writeln('') in your procedures i find it very un-pleasing to the eye.

Lorax

2006-03-26 07:21:56

From: WT-Fakawi

Think about programmatic problems during daily routines: while biking to school for instance….

Jesus christ are you a female or what? Othervise you may have noticed that it's impossible for lads to multi-task. That's why I never script and walk to dog on the same time *like in my mind*.