Jump to content
Kavex

FindBitmap and mouse click bitmap

Recommended Posts

Hello Scar Divi,

 

I found this interesting program the other day and I've been playing around with it.

 

I've figured out how to find colors on the see and then push a key on the keyboard but I've been trying to figure out bitmaps and for the life of me I can't. I've try to do some searches and read the wiki and it still goes over my head.

 

I want to search for a bitmap and when it sees the bitmap then it will click on it and move onto the next command if there is one.

 

Here is what I got so far

 

[scar]

var Bitmap1: Integer;

 

procedure LoadBitmap;

begin

Bitmap1 := BitmapFromString('deNrtlNEJgDAMRG8D93EnJ3BTl1GhEESTXEyr/' +

'WnIh5Rn7qxHZkzY1mX0d727RRk66nquwvUSUgB8pgDOqBPw4ZwEjCpYeVZhOiT' +

'ilkpYb0Vi43xv4i0K0yTk3D4H/uM2fUtObiNCcQNqYhP/9BY/VaLebS636o56u' +

'xO6uJXzjm4jq9vKZ1u3suj8u4VdFLMkLN2In9Ft+wB7vHkH');

if FindBitmap(Bitmap1, 0, 0) then

 

Mouse(Bitmap1,0,0,true);

 

until(false);

end.

[/scar]

 

I know I'm think about this all wrong

Link to comment
Share on other sites

Thanks for the link but now I'm even more confused

 

So it goes something like this?

 

[scar]

var

Bmp: TSCARBitmap;

 

begin

Bmp := TSCARBitmap.Create('deNrtlNEJgDAMRG8D93EnJ3BTl1GhEESTXEyr/' +

'WnIh5Rn7qxHZkzY1mX0d727RRk66nquwvUSUgB8pgDOqBPw4ZwEjCpYeVZhOiT' +

'ilkpYb0Vi43xv4i0K0yTk3D4H/uM2fUtObiNCcQNqYhP/9BY/VaLebS636o56u' +

'xO6uJXzjm4jq9vKZ1u3suj8u4VdFLMkLN2In9Ft+wB7vHkH');

if FindBitmap (Bmp, 0, 0); then **This is where I'm getting confused now I guess**

Mouse(Bmp,0,0,true);

end;

[/scar]

 

It seemed to be easier in the older version or atleast to me it did

Link to comment
Share on other sites

A lot can be said about the new vs old versions.

 

You have it right, but I cant check the code atm. Note you need to free the bitmap when your done with it by doing Bmp.Free;

 

TSCARBitmap is a type just like integer is. Both have to be freed as well. In the old methods there was a Freebitmap procedure. So essentially all we changed here is the way we are doing it. The TSCARBirmap type was made by Freddy, is optimized compared to old methods, and provides many more options. Such as saving to a png file...

 

Edit: My bad didnt look closely. You need to remove the semi colon ; from that if then statement. Also change end; to end.

Edited by LordJashin
Link to comment
Share on other sites

Okay I am at my computer now. Watch this, run this:

 

[scar]

program New;

 

var

Bmp: TSCARBitmap;

x, y: Integer;

Box1: TBox;

Desktop: TSCARWindowClient;

 

procedure SetupCrap;

begin

Bmp := TSCARBitmap.Create('deNrtlNEJgDAMRG8D93EnJ3BTl1GhEESTXEyr/' +

'WnIh5Rn7qxHZkzY1mX0d727RRk66nquwvUSUgB8pgDOqBPw4ZwEjCpYeVZhOiT' +

'ilkpYb0Vi43xv4i0K0yTk3D4H/uM2fUtObiNCcQNqYhP/9BY/VaLebS636o56u' +

'xO6uJXzjm4jq9vKZ1u3suj8u4VdFLMkLN2In9Ft+wB7vHkH');

Desktop := TSCARWindowClient.Create(GetDesktopWindow);

SetClient(Desktop);

Box1 := GetWindowBox(GetDesktopWindow);

end;

 

 

 

begin

SetupCrap;

DebugBitmap(Bmp);

if FindBitmap(x, y, Bmp, 0, 0, Box1.X2 - 1, Box1.Y2 - 1) then

MoveMouse(x, y);

MoveMouse(0, 0);

wait(500); // half a second wait

if FindBitmap(x, y, Bmp, 0, 0, Box1.X2 - 1, Box1.Y2 - 1) then

begin

MoveMouse(x, y);

WriteLn('woot we found the bitmap at: ' + IntToStr(x) + ', ' + IntToStr(y) + ' coords' + #13#10 +

'in the search area from 0, 0 to the (width and height of the desktop) - 1');

end;

Bmp.Free;

end.

 

[/scar]

Link to comment
Share on other sites

Im bored soo i can do somewhat explaining if u want:P

 

Haha soo in his code given to you.

 

his procdure 'SetupCrap' is declaring what the variable 'Bmp' even means, and he is saying it means (a bunch of random crap) which is your actually picture.

also, you need a client to basically look at so he is declaring the variable 'Desktop' as your actualy window's desktop.

Then he is selecting the client 'Desktop' which is your actual computer's desktop.

Then the function 'DebugBitmap(Bmp);' is saying to create the picture of 'Bmp' which is delcared in 'SetupCrap' which is the picture of your little fight button.

Then he is saying if we find the picture 'Bmp' in the search area of 0,0 to Box1.x2-1,Box1.y2-1

then it will move the mouse coordinates to your found bitmap which is declared as 'x' and 'y'.

(which is all you need, but then its searching for it again for some reason?)

So then it will move to the top left of your screen or (0,0)

then wait 1/2sec.

then search for the same bitmap (picture) again

then move to that picture as 'x' and 'y'

then write a line in the debug box saying

woot we found the bitmap at: ' + IntToStr(x) + ', ' + IntToStr(y) + ' coords' + #13#10 +

'in the search area from 0, 0 to the (width and height of the desktop) - 1

Then you need that Bmp.Free; so it can free up that bitmap.

 

 

Aaannndd thats the basics of it:) Goodluck on coding in the future:)

 

 

EDIT: or use this code which doesnt search for it twice, i believe LordJashin just accidently messed up, becasue trust me, he is a phenomenal Scar coder.

[scar]var

Bmp: TSCARBitmap;

x, y: Integer;

Box1: TBox;

Desktop: TSCARWindowClient;

 

procedure SetupCrap;

begin

Bmp := TSCARBitmap.Create('deNrtlNEJgDAMRG8D93EnJ3BTl1GhEESTXEyr/' +

'WnIh5Rn7qxHZkzY1mX0d727RRk66nquwvUSUgB8pgDOqBPw4ZwEjCpYeVZhOiT' +

'ilkpYb0Vi43xv4i0K0yTk3D4H/uM2fUtObiNCcQNqYhP/9BY/VaLebS636o56u' +

'xO6uJXzjm4jq9vKZ1u3suj8u4VdFLMkLN2In9Ft+wB7vHkH');

Desktop := TSCARWindowClient.Create(GetDesktopWindow);

SetClient(Desktop);

Box1 := GetWindowBox(GetDesktopWindow);

end;

 

 

begin

SetupCrap;

DebugBitmap(Bmp);

wait(500); // half a second wait

if FindBitmap(x, y, Bmp, 0, 0, Box1.X2 - 1, Box1.Y2 - 1) then

begin

MoveMouse(x, y);

WriteLn('woot we found the bitmap at: ' + IntToStr(x) + ', ' + IntToStr(y) + ' coords' + #13#10 +

'in the search area from 0, 0 to the (width and height of the desktop) - 1');

end;

Bmp.Free;

end.

[/scar]

Edited by BryceTheCoder
Link to comment
Share on other sites

Just wanted to show it without the begin..end; block, and with it.

He summed it up pretty good. Basically though,

 

1. we are using SCAR Divi's DebugBitmap function. Which actually opens a window and shows the bitmap on SCAR's Debug Image Window.

2. Then we set the Client for SCAR's searching to the entire Desktop! So that this window will be included as well because of the size of the desktop, and it is a child window of the desktop I think.

 

Note: We could have just used SCAR's crosshairs to select the Debug Image Window that SCAR has.

Refer to this tutorial if you don't understand the client stuff - http://forums.scar-divi.com/showthread.php?1811-The-All-In-One-Beginners-Guide-To-SCAR-Divi!

 

Go to 8. SCAR Divi's AutoCompletion/Code Hints and Selecting a Client

 

If you selected it with the crosshairs, then you would use the GetClient methods to do things such as getting the box to search in.

There is also a HideDebugImgWindow; function to hide the debug window...

Edited by LordJashin
Link to comment
Share on other sites

Thanks for the explanation and i'm sure it will helps others as well

 

I wish I could program a little better but I guess this is how it starts out. You find something you want to do and learn how to do it. Now if I can only figure out how to make it move mouse to another bitmap after the first one was found then repeat the whole script from the top and work all the way down again. I've looked at other peoples script and been trying to modify the one that was given to me by LordJashin.

 

I'm sure I'll figure it out ... I hope

 

Thanks again

Edited by Kavex
Link to comment
Share on other sites

Programming is challenging, especially when you are new to it, and don't fully understand the key concepts. But if one codes and executes code enough to get results (Like on SCAR). Eventually you'll know how it works out.

 

SCAR Coding is just bold keyword usage. Its almost verbatim of english, and most signage is easy. There is no crazy C++ weird signage such as >>.

 

if

begin

end

repeat

until

for

do

 

etc. All bolded key words in SCAR Divi.

 

Just practice, try out things said in the tutorials esp. the one here, and never give up!

 

"Now if I can only figure out how to make it move mouse to another bitmap after the first one was found then repeat the whole script from the top and work all the way down again"

 

Here is how:

 

[scar]

var

Bmp, Bmp1: TSCARBitmap;

x, y: Integer;

ClientBox: TBox;

 

procedure SetupCrap;

begin

Bmp := TSCARBitmap.Create('deNrtlNEJgDAMRG8D93EnJ3BTl1GhEESTXEyr/' +

'WnIh5Rn7qxHZkzY1mX0d727RRk66nquwvUSUgB8pgDOqBPw4ZwEjCpYeVZhOiT' +

'ilkpYb0Vi43xv4i0K0yTk3D4H/uM2fUtObiNCcQNqYhP/9BY/VaLebS636o56u' +

'xO6uJXzjm4jq9vKZ1u3suj8u4VdFLMkLN2In9Ft+wB7vHkH');

Bmp1 := TSCARBitmap.Create('deNrtlNEJgDAMRG8D93EnJ3BTl1GhEESTXEyr/' +

'WnIh5Rn7qxHZkzY1mX0d727RRk66nquwvUSUgB8pgDOqBPw4ZwEjCpYeVZhOiT' +

'ilkpYb0Vi43xv4i0K0yTk3D4H/uM2fUtObiNCcQNqYhP/9BY/VaLebS636o56u' +

'xO6uJXzjm4jq9vKZ1u3suj8u4VdFLMkLN2In9Ft+wB7vHkH');

ClientBox := GetClient.ImageArea;

end;

 

 

begin

SetupCrap;

Repeat

if FindBitmap(x, y, Bmp, 0, 0, ClientBox.X2, ClientBox.Y2) then

begin

wait(1000);

MoveMouse(x, y);

if FindBitmap(x, y, Bmp1, 0, 0, ClientBox.X2, ClientBox.Y2) then

MoveMouse(x, y);

end;

until (False);

 

Bmp.Free;

Bmp1.Free;

end.

[/scar]

 

Repeat..Until False. Is an infinite loop. It will never stop, this is not recommended. You could do like Until variable i = 10, then increase the value of i in the loop.

 

We stored the Selected Clients search area (Image Area) in the variable ClientBox. Then we did, ClientBox.X2 In a box there is (X1, Y1, X2, Y2) for the 2 points in the box. X1 Y1 top left point, X2 Y2 bottom right point. So we are searching from 0, 0 to the clients width, and height for said Bitmap.

 

How do we know what goes where in the FindBitmap function?

 

[ATTACH=CONFIG]600[/ATTACH]

 

Out X, and Out Y. Means this function is going to expect a variable in place of those slots when used. So we have our X, And Y vars. If the bitmap is found, the x, and y value where it was found will be returned through whatever variables you put in the Out X, and Out Y slots.

 

Next you have the TSCARBitmap. This is the bitmap you are trying to find. Then (XS, YS, XE, YE) is pretty much the same thing as (X1, Y1, X2, Y2) This is the search area you are looking for the bitmap. And do note that SCAR has no idea unless you set the client, or use the crosshairs.

 

Finally the ): Boolean; part of that function means it will return a true or false value. If it found the bitmap it will return true. And so:

 

 

 

 

if FindBitmap(x, y, Bmp, 0, 0, 50, 50) then

WriteLn('found it');

Edited by LordJashin
Link to comment
Share on other sites

The bitmap things is really really cool. I made a bot for pokemon with your help LordJashin. It will walk around and then when it gets into a fight and it will click on fight (of course) and then on different attacks. This is really fun.

 

Thanks for taking the time to tutor a noob like myself. I think programs are only as good as the support you get from the community when your confused and stuck.

 

Trust me I've been looking up tuts and others peoples work like crazy and try to edit or break it apart.

 

Two Questions:

1. Someone told me that bitmaps take up a lot of memory. If this true?

2. When I was looking at the Bitmap Alpha Blending in the "All About TSCARBitmap" I saw Freddy changing the colors of the background. I'm looking if it's possible to ignore the back ground.

 

[scar]

Fight := TSCARBitmap.Create('');

Fight.LoadFromPng(ScriptPath + 'Fight.PNG');[/scar]

 

RLBpA.png (fight without the background)

 

Because the background is transparent it will not find it at all.

 

I have two backgrounds to worry about so I'm looking to have it just detect whats in the png and ignore any color background.

 

Color 1: 8wZ5Z.png (Color: 7175130)

 

Color 2: fnbHk.png (Color: 5070016)

 

Fight 1: T7DEJ.png

Fight 2:v9cQQ.png

 

lol soon this will be the go to infomation thread for TSCARBitmap

Edited by Kavex
Link to comment
Share on other sites

The bitmap things is really really cool. I made a bot for pokemon with your help LordJashin. It will walk around and then when it gets into a fight and it will click on fight (of course) and then on different attacks. This is really fun.

 

Thanks for taking the time to tutor a noob like myself. I think programs are only as good as the support you get from the community when your confused and stuck.

 

Trust me I've been looking up tuts and others peoples work like crazy and try to edit or break it apart.

 

Two Questions:

1. Someone told me that bitmaps take up a lot of memory. If this true?

2. When I was looking at the Bitmap Alpha Blending in the "All About TSCARBitmap" I saw Freddy changing the colors of the background. I'm looking if it's possible to ignore the back ground.

 

[scar]

Fight := TSCARBitmap.Create('');

Fight.LoadFromPng(ScriptPath + 'Fight.PNG');[/scar]

 

[ATTACH=CONFIG]601[/ATTACH] (fight without the background)

 

Because the background is transparent it will not find it at all.

 

I have two backgrounds to worry about so I'm looking to have it just detect whats in the png and ignore any color background.

 

Color 1: [ATTACH=CONFIG]602[/ATTACH] (Color: 7175130)

 

Color 2: [ATTACH=CONFIG]603[/ATTACH] (Color: 5070016)

 

Fight 1: [ATTACH=CONFIG]604[/ATTACH]

Fight 2:[ATTACH=CONFIG]605[/ATTACH]

 

lol soon this will be the go to infomation thread for TSCARBitmap

 

You can ignore the background, but it is seperate from the alpha blending system. You need to have the bitmap with a solid color background that you want to ignore. Then set the TranspColor property to that color (wihtout using alpha blending). Then just use FindBitmap and it will ignore that color on the bitmap in the search.

Link to comment
Share on other sites

Bitmaps probably do take up memory, as to how much, and what is too much I have no idea. I would imagine it would be fairly good with the new bitmap system. Maybe you could check how much memory SCAR is using after loading a couple bitmaps in the script while its still running it using Task Manager.

 

Note that no matter what, SCAR will free the bitmaps automatically for you usually. That is why you don't get any errors upon not freeing them, or you get less of them. Its still good practice to free them though when you are done using them.

Link to comment
Share on other sites

Check out the Samples folder: http://svn.scar-divi.com/scar/samples/

I think TranspColor is used in there a bunch. Freddy went through it on his videos, but maybe that will help you more.

 

For usage with Finding functions, idk much. If I remember you can't find bitmaps with transparency, or anything like that. So really all it does is exclude the color from the search when used? Maybe in conjunction with other things it would do more, not entirely sure though.

Link to comment
Share on other sites

Ok I've come across come coding issues and since it somewhat related to this current topic I might as well keep it in one spot.

 

[scar]

if FindBitmap(x, y, Chansey, 0, 0, ClientBox.X2, ClientBox.Y2) then

begin

if FindBitmap(x, y, Bait, 0, 0, ClientBox.X2, ClientBox.Y2) then

MoveMouse(x, y);

Wait(100);

ClickMouse(x, y, mbLeft);

Wait(1000);

end;

 

if FindBitmap(x, y, Chansey, 0, 0, ClientBox.X2, ClientBox.Y2) then

begin

if FindBitmap(x, y, Bait2, 0, 0, ClientBox.X2, ClientBox.Y2) then

MoveMouse(x, y);

Wait(100);

ClickMouse(x, y, mbLeft);

Wait(1000);

end;

 

if FindBitmap(x, y, Chansey, 0, 0, ClientBox.X2, ClientBox.Y2) then

begin

if FindBitmap(x, y, Ball, 0, 0, ClientBox.X2, ClientBox.Y2) then

MoveMouse(x, y);

Wait(100);

ClickMouse(x, y, mbLeft);

Wait(200);

end;

 

if FindBitmap(x, y, Chansey, 0, 0, ClientBox.X2, ClientBox.Y2) then

begin

if FindBitmap(x, y, Ball2, 0, 0, ClientBox.X2, ClientBox.Y2) then

MoveMouse(x, y);

Wait(100);

ClickMouse(x, y, mbLeft);

Wait(200);

end;

[/scar]

 

So my current code works but I'm sure it very efficient and not knowing a whole a lot of programming and when I try to change something I'm finding it catching on scar divi's debugger.

 

I'm looking for " if find Chansey then find and click on bait or bait2" then wait and do the same for ball or ball2

(bait and bait2 are two different color bitmaps as well as ball and ball2

 

I think I need to use a "else" or "or" conditional statement but I'm not sure how to go about that

Edited by Kavex
Link to comment
Share on other sites

There is OR & AND & NOT conditional operators. This is not to be mixed up with bitwise operators. XOR might be an operator too but i forget. For if statements and others you have to consider the variable types e.g if s = 'm'

s must be a string and this is saying if s has only m in its string then do this it will do whatever is after then

 

So then you can add more to the line that is before then. By doing OR or AND.

 

So: [scar]if Findbitmap or findbitmap2 then

 

if findbitmap and findbitmap2 then

 

if i > 5 then

 

If (i> 5) and findbitmap then

 

If not findbitmap or i = 10 then

 

If i >= 5 then

Writeln('i is greater than or equal to 5');

 

If condition then

DoYlthis // when there is no begin end here and there is an else no semi colon ; is at the end

Else

Dothis;

 

 

[/scar]

Edited by LordJashin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...