SRL Archive - SRL Archives

function CreateDTMFromClient(x1, y1, x2, y2, maxsubpoints: integer): integer;


pwnaz0r

2007-09-16 16:55:05

Here it is. I use it for making DTMs of items in my inventory that there could be alot of (Ex. There are so many types of fish and food, i don't want to make dtms for all of them, so i just made this. The script will make the DTM for me :D).


function CreateDTMFromClient(x1, y1, x2, y2, maxsubpoints: integer): integer;
var
DDTMDef: TDTMPointDef;
DDTMSub: array of TDTMPointDef;
DDTMMain: TDTM;
a, b, c, d, e, bitmap: integer;
first: boolean;
begin
if x2 <= x1 then Swap(x2, x1);
if y2 <= y1 then Swap(y2, y1);
CopyClientToBitmap(bitmap, x1, y1, x2, y2);
c:= x2 - x1;
d:= y2 - y1;
first:= true;
for a:= 0 to c do
begin
for b:= 0 to d do
begin
if FastGetPixel(bitmap, a, b) = 65536 then
begin
if First then
begin
DDTMDef.x:= x1 + a;
DDTMDef.y:= y1 + b;
DDTMDef.AreaSize:= 1;
DDTMDef.AreaShape:= 0;
DDTMDef.Color:= 65536;
DDTMDef.Tolerance:= 0;
First:= false;
wait(500);
end else
begin
SetArrayLength(DDTMSub, Length(DDTMSub) + 1);
e:= Length(DDTMSub) - 1;
DDTMSub[e].x:= x1 + a;
DDTMSub[e].y:= y1 + b;
DDTMSub[e].AreaSize:= 1;
DDTMSub[e].AreaShape:= 0;
DDTMSub[e].Color:= 65536;
DDTMSub[e].Tolerance:= 0;
wait(500);
if e >= maxsubpoints then
begin
DDTMMain.MainPoint:= DDTMDef;
DDTMMain.SubPoints:= DDTMSub;
result:= AddDTM(DDTMMain);
exit;
end;
end;
end;
end;
end;
DDTMMain.MainPoint:= DDTMDef;
DDTMMain.SubPoints:= DDTMSub;
result:= AddDTM(DDTMMain);
end;

R0b0t1

2007-09-16 17:15:17

1). It probably took more time to make that than the DTM's,

2). large bitmaps are waste full, you can cut it down somehow, and

3). setting the main point as the edge isn't condoned by me. It would be better to use the center.

pwnaz0r

2007-09-16 17:23:16

From: r0b0t1
1). It probably took more time to make that than the DTM's,

2). large bitmaps are waste full, you can cut it down somehow, and

3). setting the main point as the edge isn't condoned by me. It would be better to use the center.


1. Probably was, that isnt the point..

2. the amount is trivial. It doesnt save it and it releases it at the end.

3. considering 9/10 the static color is on the outside, there is nothing i can do. I made it the first so users can say


If FindDTM(dtm,x,y,bla)then
Mouse(x + 15, y + 15, 0, 0, false);

R0b0t1

2007-09-16 17:33:00

Thats not what I mean! You can just set the color as the middle of the object, and make its tolerance 255. Another problem is the the main point of the DTM is the place where the X and Y coordinates are returned from. Odd to see someone clicking on the edge every time, eh?

pwnaz0r

2007-09-16 17:52:40

its not…

If FindDTM(dtm,x,y,bla)then
Mouse(x + 15, y + 15, 4, 4, false);

Buckleyindahouse

2007-09-16 20:11:22

What Pwnaz0r is saying it finds the edge then it clicks 15 extra pixels to make it in the middle.

pwnaz0r

2007-09-17 23:12:51

Thank you buckley lol

mat_de_b

2007-09-18 10:30:07

Cant taht go wrong so if say the first point is on the bottom edge? surely there must be a way to locate a center point from teh surrounding ones?


EDIT: I have an idea… make all the sub points first, then with a bit of maths get the smallest X and Y and the biggest X and Y and then get the mid point, which then becomes the Mpoint, i may be able to write it uot for you if you want

EDIT:

procedure MPoint;
var Mx1,My1,Mx2,My2:integer;
begin
Mx1 := x2;
Mx2 := x1;
My1 := y2;
My2 := y1;
for e:= 0 to MaxSubPoints do
begin
if(DDTMSub[e].x < Mx1) then
Mx1 := DDTMSub[e].x;

if(DDTMSub[e].x > Mx2) then
Mx2 := DDTMSub[e].x;

if(DDTMSub[e].y < My1) then
My1 := DDTMSub[e].y;

if(DDTMSub[e].y > My2) then
My2 := DDTMSub[e].y;
end;
DDTMDef.x:= Mx1 + (Mx2-Mx1);
DDTMDef.y:= My1 + (My2-My1);
DDTMDef.AreaSize:= 1;
DDTMDef.AreaShape:= 0;
DDTMDef.Color:= 65536;
DDTMDef.Tolerance:= 255;
end;

Hows That? Placed in the script that is

function CreateDTMFromClient(x1, y1, x2, y2, maxsubpoints: integer): integer;
var
DDTMDef: TDTMPointDef;
DDTMSub: array of TDTMPointDef;
DDTMMain: TDTM;
Mx1,My1,Mx2,My2,a, b, c, d, e, bitmap: integer;
begin
if x2 <= x1 then Swap(x2, x1);
if y2 <= y1 then Swap(y2, y1);
CopyClientToBitmap(bitmap, x1, y1, x2, y2);
c:= x2 - x1;
d:= y2 - y1;
for a:= 0 to c do
begin
for b:= 0 to d do
begin
if FastGetPixel(bitmap, a, b) = 65536 then
begin
SetArrayLength(DDTMSub, Length(DDTMSub) + 1);
e:= Length(DDTMSub) - 1;
DDTMSub[e].x:= x1 + a;
DDTMSub[e].y:= y1 + b;
DDTMSub[e].AreaSize:= 1;
DDTMSub[e].AreaShape:= 0;
DDTMSub[e].Color:= 65536;
DDTMSub[e].Tolerance:= 0;
if e >= maxsubpoints then
begin
Mx1 := x2;
Mx2 := x1;
My1 := y2;
My2 := y1;
for e:= 0 to MaxSubPoints do
begin
if(DDTMSub[e].x < Mx1) then
Mx1 := DDTMSub[e].x;

if(DDTMSub[e].x > Mx2) then
Mx2 := DDTMSub[e].x;

if(DDTMSub[e].y < My1) then
My1 := DDTMSub[e].y;

if(DDTMSub[e].y > My2) then
My2 := DDTMSub[e].y;
end;
DDTMDef.x:= Mx1 + (Mx2-Mx1);
DDTMDef.y:= My1 + (My2-My1);
DDTMDef.AreaSize:= 1;
DDTMDef.AreaShape:= 0;
DDTMDef.Color:= 65536;
DDTMDef.Tolerance:= 255;
exit;
end;
end;
end;
DDTMMain.MainPoint:= DDTMDef;
DDTMMain.SubPoints:= DDTMSub;
result:= AddDTM(DDTMMain);
end;

pwnaz0r

2007-09-19 21:58:53

I would rather not use the midpoint because

1. I don't like using non static colors in dtm's. don't work well (if in center if the box).

2. Just b/c it is in the middle of the array, doesn't mean it is in the middle of the object. Its going to be close to the same spot(look at the way it looks for colors. Left to right and there will prolly be more than 1 color in each line. So it would be the same anyways except you will just have to make different adjustments.