Jump to content
tweakmeup

finddtmrotated function

Recommended Posts

Seems I posted this in the wrong section so here it goes.

 

The function is not taking into account the search coordinates I give it. My search window was 352, 33, 353, 34 ajd somehoe it found a dtm. Those coordinates are nowhere near where I took the dtm at, so thsts impossible.

Link to comment
Share on other sites

Well the DTM system, is bugged to all hell. So I've decided to write myself a new system using RotatePoint as the god function. If that function doesn't work like I want it too, then I won't be able to do this :(.

 

Its going to use the FindColor functions... so it should work really well. I have to ditch the current system, cuz I have no idea how to convert the DTM's string into a TDTM.

 

Will make a thread later once I'm done if all goes well.

Link to comment
Share on other sites

Dang mate, what kind of problems you had LJ? Glad to hear you have some plans for workaround, though.

 

With that upcoming DTM System I am sure DTMs will be much more reliable. :)

FindDTMs() function will be helping A LOT!

 

I must say, I enjoy using this "Show Matching DTM's" (based on FindDTMs()) feature in Simba's DTM Editor (awesome piece of work by nielsie95), it just makes it so damn easy to make reliable DTMs with it! Because you can instantly see if there's any other DTMs matched around.. Not just look for matching pixels (colors).

But it could be, Simba's DTM System is a lot more reliable anyways (well, only for now, because I know this will change to even/opposite, when Freddy adds the upcoming new system in)

Too bad Simba's DTMs aint compatible with SCAR Divi. :(

 

-Jani

Link to comment
Share on other sites

Ahaha, well I'm glad you tried using the one from Simba and then tried the same string with SCAR. I was tempted to do that, now I know not to.

 

The system, It hasn't been changed in eons, I mean EONS, and I think it fails with the client system. Even if the client system worked fine with it, the DTM's we have now fail anyway. Like the only ones that work are Bixby's Inventory DTM's afaik. I looked at all the tutorials I have:

1 2 3 4 5

 

Tried many times, and couldn't get anything to work like I wanted in RS2 mini maps and in general. Here is my little scar file so far:

 

 

[scar]

program New;

{$I OSI/OSI.scar}

 

type

 

TJashDTMPoint = record

Point: TPoint;

Color, Tolerance: Integer;

end;

TJashDTMPointArray = array of TJashDTMPoint;

 

TJashDTM = record

MainPoint: TJashDTMPoint;

SubPoints: TJashDTMPointArray;

end;

 

function JashDTMTPA(JDTM: TJashDTM): TPointArray;

var

i, h: Integer;

begin

h := high(JDTM.SubPoints);

SetLength(Result, h + 2);

Result[0] := JDTM.MainPoint.Point;

for i := 1 to h do

Result := JDTM.SubPoints.Point;

end;

 

function FindJashDTMRotated(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer; StartAng, EndAng, AngStep: Extended; var ang: Extended; ExactPDist: Boolean): Boolean;

var

i, h: Integer;

JTPA, MainTPA: TPointArray;

begin

Result := False;

JTPA := JashDTMTPA(JDTM);

if not BoxContains(TPABounds(JTPA), Box(XS, YS, XE, YE)) then Exit;

//if not JashDTMExists(JDTM) then Exit;

if not FindColorTolEx(MainTPA, JDTM.MainPoint.Color, XS, YS, XE, YE, JDTM.MainPoint.Tolerance) then Exit;

 

h := high(JTPA);

 

for i := 1 to h do

begin

 

end;

//

 

 

 

//

end;

 

 

 

begin

 

end.

[/scar]

 

How does this work?

1. Find main point color

2. Find "a" sub points color

3. check distance from main point and compare to JashDTM, and loop through arrays.

 

Each findcolor uses its own tolerance like we can do now with DTMs.

This isn't complete yet but I'm workin on it.

Edited by LordJashin
Link to comment
Share on other sites

Well, I'm pleased with the FindDTM function. However, the timing with it...meh. If it doesn't find the DTM it will sit there for a couple seconds. Will try to fix that.

 

Can't get this damn rotation stuff to work though. It fails if i try it. Here's source update:

 

[scar]

program New;

{$I OSI/OSI.scar}

 

type

 

TJashDTMPoint = record

Point: TPoint;

Color, Tolerance: Integer;

end;

 

TJashDTMPointArray = array of TJashDTMPoint;

 

TJashDTM = record

MainPoint: TJashDTMPoint;

SubPoints: TJashDTMPointArray;

end;

 

function JashDTMTPA(JDTM: TJashDTM): TPointArray;

var

i, h: Integer;

begin

h := high(JDTM.SubPoints);

SetLength(Result, h + 2);

Result[0] := JDTM.MainPoint.Point;

for i := 1 to (h + 1) do

Result := JDTM.SubPoints.Point;

end;

 

function JashDTMFind(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer; ExactPDist: Boolean): Boolean;

var

i, h, j, k: Integer;

MainTPA, SubTPA, FoundTPA: TPointArray;

begin

//if not JashDTMExists(JDTM) then Exit;

if not FindColorTolEx(MainTPA, JDTM.MainPoint.Color, XS, YS, XE, YE, JDTM.MainPoint.Tolerance) then Exit;

h := high(JDTM.SubPoints);

for i := 0 to high(MainTPA) do

for j := 0 to h do

begin

if FindColorTolEx(SubTPA, JDTM.SubPoints[j].Color, XS, YS, XE, YE, JDTM.SubPoints[j].Tolerance) then

begin

for k := 0 to high(SubTPA) do

begin

if (SubTPA[k].X = (MainTPA.X + (JDTM.SubPoints[j].Point.X - JDTM.MainPoint.Point.X))) and (SubTPA[k].Y = (MainTPA.Y + (JDTM.SubPoints[j].Point.Y - JDTM.MainPoint.Point.Y))) then

begin

SetLength(FoundTPA, Length(FoundTPA) + 1);

FoundTPA[Length(FoundTPA) - 1] := SubTPA[k];

end;

end;

SetLength(SubTPA, 0);

end;

if (Length(FoundTPA) = (h + 1)) then

begin

Result := True;

X := MainTPA.X;

Y := MainTPA.Y;

SetLength(FoundTPA, 0);

SetLength(MainTPA, 0);

Exit;

end;

if (Length(FoundTPA) > 0) then

SetLength(FoundTPA, 0);

end;

SetLength(MainTPA, 0);

end;

 

function JashDTMFindRotated(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer; StartAng, EndAng, AngStep: Extended; var ang: Extended; ExactPDist: Boolean): Boolean;

var

A: Extended;

i, fX, fY: Integer;

B: Boolean;

begin

for i := 0 to high(JDTM.SubPoints) do

JDTM.SubPoints.Point := RotatePoint(JDTM.SubPoints.Point, JDTM.MainPoint.Point, StartAng);

A := StartAng;

Repeat

if (A <> StartAng) then

A := A + AngStep;

B := JashDTMFind(fX, fY, JDTM, XS, YS, XE, YE, ExactPDist);

for i := 0 to high(JDTM.SubPoints) do

JDTM.SubPoints.Point := RotatePoint(JDTM.SubPoints.Point, JDTM.MainPoint.Point, AngStep);

until (B or (A >= EndAng));

if B then

begin

Result := True;

ang := A;

X := fX;

Y := fY

end;

end;

 

var

JashDTM: TJashDTM;

X, Y, w, h: Integer;

ang: Extended;

 

procedure SetupJashDTM;

var

i: Integer;

begin

JashDTM.MainPoint.Point := Point(1272, 471);

JashDTM.MainPoint.Color := 3051897;

SetLength(JashDTM.SubPoints, 3);

JashDTM.SubPoints[0].Point := Point(1268, 518);

JashDTM.SubPoints[0].Color := 608045;

JashDTM.SubPoints[1].Point := Point(1236, 517);

JashDTM.SubPoints[1].Color := 3638151;

JashDTM.SubPoints[2].Point := Point(1213, 503);

JashDTM.SubPoints[2].Color := 403770;

{JashDTM.SubPoints[3].Point := Point(79, 1027);

JashDTM.SubPoints[3].Color := 1974049;

JashDTM.SubPoints[4].Point := Point(85, 1019);

JashDTM.SubPoints[4].Color := 13488590;}

//for i := 0 to high(JashDTM.SubPoints) do

//JashDTM.SubPoints.Point := RotatePoint(JashDTM.SubPoints.Point, JashDTM.MainPoint.Point, Radians(10));

end;

 

procedure MainLoop;

begin

ClearDebug;

GetClient.Activate;

GetBoxSize(GetClient.ImageArea, w, h);

SetupJashDTM;

if JashDTMFind(X, Y, JashDTM, 0, 0, w - 1, h - 1, True) then

begin

WriteLn('JashDTMFind: Found at (' + IntToStr(X) + ', ' + IntToStr(Y) + ')');

MoveMouse(X, Y);

end;

{ if JashDTMFindRotated(X, Y, JashDTM, 0, 0, w - 1, h - 1, Radians(0), Radians(360), Radians(1), ang, True) then

begin

WriteLn('JashDTMFindRotated: Found at (' + IntToStr(X) + ', ' + IntToStr(Y) + ')');

WriteLn('JashDTMFindRotated: Angle found at: ' + FloatToStr(ang));

MoveMouse(X, Y);

end; }

SetLength(JashDTM.SubPoints, 0);

end;

 

begin

MainLoop;

WriteLn('Script Successfully ran!');

end.

 

[/scar]

 

Help me if you would like to xD

 

I'm more than likely doing something wrong with the rotation stuff lols

 

Tbh, this thing is really crappy with SCAR atm. Causing me a headache, I think I'll remove all those SetLengths to 0

Edited by LordJashin
Link to comment
Share on other sites

Well, I've pretty much finished my FindDTM function. However you can't make a DTM using the DTM Editor :(

 

Works very good, I'll try to get the rotation to work 2morow. Here's the source:

 

[scar]

 

type

 

TJashDTMPoint = record

Point: TPoint;

Color, Tolerance: Integer;

end;

 

TJashDTMPointArray = array of TJashDTMPoint;

 

TJashDTM = record

MainPoint: TJashDTMPoint;

SubPoints: TJashDTMPointArray;

end;

 

function JashDTMTPA(JDTM: TJashDTM): TPointArray;

var

i, h: Integer;

begin

h := high(JDTM.SubPoints);

SetLength(Result, h + 2);

Result[0] := JDTM.MainPoint.Point;

for i := 1 to (h + 1) do

Result := JDTM.SubPoints.Point;

end;

 

function JashDTMFind(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer; ExactPDist: Boolean): Boolean;

var

i, h, j, xs1, ys1, xf, yf: Integer;

MainTPA, FoundTPA: TPointArray;

begin

//if not JashDTMExists(JDTM) then Exit;

if not FindColorTolEx(MainTPA, JDTM.MainPoint.Color, XS, YS, XE, YE, JDTM.MainPoint.Tolerance) then Exit;

h := high(JDTM.SubPoints);

for i := 0 to high(MainTPA) do

for j := 0 to h do

begin

xs1 := (MainTPA.X + (JDTM.SubPoints[j].Point.X - JDTM.MainPoint.Point.X));

ys1 := (MainTPA.Y + (JDTM.SubPoints[j].Point.Y - JDTM.MainPoint.Point.Y));

if FindColorTol(xf, yf, JDTM.SubPoints[j].Color, xs1, ys1, xs1 + 1, ys1 + 1, JDTM.SubPoints[j].Tolerance) then

begin

SetLength(FoundTPA, Length(FoundTPA) + 1);

FoundTPA[Length(FoundTPA) - 1] := Point(xf, yf);

end;

if (Length(FoundTPA) = (h + 1)) then

begin

Result := True;

X := MainTPA.X;

Y := MainTPA.Y;

SetLength(FoundTPA, 0);

SetLength(MainTPA, 0);

Exit;

end;

if (j = h) then

SetLength(FoundTPA, 0);

end;

SetLength(MainTPA, 0);

end;

 

function JashDTMFindRotated(var X, Y: Integer; JDTM: TJashDTM; XS, YS, XE, YE: Integer; StartAng, EndAng, AngStep: Extended; var ang: Extended; ExactPDist: Boolean): Boolean;

var

currAng: Extended;

i, fX, fY: Integer;

B: Boolean;

begin

for i := 0 to high(JDTM.SubPoints) do

JDTM.SubPoints.Point := RotatePoint(JDTM.SubPoints.Point, JDTM.MainPoint.Point, StartAng);

currAng := StartAng;

Repeat

B := JashDTMFind(fX, fY, JDTM, XS, YS, XE, YE, ExactPDist);

for i := 0 to high(JDTM.SubPoints) do

JDTM.SubPoints.Point := RotatePoint(JDTM.SubPoints.Point, JDTM.MainPoint.Point, AngStep);

currAng := currAng + AngStep;

until (B or (currAng >= EndAng));

if B then

begin

Result := True;

ang := currAng - AngStep;

X := fX;

Y := fY

end;

end;

 

[/scar]

 

The FindDTM runs very fast, and fast even if it isn't found.

Link to comment
Share on other sites

Alright, I got minimap rotation working perfect now. But the rotation still takes a long time, going to try to speed it up. Takes 5-10 seconds to find a DTM rotated with JashDtm's. But hell it works like a boss:

 

SNr6m.png

 

Will release this, as soon as I speed it up.

 

EDIT: This is true, until Freddy can help me, I can't take what the editor prints out.

 

But the whole idea behind DTM's can be done script side too. Its just a lot more work compared to just printing it out in string form.

This thing I got going here can successfully be used for MAP Walking. While as the current dtm system, failed so hard.

Edited by LordJashin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...