PDA

View Full Version : Using a Tbox



Lolsen
03-02-2014, 09:51 AM
Hi guys,

Have been really active in asking questions lately and am sorry about that, feeling like a pest :P

However I will ask a question about Tboxes

So with T boxes, can I instantly create a tbox after a click, so after I've used findobject can I get it to create a tbox around the findobject? So I can then search for a colour within the Tbox?


My use of this, is my script finds a certain bush, it then clicks it and an item appears next to the bush, I need a tbox around the bush so I can search within the Tbox only for the item because the item is the same colour as another part of the screen, if you have any other recommendations for this please say :)

riwu
03-02-2014, 10:42 AM
Yeah something like:
GetMousePos(x,y);
box:= IntToBox(x-5, y-5, x+5, y+5);
will create a size-10 box around the mouse position.

sdf
03-02-2014, 12:07 PM
It's best you write your own object finder.

Here's an example:
if FindColorsTolerance(BoundsTPA, colour, mainScreen.getBounds(), tolerance, colorSetting(2, hue, sat)) then
begin
Bounds2D := BoundsTPA.split(100,100); //I prefer to use cluster, but use whatever you need it for.
Bounds2D.sortBySize; //or any other sorting method here, depending on what you are finding.

if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
begin //uses the bounds of the first found object to find colours within it.
Inner2D := InnerTPA.cluster(20);
Inner2D.sortBySize;

for i:=low(Inner2D) to high(Inner2D) do
begin
smartImage.clearArea(mainScreen.getBounds);
smartImage.debugATPA(Inner2D);
smartImage.debugTPA(Inner2D[i]);
MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN); //from this line, it goes through each valid ATPA and performs an action
if (chooseOption.select(['some option here'], 500)) then
begin
//actions to perform.
end;
end;
end;
end;

Riwu's example would be a simpler method, but less dynamic I suppose.

Lolsen
03-03-2014, 06:33 AM
It's best you write your own object finder.

Here's an example:
if FindColorsTolerance(BoundsTPA, colour, mainScreen.getBounds(), tolerance, colorSetting(2, hue, sat)) then
begin
Bounds2D := BoundsTPA.split(100,100); //I prefer to use cluster, but use whatever you need it for.
Bounds2D.sortBySize; //or any other sorting method here, depending on what you are finding.

if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
begin //uses the bounds of the first found object to find colours within it.
Inner2D := InnerTPA.cluster(20);
Inner2D.sortBySize;

for i:=low(Inner2D) to high(Inner2D) do
begin
smartImage.clearArea(mainScreen.getBounds);
smartImage.debugATPA(Inner2D);
smartImage.debugTPA(Inner2D[i]);
MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN); //from this line, it goes through each valid ATPA and performs an action
if (chooseOption.select(['some option here'], 500)) then
begin
//actions to perform.
end;
end;
end;
end;

Riwu's example would be a simpler method, but less dynamic I suppose.



This sounds like the right idea, just need to get my head around it, I'll show you what I have so far.

procedure findNeverBerryBush();
var
findObject, x, y, i: integer;
begin
if not isLoggedIn() then
exit;

repeat
mainscreen.findObject(x, y, 1657928, 2, colorSetting(2, 1.29, 6.63), mainscreen.playerPoint, 40, 40, 30, ['arget', 'ush'], MOUSE_LEFT);
wait(randomRange(1000, 2000));
inc(i);

until;
end;


This is really simple what I've used, just wondering how I'd implement that variable and be able to start using it?

also will I in the future be able to implement pixelshift? cheers

Clarity
03-03-2014, 06:46 AM
How dare you ask questions and try to learn how to script, unlike 75% of the people who browse these forums. Reporting for spam. ;D

In my charms sprite script, I have a global variable called "bushLocation" which updates after the sprite lure is activated and the sprites come out of the bush.

The problem with a limited search is that the sprites move so fast that it's hard to come up with any sort of universal search boundary. So instead, I sort the ATPA of recognized charm sprites in order of proximity to the bush.

ATPA.sortFromMidPoint(bushLocation);

Hope it's going well for you! :)

sdf
03-03-2014, 07:03 AM
Basically, instead of using findObject you'll have to use something like I wrote above since findObject doesn't output a TPA for us to grab bounds to find the second colour. Your entire findObject line will be replaced in your procedure.

I don't use/never tried using findObject, but I take it you've got it left clicking once on a bush (but you can't seem to differentiate between shaking and non-shaking bushes? [assuming you're making a sprite charm hunter]). Pixelshift is definitely possible, but I would imagine it would be slow in finding shaking bushes since you would be checking over one search area at a time for x-amount of time in a field of 10+ bushes (unless of course you are using this to confirm shaking bushes after the secondary colour search).

A function (albeit messy) you would use would be like this (haven't tested):
function findActiveBush(colour1, colour2, tolerance1, tolerance2: Integer; hue1, sat1, hue2, sat2: Extended): Boolean;
var
BoundsTPA, InnerTPA: TPointArray;
Bounds2D, Inner2D: T2DPointArray;
i: Integer;
begin
if FindColorsTolerance(BoundsTPA, colour1, mainScreen.getBounds(), tolerance1, colorSetting(2, hue1, sat1)) then
begin
Bounds2D := BoundsTPA.split(100,100); //I prefer to use cluster, but use whatever you need it for.
Bounds2D.sortBySize; //or any other sorting method here, depending on what you are finding.

if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
begin //uses the bounds of the first found object to find colours within it.
Inner2D := InnerTPA.cluster(20);
Inner2D.sortBySize;

for i:=low(Inner2D) to high(Inner2D) do
begin
smartImage.clearArea(mainScreen.getBounds);
smartImage.debugATPA(Inner2D);
smartImage.debugTPA(Inner2D[i]);
MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN); //from this line, it goes through each valid ATPA and performs an action
if (chooseOption.select(['some option here'], 500)) then
begin
result := true;
//actions to perform.
end;
end;
end;
end;
end;

If you get exceptions with drawing, edit out the smartImage lines or enable smart drawing in your script.

Lolsen
03-03-2014, 10:01 AM
Thanks heaps clarity, you've been a lifesaver, that pest message was directed towards you probably 60% as I felt I'd kept asking silly questions :P





Basically, instead of using findObject you'll have to use something like I wrote above since findObject doesn't output a TPA for us to grab bounds to find the second colour. Your entire findObject line will be replaced in your procedure.

I don't use/never tried using findObject, but I take it you've got it left clicking once on a bush (but you can't seem to differentiate between shaking and non-shaking bushes? [assuming you're making a sprite charm hunter]). Pixelshift is definitely possible, but I would imagine it would be slow in finding shaking bushes since you would be checking over one search area at a time for x-amount of time in a field of 10+ bushes (unless of course you are using this to confirm shaking bushes after the secondary colour search).

A function (albeit messy) you would use would be like this (haven't tested):
function findActiveBush(colour1, colour2, tolerance1, tolerance2: Integer; hue1, sat1, hue2, sat2: Extended): Boolean;
var
BoundsTPA, InnerTPA: TPointArray;
Bounds2D, Inner2D: T2DPointArray;
begin
if FindColorsTolerance(BoundsTPA, colour1, mainScreen.getBounds(), tolerance1, colorSetting(2, hue1, sat1)) then
begin
Bounds2D := BoundsTPA.split(100,100); //I prefer to use cluster, but use whatever you need it for.
Bounds2D.sortBySize; //or any other sorting method here, depending on what you are finding.

if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
begin //uses the bounds of the first found object to find colours within it.
Inner2D := InnerTPA.cluster(20);
Inner2D.sortBySize;

for i:=low(Inner2D) to high(Inner2D) do
begin
smartImage.clearArea(mainScreen.getBounds);
smartImage.debugATPA(Inner2D);
smartImage.debugTPA(Inner2D[i]);
MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN); //from this line, it goes through each valid ATPA and performs an action
if (chooseOption.select(['some option here'], 500)) then
begin
result := true;
//actions to perform.
end;
end;
end;
end;
end;

If you get exceptions with drawing, edit out the smartImage lines or enable smart drawing in your script.


Hey thanks for that, I do get one exceptio

for i:= low(Inner2D) to high(Inner2D) do


I just thought I'd put it in and see if it came back with any exceptions and that's the only exception :P

sdf
03-03-2014, 10:31 AM
see above edited post.