SRL Archive - SRL Archives

Better DTM-finding on the Main-Screen


King of Knives

2007-11-05 15:35:56

I was about to make a script for something. Incidently the script involved door opening (If the door wasn't open already). The door-DTM I made was found a few other places on the screen, so I got an idea. Screen-Splitting.

So, what I made was a little procedure that divides the Main-screen up into smaller boxes, giving something similar to skipboxes. Along with the Screen-Splitter, there is a DTM finder, which will search all of the boxes for a DTM. If the DTM is found, it will hover over. If the specified uptext is found, it will exit the procedures, and if not, it will simply continue searching in the remaining boxes.

Give me a post. Why you you like it or not, what could be better, bugs, if any (I believe there shouldn't be any, though), and so on.

—-

Code:

Function SplitScreen(Px,Py: Integer): TBoxArray; // Px = Boxes on x-axis
var // Py = Boxes on y-axis
I,O,Dx,Dy,Xx,Xy,T: Integer;
Sx,Sy: TIntegerArray;
begin
SetArrayLength(Sx,Px+1)
SetArrayLength(Sy,Py+1)
SetArrayLength(Result,Px*Py)
Dx:= Round(511 / Px);
Dy:= Round(333 / Py);
Xx:= 511 Mod Dx;
Xy:= 333 Mod Dy;
for I:= 0 to Px-1 do
begin
Sx[I]:= 4+(I*Dx)
end;
Sx[Px]:= Sx[Px-1]+Dx+Xx-4;
for I:= 0 to Py-1 do
begin
Sy[I]:= 4+(I*Dy)
end;
Sy[Py]:= Sy[Py-1]+Dy+Xy-4;
for I:= 0 to Py-1 do
begin
for O:= 0 to Px-1 do
begin
Result[T].x1:= Sx[O];
Result[T].x2:= Sx[O+1];
Result[T].y1:= Sy[I];
Result[T].y2:= Sy[I+1];
T:= T + 1;
end;
end;
end;

Function FindDTMSSUpText(DTM: Integer; var a,b: Integer; UpText: String; SSBox: TBoxArray): Boolean;
var I: Integer;
begin
for I:= 0 to GetArrayLength(SSBox)-1 do
begin
if FindDTM(DTM,a,b,SSBox[I].x1,SSBox[I].y1,SSBox[I].x2,SSBox[I].y2) then
begin
MMouse(a,b,0,0)
Wait(200+random(200))
if IsUpText(UpText) then
begin
GetMousePos(a,b)
Result:= True;
Exit;
end;
end;
end;
end;

var a,b,Door: integer;

begin
ClearDebug;
SetupSRL;
Door := DTMFromString('78DA633465646088644001539A92193480342' +
'394CF68016445A0AAE9AD894555E380A9A6AB3206558D1B116ACC' +
'81AC3854354B27E6A3AAB1C154B3B83F17558D3DA69ABAFC10543' +
'5EE4498E30A6445E3F73B00B3471410');
ScreenBoxes:= SplitScreen(5,10)
if FindDTMSSUpText(Door,a,b,'pen',ScreenBoxes) then
begin
Mouse(a,b,0,0,true)
end;
FreeDTM(Door)
end.

Enjoy,

-Knives

Special Ed

2007-11-05 16:10:13

Huzzah! Another Object Finder!

I'll be a good sport and test this one though, lemme see, I'll try harpoon, bones, and… feather?

King of Knives

2007-11-05 16:13:37

This is for the mainscreen :P If it was for the inventory, it would be useless. It probably works best on bigger objects, but I don't know, really. But it can also be modified to work with bitmaps, rotated DTMs, deformed bitmaps and so on…

-Knives

Special Ed

2007-11-05 19:42:03

Yea I was talking about finding those objects on the ground… Like when you drop them, ect. I haven't gotten to it yet, I'm working hard on my powerfisher atm. I'll try to get the test in tonight at least thought, hopefully… :)

JuKKa

2007-11-06 00:53:48

I made this exact same thing but it returned in a TPA..

Suggestion to freddy: Add
Procedure FindDTMS(DTM: Integer; Var TPA: TPointArray; X1, Y1, X2, Y2: Integer);

BobboHobbo

2007-11-06 01:07:27

Useful for fishing :D like loosing your cage, harpoon and etc. I like it :)

mat_de_b

2007-11-06 01:32:58

Waht happens if your DTM is on the line of 2 different boxeS?

King of Knives

2007-11-06 08:59:11

It probably won't find it… Haven't tried. It's not very likely to happen if your DTM is something like 20*20 pixels size, and the mainscreen is split in 10*15. But it can happen.
It shouldn't be very hard to add a loop that will move the boxes by 1 pixel (and repeat of course), to find the DTM even if it was on a line of the original box-positions.

-Knives