Blumblebee
05-14-2009, 01:02 PM
Alright, so I've noticed an incredible amount of DDTM's created with static colors or tolerances, and frankly they are a waste of space and memory. So this tutorial will teach you how to correctly use a DDTM.
Table of Contents
I. - Introduction to DDTM's
II. - Autocoloring DDTM's
III. - Changing the Tolerance
IV. - Side notes
V. - End Credits
I. Introduction to DDTM's
So, if your reading this your interested in using a ddtm (correctly). The easiest way to create a ddtm is by using nielsie95's DDTM editor. You can find it in includes>SRL>Scripting Tools, or simply download it here (http://www.villavu.com/forum/showthread.php?t=25312). Now lets start with a DDTM of the varrock road. We will use create our bitmap using PrintScreen, found on the upper right of your keyboard. After we capture the image we should input it into the DDTM editor by going Image>PasteImage.
Now lets actually make the DDTM by creating one mainpoint with the areasize of 1, tolerance of 0, and 3-4 subpoints. All of the points must be on the road, else the DDTM will not work! The end result will look something like this.
http://i40.tinypic.com/idhtvb.jpg
alright so lets go File > DDTM to Text to get our output and copy and paste that into scar. The code will look similiar to this.
function SetDDTM: Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
begin
dtmMainPoint.x := 918;
dtmMainPoint.y := 375;
dtmMainPoint.AreaSize := 1;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 8028292;
dtmMainPoint.Tolerance := 0;
dtmSubPoints[0].x := 918;
dtmSubPoints[0].y := 375;
dtmSubPoints[0].AreaSize := 1;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := 8028292;
dtmSubPoints[0].Tolerance := 0;
dtmSubPoints[1].x := 904;
dtmSubPoints[1].y := 372;
dtmSubPoints[1].AreaSize := 1;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := 8028292;
dtmSubPoints[1].Tolerance := 0;
dtmSubPoints[2].x := 933;
dtmSubPoints[2].y := 373;
dtmSubPoints[2].AreaSize := 1;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := 8028292;
dtmSubPoints[2].Tolerance := 0;
dtmSubPoints[3].x := 928;
dtmSubPoints[3].y := 377;
dtmSubPoints[3].AreaSize := 1;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := 8028292;
dtmSubPoints[3].Tolerance := 0;
dtmSubPoints[4].x := 913;
dtmSubPoints[4].y := 378;
dtmSubPoints[4].AreaSize := 1;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := 8028292;
dtmSubPoints[4].Tolerance := 0;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Alright the first thing I want you to note, the first subpoint and the mainpoint are the exact same. This is not a problem really, just a small bug with nielsie95's DDTM editor, you can leave it, or what i usually do is remove it (you will then have to fix the array aswell).
Congratulations you have just made your first DDTM, although right now its nothing more than a DTM that takes up 10x the amount of lines.
II. Dynamic: Autocoloring Your DDTM
Alright, so lets get to the beef of the tutorial. This is what separates the DDTM's from the DTM's. you will notice in the code, that the mainpoint and all the subpoints have a color that looks like:
dtmSubPoints[4].Color := 8028292;
This is where we must add our autocolor. For this we will need to add a variable at the top of the function. Name it ACvar, and make it an integer.
var ACvar: Integer
Now we must set that to an autocolor, so before any of the DDTM is declare we must make ACvar := FindVarrockRoadColor; // Remember that this autocolor is for Varrock, substitute the autocolor you need here
But we still arent done. We must now change all the dtmSubPoints[4].Color := 8028292; to dtmSubPoints[4].Color := ACvar;
Making the overall Script look something like:
function SetDDTM: Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
ACvar: integer;
begin
ACvar := FindVarrockRoadColor;
dtmMainPoint.x := 918;
dtmMainPoint.y := 375;
dtmMainPoint.AreaSize := 1;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := ACvar;
dtmMainPoint.Tolerance := 0;
dtmSubPoints[0].x := 918;
dtmSubPoints[0].y := 375;
dtmSubPoints[0].AreaSize := 1;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := ACvar;
dtmSubPoints[0].Tolerance := 0;
dtmSubPoints[1].x := 904;
dtmSubPoints[1].y := 372;
dtmSubPoints[1].AreaSize := 1;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := ACvar;
dtmSubPoints[1].Tolerance := 0;
dtmSubPoints[2].x := 933;
dtmSubPoints[2].y := 373;
dtmSubPoints[2].AreaSize := 1;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := ACvar;
dtmSubPoints[2].Tolerance := 0;
dtmSubPoints[3].x := 928;
dtmSubPoints[3].y := 377;
dtmSubPoints[3].AreaSize := 1;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := ACvar;
dtmSubPoints[3].Tolerance := 0;
dtmSubPoints[4].x := 913;
dtmSubPoints[4].y := 378;
dtmSubPoints[4].AreaSize := 1;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := ACvar;
dtmSubPoints[4].Tolerance := 0;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Congratulations, you have now just autocolored your first DDTM, which now makes it a proper DDTM!
III. Dynamic: Tolerance Changing
Alright, another method for creating a proper DDTM is dynamic tolerance. For this section, we are going to include DDTM finding, aswell as declaration. So lets go back to the original model of our DDTM. we are going to add a Global variable first (This means a variable outside the Function/Procedure usually at the top of the script). So lets call our Global Variable ddtmTolerance, and we will make it an integer. So under
{.include SRL/SRL.scar}
Add:
var ddtmTolerance: integer;
Now lets head back to our DDTM and this time we will change all the Tolerances for the mainpoint and subpoints to this:
dtmMainPoint.Tolerance := ddtmTolerance;
In the end our script will now look like below:
function SetDDTM: Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
begin
ACvar := FindVarrockRoadColor;
dtmMainPoint.x := 918;
dtmMainPoint.y := 375;
dtmMainPoint.AreaSize := 1;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 8028292;
dtmMainPoint.Tolerance := ddtmTolerance;
dtmSubPoints[0].x := 918;
dtmSubPoints[0].y := 375;
dtmSubPoints[0].AreaSize := 1;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := 8028292;
dtmSubPoints[0].Tolerance := ddtmTolerance;
dtmSubPoints[1].x := 904;
dtmSubPoints[1].y := 372;
dtmSubPoints[1].AreaSize := 1;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := 8028292;
dtmSubPoints[1].Tolerance := ddtmTolerance;
dtmSubPoints[2].x := 933;
dtmSubPoints[2].y := 373;
dtmSubPoints[2].AreaSize := 1;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := 8028292;
dtmSubPoints[2].Tolerance := ddtmTolerance;
dtmSubPoints[3].x := 928;
dtmSubPoints[3].y := 377;
dtmSubPoints[3].AreaSize := 1;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := 8028292;
dtmSubPoints[3].Tolerance := ddtmTolerance;
dtmSubPoints[4].x := 913;
dtmSubPoints[4].y := 378;
dtmSubPoints[4].AreaSize := 1;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := 8028292;
dtmSubPoints[4].Tolerance := ddtmTolerance;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Alright so now have that declared. So now we have a variable to change the tolerance, but it doesnt do anything yet. So lets make a DDTM finding procedure, we'll make it as so:
Function FindDDTMonMM: Boolean;
var x,y, theddtm: Integer;
begin
ddtmTolerance := 5;
theddtm := SetDDTM;
repeat
if not DtmRotated(theddtm, X, Y, MMX1, MMY1, MMX2, MMY2) then
begin
IncEx(ddtmTolerance, 5)
FreeDTM(theddtm);
theddtm := SetDDTM;
end else
begin
Result := True;
Break;
end;
until (ddtmTolerance >= 50);
ddtmTolerance := 5;
FreeDtm(theddtm);
end;
Looks confusing, but really its not. Lets break it down step by step.
ddtmTolerance := 5; Pretty much self explainitory, we set the initial ddtmTolerance to 5.
theddtm := SetDDTM;we declare the ddtm so that it doesnt get constantly declared as the function repeats, this saves time and memory.
if not DtmRotated(theddtm, X, Y, MMX1, MMY1, MMX2, MMY2) then this is just a basic way of finding a ddtm. Used mostly for finding ddtms on the Minimap.
IncEx(ddtmTolerance, 5) else
begin
Result := True;
Break;
end; ok so IncEx(the variable you want to increase, how much you want to increase the variable by). the "else" is used because we use an if then loop. so the script tries to find the ddtm if it doesn't (if not) then it increases the tolerance and continues through the loop. If it does find the DDTM then it makes the result true and then breaks out of the loop. We dont exit because we want to free the DDTM to save memory.
until (ddtmTolerance >= 50); Pretty much this is just a failsafe, if it continually cannot find the ddtm and the tolerance reaches a point of being 50 or higher, it breaks from the loop.
ddtmTolerance := 5;
FreeDtm(theddtm); the first line just resets the tolerance, just incase you use it in another procedure, you wouldnt want it to be 45 tolerance, so we reset it to 5 to be safe. The second line simply free's the DDTM.
Alright awesome, so you've sucessfully made your first ddtm with a dynamic tolerance! Congratulations.[/quote]
IV. Extra Notes
Here I will add all the extra stuff about DDTM's I can think of really that is somewhat helpful.
Ok, so this will be very brief as I'm tired. Declaring Multiple DDTM's is a very common mistake with many people. Some people think it takes numerous amounts of lines and procedures, when in reality its takes a very small amount. Here is an example of how I load numerous DDTM's.
var Rdcl: Integer;
Function SetWalkDtm(Number:Integer): Integer;
var MainPoint: TDTMPointDef; dtmSubPoints: Array [0..3] of TDTMPointDef; TempTDTM: TDTM; i: Integer;
begin
RdCl := FindVarrockRoadColor;
case Number of
0:
begin
with MainPoint do
begin
x := 934;
y := 378;
AreaSize := 1;
AreaShape := 0;
Color := RdCl;
Tolerance := 5;
end;
dtmSubPoints[0].x := 934;
dtmSubPoints[0].y := 378;
dtmSubPoints[1].x := 922;
dtmSubPoints[1].y := 375;
dtmSubPoints[2].x := 942;
dtmSubPoints[2].y := 375;
dtmSubPoints[3].x := 939;
dtmSubPoints[3].y := 381;
end;
1:
begin
with MainPoint do
begin
x := 915;
y := 375;
AreaSize := 1;
AreaShape := 0;
Color := Rdcl;
Tolerance := 5;
end;
dtmSubPoints[0].x := 907;
dtmSubPoints[0].y := 371;
dtmSubPoints[1].x := 921;
dtmSubPoints[1].y := 372;
dtmSubPoints[2].x := 908;
dtmSubPoints[2].y := 377;
dtmSubPoints[3].x := 920;
dtmSubPoints[3].y := 377;
end;
2:
begin
with MainPoint do
begin
x := 880;
y := 408;
AreaSize := 1;
AreaShape := 0;
Color := Rdcl;
Tolerance := 5;
end;
dtmSubPoints[0].x := 880;
dtmSubPoints[0].y := 408;
dtmSubPoints[1].x := 880;
dtmSubPoints[1].y := 400;
dtmSubPoints[2].x := 883;
dtmSubPoints[2].y := 416;
dtmSubPoints[3].x := 883;
dtmSubPoints[3].y := 412;
end;
end;
for i := 0 to High(dtmSubPoints) do
begin
dtmSubPoints[i].AreaSize := 1;
dtmSubPoints[i].AreaShape := 0;
dtmSubPoints[i].Color := RdCl;
dtmSubPoints[i].Tolerance := 5;
end;
TempTDTM.MainPoint := MainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
ok so your probably like Wtf? So I'll walk you through it as best I can.
RdCl := FindVarrockRoadColor; this is exactly what Part II is about in the tutorial, its an autocolor for all the ddtm points. now, for the function, all I do is declare the DDTM mainpoints and subpoints through an index which is called in the function (so say I want the first ddtm, its simply SetWalkddtm(0); ) After all of these are declared, I call the static parts of each of the ddtm's subpoints such as areasize, areashape ect. I use High() so that I can have any number of subpoints I so choose. This is a little confusing I know, I'm just tired and dont want to type anymore, so later I may elaborate.
Alright Ready for part 2? So ever noticed that your ddtm could be found in different locations on the mm? And the script messes up becauseit finds the ddtm somewhere else? Well here comes your answer.
Ok so, the first thing you will notice when you call upon a ddtm would look something like this...
DtmRotated(theddtm, X, Y, MMX1, MMY1, MMX2, MMY2)
Now the first thing you should note is that the DDTM searches the entire Minimap. Now how do we combat that? Well the easiest thing you can do is change the Minimap coords to fit your needs. so something like DtmRotated(theddtm, X, Y, MMcx, MMcy, MMX2, MMY2) that would look in the bottom right (third quadrant of the Minimap). Again you can substitue the coords there for flat out numerals for a more exact search. This is a point that many people forget to do when finding DDTM's. Here's the function I like to use when I call for DDTM's in walking,
Function DtmLocate(q, w, e, r, Dtm: Integer): Boolean;
var x, y, thedtm: Integer;
begin
thedtm := dtm;
Result := DTMRotated(thedtm, x, y, q, w, e, r);
end;
V. End Credits
Not many real credits, but some good reads if your still interested in DDTM's.
adding the (D) in (D)DTM's (http://www.villavu.com/forum/showthread.php?t=36278&highlight=ddtm)
Complete DDTM Walking Tutorial (http://www.villavu.com/forum/showthread.php?t=32608) (My personal Fav)
DDTM's and their uses (http://www.villavu.com/forum/showthread.php?t=26968)
So thanks for reading, and I hope you learnt something. :)
Table of Contents
I. - Introduction to DDTM's
II. - Autocoloring DDTM's
III. - Changing the Tolerance
IV. - Side notes
V. - End Credits
I. Introduction to DDTM's
So, if your reading this your interested in using a ddtm (correctly). The easiest way to create a ddtm is by using nielsie95's DDTM editor. You can find it in includes>SRL>Scripting Tools, or simply download it here (http://www.villavu.com/forum/showthread.php?t=25312). Now lets start with a DDTM of the varrock road. We will use create our bitmap using PrintScreen, found on the upper right of your keyboard. After we capture the image we should input it into the DDTM editor by going Image>PasteImage.
Now lets actually make the DDTM by creating one mainpoint with the areasize of 1, tolerance of 0, and 3-4 subpoints. All of the points must be on the road, else the DDTM will not work! The end result will look something like this.
http://i40.tinypic.com/idhtvb.jpg
alright so lets go File > DDTM to Text to get our output and copy and paste that into scar. The code will look similiar to this.
function SetDDTM: Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
begin
dtmMainPoint.x := 918;
dtmMainPoint.y := 375;
dtmMainPoint.AreaSize := 1;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 8028292;
dtmMainPoint.Tolerance := 0;
dtmSubPoints[0].x := 918;
dtmSubPoints[0].y := 375;
dtmSubPoints[0].AreaSize := 1;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := 8028292;
dtmSubPoints[0].Tolerance := 0;
dtmSubPoints[1].x := 904;
dtmSubPoints[1].y := 372;
dtmSubPoints[1].AreaSize := 1;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := 8028292;
dtmSubPoints[1].Tolerance := 0;
dtmSubPoints[2].x := 933;
dtmSubPoints[2].y := 373;
dtmSubPoints[2].AreaSize := 1;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := 8028292;
dtmSubPoints[2].Tolerance := 0;
dtmSubPoints[3].x := 928;
dtmSubPoints[3].y := 377;
dtmSubPoints[3].AreaSize := 1;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := 8028292;
dtmSubPoints[3].Tolerance := 0;
dtmSubPoints[4].x := 913;
dtmSubPoints[4].y := 378;
dtmSubPoints[4].AreaSize := 1;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := 8028292;
dtmSubPoints[4].Tolerance := 0;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Alright the first thing I want you to note, the first subpoint and the mainpoint are the exact same. This is not a problem really, just a small bug with nielsie95's DDTM editor, you can leave it, or what i usually do is remove it (you will then have to fix the array aswell).
Congratulations you have just made your first DDTM, although right now its nothing more than a DTM that takes up 10x the amount of lines.
II. Dynamic: Autocoloring Your DDTM
Alright, so lets get to the beef of the tutorial. This is what separates the DDTM's from the DTM's. you will notice in the code, that the mainpoint and all the subpoints have a color that looks like:
dtmSubPoints[4].Color := 8028292;
This is where we must add our autocolor. For this we will need to add a variable at the top of the function. Name it ACvar, and make it an integer.
var ACvar: Integer
Now we must set that to an autocolor, so before any of the DDTM is declare we must make ACvar := FindVarrockRoadColor; // Remember that this autocolor is for Varrock, substitute the autocolor you need here
But we still arent done. We must now change all the dtmSubPoints[4].Color := 8028292; to dtmSubPoints[4].Color := ACvar;
Making the overall Script look something like:
function SetDDTM: Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
ACvar: integer;
begin
ACvar := FindVarrockRoadColor;
dtmMainPoint.x := 918;
dtmMainPoint.y := 375;
dtmMainPoint.AreaSize := 1;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := ACvar;
dtmMainPoint.Tolerance := 0;
dtmSubPoints[0].x := 918;
dtmSubPoints[0].y := 375;
dtmSubPoints[0].AreaSize := 1;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := ACvar;
dtmSubPoints[0].Tolerance := 0;
dtmSubPoints[1].x := 904;
dtmSubPoints[1].y := 372;
dtmSubPoints[1].AreaSize := 1;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := ACvar;
dtmSubPoints[1].Tolerance := 0;
dtmSubPoints[2].x := 933;
dtmSubPoints[2].y := 373;
dtmSubPoints[2].AreaSize := 1;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := ACvar;
dtmSubPoints[2].Tolerance := 0;
dtmSubPoints[3].x := 928;
dtmSubPoints[3].y := 377;
dtmSubPoints[3].AreaSize := 1;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := ACvar;
dtmSubPoints[3].Tolerance := 0;
dtmSubPoints[4].x := 913;
dtmSubPoints[4].y := 378;
dtmSubPoints[4].AreaSize := 1;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := ACvar;
dtmSubPoints[4].Tolerance := 0;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Congratulations, you have now just autocolored your first DDTM, which now makes it a proper DDTM!
III. Dynamic: Tolerance Changing
Alright, another method for creating a proper DDTM is dynamic tolerance. For this section, we are going to include DDTM finding, aswell as declaration. So lets go back to the original model of our DDTM. we are going to add a Global variable first (This means a variable outside the Function/Procedure usually at the top of the script). So lets call our Global Variable ddtmTolerance, and we will make it an integer. So under
{.include SRL/SRL.scar}
Add:
var ddtmTolerance: integer;
Now lets head back to our DDTM and this time we will change all the Tolerances for the mainpoint and subpoints to this:
dtmMainPoint.Tolerance := ddtmTolerance;
In the end our script will now look like below:
function SetDDTM: Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
begin
ACvar := FindVarrockRoadColor;
dtmMainPoint.x := 918;
dtmMainPoint.y := 375;
dtmMainPoint.AreaSize := 1;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 8028292;
dtmMainPoint.Tolerance := ddtmTolerance;
dtmSubPoints[0].x := 918;
dtmSubPoints[0].y := 375;
dtmSubPoints[0].AreaSize := 1;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := 8028292;
dtmSubPoints[0].Tolerance := ddtmTolerance;
dtmSubPoints[1].x := 904;
dtmSubPoints[1].y := 372;
dtmSubPoints[1].AreaSize := 1;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := 8028292;
dtmSubPoints[1].Tolerance := ddtmTolerance;
dtmSubPoints[2].x := 933;
dtmSubPoints[2].y := 373;
dtmSubPoints[2].AreaSize := 1;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := 8028292;
dtmSubPoints[2].Tolerance := ddtmTolerance;
dtmSubPoints[3].x := 928;
dtmSubPoints[3].y := 377;
dtmSubPoints[3].AreaSize := 1;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := 8028292;
dtmSubPoints[3].Tolerance := ddtmTolerance;
dtmSubPoints[4].x := 913;
dtmSubPoints[4].y := 378;
dtmSubPoints[4].AreaSize := 1;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := 8028292;
dtmSubPoints[4].Tolerance := ddtmTolerance;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Alright so now have that declared. So now we have a variable to change the tolerance, but it doesnt do anything yet. So lets make a DDTM finding procedure, we'll make it as so:
Function FindDDTMonMM: Boolean;
var x,y, theddtm: Integer;
begin
ddtmTolerance := 5;
theddtm := SetDDTM;
repeat
if not DtmRotated(theddtm, X, Y, MMX1, MMY1, MMX2, MMY2) then
begin
IncEx(ddtmTolerance, 5)
FreeDTM(theddtm);
theddtm := SetDDTM;
end else
begin
Result := True;
Break;
end;
until (ddtmTolerance >= 50);
ddtmTolerance := 5;
FreeDtm(theddtm);
end;
Looks confusing, but really its not. Lets break it down step by step.
ddtmTolerance := 5; Pretty much self explainitory, we set the initial ddtmTolerance to 5.
theddtm := SetDDTM;we declare the ddtm so that it doesnt get constantly declared as the function repeats, this saves time and memory.
if not DtmRotated(theddtm, X, Y, MMX1, MMY1, MMX2, MMY2) then this is just a basic way of finding a ddtm. Used mostly for finding ddtms on the Minimap.
IncEx(ddtmTolerance, 5) else
begin
Result := True;
Break;
end; ok so IncEx(the variable you want to increase, how much you want to increase the variable by). the "else" is used because we use an if then loop. so the script tries to find the ddtm if it doesn't (if not) then it increases the tolerance and continues through the loop. If it does find the DDTM then it makes the result true and then breaks out of the loop. We dont exit because we want to free the DDTM to save memory.
until (ddtmTolerance >= 50); Pretty much this is just a failsafe, if it continually cannot find the ddtm and the tolerance reaches a point of being 50 or higher, it breaks from the loop.
ddtmTolerance := 5;
FreeDtm(theddtm); the first line just resets the tolerance, just incase you use it in another procedure, you wouldnt want it to be 45 tolerance, so we reset it to 5 to be safe. The second line simply free's the DDTM.
Alright awesome, so you've sucessfully made your first ddtm with a dynamic tolerance! Congratulations.[/quote]
IV. Extra Notes
Here I will add all the extra stuff about DDTM's I can think of really that is somewhat helpful.
Ok, so this will be very brief as I'm tired. Declaring Multiple DDTM's is a very common mistake with many people. Some people think it takes numerous amounts of lines and procedures, when in reality its takes a very small amount. Here is an example of how I load numerous DDTM's.
var Rdcl: Integer;
Function SetWalkDtm(Number:Integer): Integer;
var MainPoint: TDTMPointDef; dtmSubPoints: Array [0..3] of TDTMPointDef; TempTDTM: TDTM; i: Integer;
begin
RdCl := FindVarrockRoadColor;
case Number of
0:
begin
with MainPoint do
begin
x := 934;
y := 378;
AreaSize := 1;
AreaShape := 0;
Color := RdCl;
Tolerance := 5;
end;
dtmSubPoints[0].x := 934;
dtmSubPoints[0].y := 378;
dtmSubPoints[1].x := 922;
dtmSubPoints[1].y := 375;
dtmSubPoints[2].x := 942;
dtmSubPoints[2].y := 375;
dtmSubPoints[3].x := 939;
dtmSubPoints[3].y := 381;
end;
1:
begin
with MainPoint do
begin
x := 915;
y := 375;
AreaSize := 1;
AreaShape := 0;
Color := Rdcl;
Tolerance := 5;
end;
dtmSubPoints[0].x := 907;
dtmSubPoints[0].y := 371;
dtmSubPoints[1].x := 921;
dtmSubPoints[1].y := 372;
dtmSubPoints[2].x := 908;
dtmSubPoints[2].y := 377;
dtmSubPoints[3].x := 920;
dtmSubPoints[3].y := 377;
end;
2:
begin
with MainPoint do
begin
x := 880;
y := 408;
AreaSize := 1;
AreaShape := 0;
Color := Rdcl;
Tolerance := 5;
end;
dtmSubPoints[0].x := 880;
dtmSubPoints[0].y := 408;
dtmSubPoints[1].x := 880;
dtmSubPoints[1].y := 400;
dtmSubPoints[2].x := 883;
dtmSubPoints[2].y := 416;
dtmSubPoints[3].x := 883;
dtmSubPoints[3].y := 412;
end;
end;
for i := 0 to High(dtmSubPoints) do
begin
dtmSubPoints[i].AreaSize := 1;
dtmSubPoints[i].AreaShape := 0;
dtmSubPoints[i].Color := RdCl;
dtmSubPoints[i].Tolerance := 5;
end;
TempTDTM.MainPoint := MainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
ok so your probably like Wtf? So I'll walk you through it as best I can.
RdCl := FindVarrockRoadColor; this is exactly what Part II is about in the tutorial, its an autocolor for all the ddtm points. now, for the function, all I do is declare the DDTM mainpoints and subpoints through an index which is called in the function (so say I want the first ddtm, its simply SetWalkddtm(0); ) After all of these are declared, I call the static parts of each of the ddtm's subpoints such as areasize, areashape ect. I use High() so that I can have any number of subpoints I so choose. This is a little confusing I know, I'm just tired and dont want to type anymore, so later I may elaborate.
Alright Ready for part 2? So ever noticed that your ddtm could be found in different locations on the mm? And the script messes up becauseit finds the ddtm somewhere else? Well here comes your answer.
Ok so, the first thing you will notice when you call upon a ddtm would look something like this...
DtmRotated(theddtm, X, Y, MMX1, MMY1, MMX2, MMY2)
Now the first thing you should note is that the DDTM searches the entire Minimap. Now how do we combat that? Well the easiest thing you can do is change the Minimap coords to fit your needs. so something like DtmRotated(theddtm, X, Y, MMcx, MMcy, MMX2, MMY2) that would look in the bottom right (third quadrant of the Minimap). Again you can substitue the coords there for flat out numerals for a more exact search. This is a point that many people forget to do when finding DDTM's. Here's the function I like to use when I call for DDTM's in walking,
Function DtmLocate(q, w, e, r, Dtm: Integer): Boolean;
var x, y, thedtm: Integer;
begin
thedtm := dtm;
Result := DTMRotated(thedtm, x, y, q, w, e, r);
end;
V. End Credits
Not many real credits, but some good reads if your still interested in DDTM's.
adding the (D) in (D)DTM's (http://www.villavu.com/forum/showthread.php?t=36278&highlight=ddtm)
Complete DDTM Walking Tutorial (http://www.villavu.com/forum/showthread.php?t=32608) (My personal Fav)
DDTM's and their uses (http://www.villavu.com/forum/showthread.php?t=26968)
So thanks for reading, and I hope you learnt something. :)