PDA

View Full Version : The Beauty of FindObjCustom



Goobs
07-12-2008, 04:49 AM
Hi there! I'm ProphesyOfWolf~

INTRODUCTION

What is FindObjCustom, and how can you use it? Well, it's pretty simple. Let me start by showing you what it looks like.

function FindObjCustom(var cx, cy: Integer; Text: TStringArray; Color: TIntegerArray; Tol: Integer): Boolean;

Okay, so you may be thinking "OMG WTF IS THAT?". All in due time, young Padawan.

FindObjCustom finds an object with color(s) stored in the TIntegerArray Color, and with the uptext(s) stored in the TStringArray Text. Then, it stores the co-ordinates of said object to the values cx, cy, for use with other functions.
Tol is the tolerance that the function uses to increase the likelyhood of finding that object.

Okay, let's try to make this easier to understand.

Let's start with the TIntegerArray Color. As the name implies, it's an array of integers, which, in this case, are colors. This array stores colors like so:

FindObjCustom(cx, cy, Text, [234543, 456456, 345765], Tol);

The nice thing about this function is that you can use as many or as few colors as you'd like to. You can store them the way I did above, with the color value in the array, or you can do something like this:

procedure Tutorial;
var
Color1, Color2, Color3: Integer;
begin
Color1 := 1234123;
Color2 := 3213213;
Color3 := 4566545;
FindObjCustom(cx, cy, Text, , Tol);
end;

It can save you a lot of time if you're dealing with a lot of colors. So far, so good?

Okay, next thing we'll talk about is the TStringArray Text. It's basically the same idea as the Colors we just discussed, except!.. You put in parts of the uptext that shows when you put your mouse over the object. For example:

Let's say you're making a script to find and kill chickens. You'd want to set the colors of the chicken up in Colors (2 or 3 will do) before you do anything else. Then, figure out the uptext that pops up when your mouse over the object, in this example, a chicken. It would say 'Attack Chicken'.

What do we put in Text? It's pretty easy.

Take parts out of the uptext. I find that this makes it work alot better in the long run. So, instead of doing:

FindObjCustom(cx, cy, ['Attack Chicken'], [123412,1234234,123423], Tol);

You'd want to do something like:

FindObjCustom(cx, cy, ['tta', 'ack', 'hick', 'ken'], [123412,1234234,123423], Tol);

That way, it makes sure to pick up your chicken.

Just remember: At this point, it simply finds the Chicken, but does not click it. You'd just have to follow up with Mouse, which I'll cover later.

Okay, now for Tol. It's pretty simple, also.

Each color you chose has a specific value, no? Meaning that it's a very precise color. Tolerance makes the function check for any color within a specified number around your colors that you chose earlier. Okay, easy to use, hard to explain.

Usually, just use a number from 1 to 10 (higher depending on what you're looking for). I usually use around 5.

Okay.. Last, but not least, comes CX and CY. They are the x and y values that the function stores the object's location at. Usually, you'd just put in x, y rather than cx, cy. Here, I'll show you.

FindObjCustom(x, y, ['tta', 'ack', 'hick', 'ken'], [123412,1234234,123423], 5);

This way, you can use it with other functions (Though, technically, you can put any thing in for the x, y, value. X and Y are just easier to remember :)), such as Mouse. Here's what it would look like:

FindObjCustom(x, y, ['tta', 'ack', 'hick', 'ken'], [123412,1234234,123423], 5);
Mouse(x, y, 2, 2, True);

Okay! So now you know how it works! I'll now show you how to work it into a simple script!

[COLOR="Red"]NOT THE INTRODUCTION ANYMORE

Let's do one of the simplest of scripts out there = a woodcutter. It can just be a script that finds and cuts down trees. I'll show you a simple one:

program Tutorial;
{.include SRL/SRL.scar}
var
x, y, Color1, Color2, Color3: Integer;

procedure FindAndChopTrees;
begin
Color1 := XXXXXXX; //This won't compile unless you change the X's to an actual number.
Color2 := XXXXXXX;
Color3 := XXXXXXX;
If (FindObjCustom(x, y, ['hop', 'ree'], , 5) then
begin
If(IsUptext('Chop Tree')) then //Forgot to mention this.. It's a great failsafe!
begin
Mouse(x, y, 2, 2, True);
end;
end;
end;

begin
FindAndChopTrees;
end.

(Also.. [COLOR="Red"]DON'T ACTUALLY AUTO WITH THIS SCRIPT! IT'S FOR EXAMPLE PURPOSES ONLY!)

COLOR FINDING

Confused on what I'm talking about involving colors, and getting them? Look no further!

SCAR has a nice little color picking tool build in. It looks like a little eyedropper:

http://www.fileden.com/files/2007/2/21/804553/Screen1.PNG

What I do is take a screenshot of what I'm getting colors of. You can do this by hitting Print Screen at the top of your keyboard, then pasting it into Paint. Drag SCAR down so you can see the object above SCAR in paint, and click the tool. Move your mouse around until you find the colors you want on the object (Try to find the colors on it that stick out the most), then click your mouse. Repeat this until you have all the colors you need. Then, look in SCAR's debug box and, wham! It will show you the colors you got, and the location it found them in.

Example:

http://www.fileden.com/files/2007/2/21/804553/Screen2.PNG

Now your colors are ready to use!

THE ENDISH

Okay, it was a short tutorial (sort of). I hope you learned something from it, because I've been here for about an hour working on it. Just post if you have any questions, and I'll answer them the best I can.

Until next time,

ProphesyOfWolf AKA Faelstorm

SubiN
07-12-2008, 04:55 AM
nice tut.. Wud be better if it had sum examples with pictures =]

Goobs
07-12-2008, 05:03 AM
I have some examples there, and whatdya mean by pictures? =D

SubiN
07-12-2008, 05:08 AM
show them how to get the colour codes etc =].

Goobs
07-12-2008, 05:21 AM
Updated ^^^

:)

Lee Lok Hin
07-12-2008, 05:33 AM
You could also tell them to just


var
i:Tintegerarray;


And


i:=[XXX,YYY,TTXXYY];


That would make declaring the colours faster. Incidentally, I think this belongs in the beginners section, because Intermediates to advanced use Findobjtpa and other custom finders. Still, great tut.

Rep to you.

Goobs
07-12-2008, 05:44 AM
Indeed, I forgot about declaring the TIntegerArray's that way. Thanks for including it =D

Thanks for the rep + =D

Congratulations! Your rep level has gone from INFINITY to INFINITY + 1!

Claymore
07-12-2008, 06:40 AM
FindObjCustom is horrible for me....

EvilChicken!
07-12-2008, 07:33 AM
Very nice tutorial, but I would prefer if you taught the use of FindObjectTPA instead, as I (and many others) find it much more efficient.

Waltzing Mouse
07-12-2008, 07:46 AM
Good tutorial, I might use this function in a powerminer.