SRL Archive - OSR Help

What am I doing wrong?[should be quick fix]


rj

2012-11-27 16:35:48

What am i doing wrong here?

procedure ClickNPC;
var
X, Y,cx,cy: Integer;
begin // kill npc
WriteLn('Attacking skeleton...');
if FindColorTolerance(X, Y, NPC, tleft, tright, bleft, bright, tolerence) then
begin
GetMousePos(cx,cy);
MouseSpeed:=40;
mmouse(x, y,1,1);
Wait(20 + Random(50));
ClickMouse(X, Y, Mouse_Left);
if FindColorTolerance(x,y,65535,cx-10,cy+10,cx+10,cy-10,5) then
begin
ClickNPC;
end;
WriteLn('Attacked skeleton!');
CheckCombat;
end;
end;

Error: Exception: You passed wrong values to a finder function: ys > ye (116,96). at line 67
The following bitmaps were not freed: [0]

YoHoJo

2012-11-27 17:56:47

if FindColorTolerance(x,y,65535,cx-10,cy-10,cx+10,cy+10,5) then

Maybe had +s and -s wrong? Try that.

rj

2012-11-27 18:13:23

From: YoHoJo
if FindColorTolerance(x,y,65535,cx-10,cy-10,cx+10,cy+10,5) then

Maybe had +s and -s wrong? Try that.


what do you mean. lol

YoHoJo

2012-11-27 18:18:12

Compare your line to mine.
From the first two you need to subtract, from the last two you need to add.
You did + - + -
I did - - + +

Enslaved

2012-11-27 18:24:00

From: rjj95
What am i doing wrong here?

procedure ClickNPC;
var
X, Y,cx,cy: Integer;
begin // kill npc
WriteLn('Attacking skeleton...');
if FindColorTolerance(X, Y, NPC, tleft, tright, bleft, bright, tolerence) then
begin
GetMousePos(cx,cy);
MouseSpeed:=40;
mmouse(x, y,1,1);
Wait(20 + Random(50));
ClickMouse(X, Y, Mouse_Left);
if FindColorTolerance(x,y,65535,cx-10,cy+10,cx+10,cy-10,5) then
begin
ClickNPC;
end;
WriteLn('Attacked skeleton!');
CheckCombat;
end;
end;

Error: Exception: You passed wrong values to a finder function: ys > ye (116,96). at line 67
The following bitmaps were not freed: [0]

You are calling the exact same function, as it is detected the first time round, it will also be detecting the second time round . etc, henceforth you just made a endless loop there mate.

Try doing something along the lines of this - based on your code

if FindColorTolerance(X, Y, NPC, tleft, tright, bleft, bright, tolerence) then
begin
MouseSpeed:=40;
mmouse(x, y,1,1);
GetMousePos(cx,cy);// shifted this so it grabs the co-ords of the moved mouse position and checks in that box there
Wait(20 + Random(50));
if FindColorTolerance(x,y,65535,cx-10,cy+10,cx+10,cy-10,5) then
begin
ClickMouse(X, Y, Mouse_Left);// if colour isfound in the mousebox around the area surrounding where first colour was found, then click on that colour spot
end;
WriteLn('Attacked skeleton!');
CheckCombat;
end;

rj

2012-11-27 19:05:24

From: Enslaved
You are calling the exact same function, as it is detected the first time round, it will also be detecting the second time round . etc, henceforth you just made a endless loop there mate.

Try doing something along the lines of this - based on your code

if FindColorTolerance(X, Y, NPC, tleft, tright, bleft, bright, tolerence) then
begin
MouseSpeed:=40;
mmouse(x, y,1,1);
GetMousePos(cx,cy);// shifted this so it grabs the co-ords of the moved mouse position and checks in that box there
Wait(20 + Random(50));
if FindColorTolerance(x,y,65535,cx-10,cy+10,cx+10,cy-10,5) then
begin
ClickMouse(X, Y, Mouse_Left);// if colour isfound in the mousebox around the area surrounding where first colour was found, then click on that colour spot
end;
WriteLn('Attacked skeleton!');
CheckCombat;
end;


The whole point is a failsafe, if it misclicks the skeleton or hits a different color, it searches again

Daniel

2012-11-27 21:40:37

This line:
[indent]

if FindColorTolerance(x,y,65535,cx-10,cy+10,cx+10,cy-10,5) then
[/indent]

Notice that you are not searching in a box starting from the top-left to the bottom-right. Instead, you are searching from the bottom-left to the top-right - Simba does not support this. The top-left should be (cx-10, cy-10), and the bottom-right should be (cx+10, cy+10). See, in your function, you did the cy+10 first, and the cy-10 second. Simply reverse these and you should be right. :)

YoHoJo

2012-11-27 21:48:13

From: Daniel
This line:
[indent]

if FindColorTolerance(x,y,65535,cx-10,cy+10,cx+10,cy-10,5) then
[/indent]

Notice that you are not searching in a box starting from the top-left to the bottom-right. Instead, you are searching from the bottom-left to the top-right - Simba does not support this. The top-left should be (cx-10, cy-10), and the bottom-right should be (cx+10, cy+10). See, in your function, you did the cy+10 first, and the cy-10 second. Simply reverse these and you should be right. :)


How dare you re-word what I said and try and one up me!


Rjj95, what you are doing is this:

Searching from bottom left to top right.

Simba only searches from top left to bottom right.
So by switching your +s and -s around like Daniel and I have said, you will need to tell Simba the top left and bottom right coordinates of the box you wish to search, then it will work!

rj

2012-11-27 21:50:27

if FindColorTolerance(X,Y,65535,cx+10,cy+10,cx-10,cy-10,20) then  

still gives me an error lol

riwu

2012-11-27 21:52:34

When you subtract a number, it becomes smaller; when you add a number, it becomes larger.
xs, ys should be smaller than xe, ye, or else you won't have a box.
So you should subtract xs ys and add xe ye by that variable.

rj

2012-11-27 21:54:35

From: riwu
When you subtract a number, it becomes smaller; when you add a number, it becomes larger.
xs, ys should be smaller than xe, ye.
So you should subtract xs ys and add xe ye by that constant.


i used
if FindColorTolerance(X,Y,65535,cx+10,cy+10,cx,cy,20) then  
And it still gives me an error

Daniel

2012-11-27 21:55:02

From: YoHoJo
How dare you re-word what I said and try and one up me!


Lol, I didn't even read what you said :p

From: rjj95
i used
if FindColorTolerance(X,Y,65535,cx+10,cy+10,cx,cy,20) then  
And it still gives me an error


Okay, think of it like this. You have to give it X, Y, Colour, X1, Y1, X2, Y2, Tolerance. You have given the function all of those successfully, except for the X1, Y1, X2, and Y2. Your X1 and Y1 are larger than X2 and Y2, this simply isn't allowed. X1 and Y1 always has to be smaller than X2 and Y2, and not the other way around.

riwu

2012-11-27 21:56:04

From: rjj95
i used
if FindColorTolerance(X,Y,65535,cx+10,cy+10,cx,cy,20) then  
And it still gives me an error

Ok, read carefully word by word of all the previous posts. You are not reading.

rj

2012-11-27 21:58:02

From: riwu
Ok, read carefully word by word of all the previous posts. You are not reading.


Can you give me an example?

Daniel

2012-11-27 21:58:32

From: rjj95
Can you give me an example?


Please re-read my edited post, above.

rj

2012-11-27 22:03:37

From: Daniel
Please re-read my edited post, above.


ok so now i put
if FindColorTolerance(X,Y,65535,cx-10,cy-10,cx+10,cy+10,20) then 
no errors, great… but now it does not work

YoHoJo

2012-11-27 22:04:07

Look at my post too (#2, and the picture one).
Simple change your line, to be like the line I posted in post #2, easy.

rj

2012-11-27 22:13:45

From: YoHoJo
Look at my post too (#2, and the picture one).
Simple change your line, to be like the line I posted in post #2, easy.


I did use it, It does not work.

The way im testing this is, I make the mouse speed really slow so that is 99% chance not to click on it therfor showing the yellow click marks:

procedure ClickNPC;
var
X, Y,cx,cy: Integer;
begin // kill npc
WriteLn('Attacking skeleton...');
if FindColorTolerance(X, Y, NPC, tleft, tright, bleft, bright, tolerence) then
begin
MouseSpeed:=5;
mmouse(x, y,1,1);
GetMousePos(cx,cy);
ClickMouse(X, Y, Mouse_Left);
//if FindColorTolerance(X,Y,65535,cx-10,cy-10,cx+10,cy+10,20) then
if FindColorTolerance(x,y,65535,cx-10,cy-10,cx+10,cy+10,5) then
begin
WriteLn('Shit, we misclicked retrying!');
ClickNPC;
end else
WriteLn('Attacked skeleton!');
CheckCombat;
end;
end;



But.. I used your method and It did not repeat the procedure like it is suposed to.

YoHoJo

2012-11-27 22:27:32

Currently you are
Looking for NPC color
Slowly moving the mouse to it
Once mouse is there, you are calling that point cx,cy
Left Clicking it
Then looking for color 65535

Add more writeln lines and stuff to debug it and see what's going on.

What is color 65535 anyways? And why are you moving the mouse slowly?

rj

2012-11-27 22:38:31

From: YoHoJo
Currently you are
Looking for NPC color
Slowly moving the mouse to it
Once mouse is there, you are calling that point cx,cy
Left Clicking it
Then looking for color 65535

Add more writeln lines and stuff to debug it and see what's going on.

What is color 65535 anyways? And why are you moving the mouse slowly?


65535 is yellow, and im moving the mouse slow for now so it misclicks the skeleton, and i was hopping the bot would see the misclick(yellow) and repeat the procedure

YoHoJo

2012-11-28 00:21:31

Look up the function DidRedClick and see if that helps you out.

Runehack123

2012-11-28 00:53:01

There's also a DidYellowClick function. :)

rj

2012-11-28 15:46:09

Ok, So I tried using the redclick function and it works some of the time. But after it clicks the skeleton, it clicks it again and again and sometimes stops and go ons to the next procedure

procedure ClickNPC;
var
X, Y,cx,cy: Integer;
begin // kill npc
Wait(650 + Random(150));
WriteLn('Attacking skeleton...');
if FindColorTolerance(X, Y, NPC, tleft, tright, bleft, bright, tolerence) then
begin
MouseSpeed:=25;
mmouse(x, y,1,1);
ClickMouse(X, Y, Mouse_Left);
if DidRedClick then
begin
WriteLn('Attacked skeleton!');
CheckCombat;
end else
WriteLn('Shit, we misclicked retrying!');
ClickNPC;
end;
end;