SRL Archive - Test corner

Function CreateItemDTM(InvSlot, NoOfPoints, Tolerance: Integer): Integer;


Starblaster100

2007-05-19 09:39:02

Hey all,

New Function from me, could be pretty useful :)

[php]
{ ——————————————————————— ]
[ >> Part of Find DTM ]
[ >> Function CreateItemDTM(InvSlot, NoOfPoints, Tolerance: Integer): ]
[ Integer; ]
[ >> Creates a Dynamic DTM of an Item in the Defined InvSlot, with ]
[ "NoOfPoints" SubPoints and "Tolerance" Tolerance ]
[ >> By Starblaster100 ]
[ ——————————————————————— }
[/php]

and here is the function itself:

[php]
program New;
{.include SRL/SRL.scar}

Var
Test: Integer;

{ ——————————————————————— ]
[ >> Part of Find DTM ]
[ >> Function CreateItemDTM(InvSlot, NoOfPoints, Tolerance: Integer): ]
[ Integer; ]
[ >> Creates a Dynamic DTM of an Item in the Defined InvSlot, with ]
[ "NoOfPoints" SubPoints and "Tolerance" Tolerance ]
[ >> By Starblaster100 ]
[ ——————————————————————— }

Function CreateItemDTM(InvSlot, NoOfPoints, Tolerance: Integer): Integer;
Var
DTM: TDTM;
Start: TPoint;
i, X1, Y1, CurrentAngle, Radius, SubPointsFound: Integer;
Begin
If not(Loggedin) then Exit;
GameTab(4);
If(ExistsItem(InvSlot)) then
Begin
Start := ItemCoords(InvSlot);

SetArrayLength(DTM.SubPoints, NoOfPoints);
DTM.MainPoint.x := Start.x;
DTM.MainPoint.y := Start.y;
DTM.MainPoint.color := GetColor(Start.x, Start.y);
DTM.MainPoint.tolerance := Tolerance;
DTM.MainPoint.areasize := 1;
DTM.MainPoint.areashape := shpRectangle;

For i := 0 to NoOfPoints-1 do
Begin
CurrentAngle := (360/NoOfPoints) * i;
For Radius := 1 to 20 do
Begin
X1 := Round ( Radius * Sin (CurrentAngle * Pi / 180)) + Start.x;
Y1 := Round (- Radius * Cos (CurrentAngle * Pi / 180)) + Start.y;
If (GetColor(X1, Y1) = 65536) then
Begin
DTM.SubPoints.x := X1;
DTM.SubPoints.y := Y1;
DTM.SubPoints.color := GetColor(X1, Y1);
DTM.SubPoints.tolerance := 0;
DTM.SubPoints.areasize := 1;
DTM.SubPoints.areashape := shpRectangle;
SubPointsFound := SubPointsFound + 1;
Writeln('Subpoint '+IntToStr(i)+' Found');
Break;
end;
end;
end;
If (SubPointsFound >= NoOfPoints) then
Result := AddDTM(DTM);
end;
end;

begin
Test := CreateItemDTM(1, 3, 0);
try
If(FindDTM(Test, x, y, 555, 374, 742, 471))then
Begin
Writeln('Found');
MMouse(x, y, 0, 0);
end else
Writeln('NotFound');
except
Writeln('All Sub Points Not Found');
Writeln('DTM Could not be Created!');
end;
end.
[/php]

Put something like a cowhide in the first inventory spot, and then put another in the bottom row somewhere. It should create a DTM of the first cowhide, find the second and move the mouse there.

I know its not perfect, I'm still working on it, hence the post in the Test Corner.

Tell me what you think

Thanks

Star

Abyssal

2007-05-19 09:54:35

Holy moly, a lot of nice work there.

Very nice work Star!

Boreas

2007-05-19 09:59:21

Nice. Almost as nice as BlackLists :p

Starblaster100

2007-05-19 10:05:35

What and where is blacklists?

EDIT: Ok found a link in ur sig ill check it out

bullzeye95

2007-05-19 10:28:55

Nice work :D! Hmm I'll check out blacklists too.

Bobarkinator

2007-05-19 10:50:27

Very nice work Star. This could be useful in scripts.

n3ss3s

2007-05-19 11:24:42

z0mg! pwn0rz fuunct000n.
Wow…

Smartzkid

2007-05-19 11:55:39

I like it!

Maybe if you could make an option to put points only on the black outline of the item?

Starblaster100

2007-05-19 12:35:34

From: Smartzkid
I like it!

Maybe if you could make an option to put points only on the black outline of the item?


Thats what it will only do lol.

Depending on how many subpoints you choose to make, it create a circle and split it into equal parts then it will start from the center of the item, and work its way outwards until it finds the black outline

Smartzkid

2007-05-19 12:39:34

Oops!

I guess I should have read over the code a bit more thoroughly….

If (GetColor(X1, Y1) = 65536) then... 

Awesome idea! I'm gonna mess around with it some

Boreas

2007-05-19 12:48:50

Smartz check out BlackLists too :p

edit: o you did lol

rkroxpunk

2007-05-20 01:33:02

why don't u make it print the DTM string in the dubug box? :D

Starblaster100

2007-05-20 07:15:17

From: rkroxpunk
why don't u make it print the DTM string in the dubug box? :D


what would be the point of that?
The point is you want to create a DTM whilst the script is running automatically, and then use it later on in the script.

omgh4x0rz

2007-05-20 12:25:25

So is this like the dynamic DTM thing people wanted in divi?

Starblaster100

2007-05-21 08:03:22

That would be it, yes

Wizzup?

2007-05-21 12:19:43

Why do you use Pi to get the black colors, can't you do FindColorsTolerance() with zero tol, take some random points out the array, and create a dtm out of that?

Starblaster100

2007-05-21 15:11:08

This makes sure that the points are all equally spread out.


2 Points 3 Points 4 Points
X X X X
| \ / |
| \ / |
X X X----- X ----X
| | |
| | |
X X X


You get the point

Bobarkinator

2007-05-21 19:20:19

From: Starblaster100

You get the point


No pun intended…

Junior

2007-05-22 21:41:45

This looks sick. Went over the code, dont understand much but good job anway… How do you guys get so good with this? This meaning SCAR.

Nice work :)

Bobarkinator

2007-05-22 23:27:10

Practice?

Wizzup?

2007-05-23 02:51:45

From: Starblaster100
This makes sure that the points are all equally spread out.


2 Points 3 Points 4 Points
X X X X
| \ / |
| \ / |
X X X----- X ----X
| | |
| | |
X X X


You get the point


What about sorting the x?

Starblaster100

2007-05-23 05:57:47

Sorting the X…?

Wizz, everyone has their own ways of scripting, this is just my own personal way to do things. It works, and I am happy with it

Abyssal

2007-05-23 08:02:52

Could I use this in my fletcher, maybe?

Starblaster100

2007-05-23 08:32:59

yea sure

Ashur2Good

2007-05-23 08:41:50

This could be really handy for people that don't know how to make dynamic DTM's, Thanks star :)

This is going into SRL 4.0 right?

-Ashur

Abyssal

2007-05-24 22:55:45

From: Starblaster100
yea sure


Awesome, awesome, awesome!!!

Thanks loads!

WhiteShadow

2007-05-24 23:24:43

I had no clue SCAR had a TDTM variable. =D I'll look into that.

Good work Star.

gsquare567

2007-06-12 21:06:20

i understand the function except these two key lines:
[php]X1 := Round ( Radius * Sin (CurrentAngle * Pi / 180)) + Start.x;
Y1 := Round (- Radius * Cos (CurrentAngle * Pi / 180)) + Start.y;[/php]
not the best thing to not know, since i have an exam on this tomorrow ;)
i only understand ur converting the angle to rads in the sin/cos, but why * radius and how did u get sin/cos? mind making a tiny triangle diagram on how this math works?

EDIT: mind if i copy a little of this to make a function with color-selecting for the dtm and make it make a dtm on the minimap. i'm up for it ;) (ps, i still really want to learn about what u did with trig there)

Starblaster100

2007-06-13 06:58:21

It turns the radius point into a coordinate.

We know the middle of the circle in the radius (Thats "Start.x" in this case), we know the radius ("Radius") and we know the angle that we want the script to look at ("CurrentAngle"). Using these 3 variables, we are able to turn that point on a circle into a coordinate.

Same for Y

Sure, this is for learning purposes, go ahead and use it

gsquare567

2007-06-13 18:07:29

hmm… is this past gr 11 math, cuz im clued out :S

Starblaster100

2007-06-13 18:21:04

mmm, Grade 11 and 12 i would say