SRL Archive - OSR Help

make it search crates?


peeweewoen

2012-05-17 22:37:27

well guyzz,
i'm trying to make a script that searches crates in Wydin's food shop (in Port Sarim), more specifically, the 2 crates stacked on top of each other, the one that gives you raw chicken.

Now, I'm not really sure how I would go about doing this. I could use FindObjMulti() or sumthin but that might not work, since there are 2 other crates of pretty much the same color in that room…

I could also use TPAs, but I am a beginning scripter, and I'm also kinda too lazy to learn about em :P

The setup is with a pile of 2 crates on the North part of the small room, 1 crate in the middle part of the room (with a banana on top of it), and 1 crate slightly South of that (with a white apron on top of it). Each pile is spaced about 1~2 tiles apart from each other.

Now if I really had to learn TPAs I shall commence to do that.
But I really hope I don't have to yet :P

I was wondering if I could somehow use DTMs or the fact that it is a stack of 2 crates, or the fact that there are items on top of the other crates, to get SIMBA to click the right crate.

Any ideas?

Thanks in advance,
Peeweewoen

Brandon

2012-05-17 23:01:02

Find Object In Object. Basically you find the colour of the floor the crates are on.. Pass it to the function below. Next find the outline of the crates and pass it to the previous call. Finally Find the one crate that stacks on the second crate and pass it to the function below. It will return you a TPA of the exact crate you want.


Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS, L, I: Integer;
TPACopy: TPointArray;
ATPA, ATPA2: T2DPointArray;
B: TBox;
begin
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);

if (Length(TPA) < 1) then
Exit;

TPACopy:= CopyTPA(TPA);
if (Length(TPACopy) < 1) then
Exit;

ATPA:= TPAToATPAEx(TPACopy, Width, Height);
SortATPASize(ATPA, True);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);

For I:= 0 To L do
begin
B := GetTPABounds(ATPA[I]);
with B do
begin
FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
if (Length(ATPA2[I]) < 1) then
Continue;
end;
end;
if (Length(ATPA2) > 0) then
Result:= MergeATPA(ATPA2)
else
Result:= [];

ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
end;



Can be used like this:

Crate On Crate In Outline on floor. Make sense I hope Example of Marble altar:


Function FindAltar: Boolean;
var
CTS, X, Y: Integer;
TPA, TPA2, TPA3: TPointArray;
begin
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.10, 0.20);
FindColorsTolerance(TPA, 3096661, 0, 0, 1000, 617, 11); //Finds the brown outline of the altar..
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);

If Length(TPA) < 1 then
Exit;

TPA2:= FindObjectInObject(TPA, 10726065, 186, 138, 23, [0.37, 0.36]); //With the brown outline, search inside it for the white marble..
If (Length(TPA2) < 1) then
Exit;

TPA3:= FindObjectInObject(TPA2, 10458003, 186, 138, 16, [0.11, 0.14]); //With the white marble, search inside that for the prayer book..
If (Length(TPA3) < 1) then
Exit;

MiddleTPAEx(TPA3, X, Y); //Our altar is found 100% of the time.
MMouse(X, Y, 0, 0);
end;

peeweewoen

2012-05-17 23:26:37

lol Great idea!
i would never have thought of that
thanks for the input :]

+rep