SRL Archive - OSR Advanced Scripting Tutorials

How to make Dynamic DTM's with DIVI.


WT-Fakawi

2007-05-12 12:06:44

As most of you will know, DIVI supports dynamic DTM's. DTM's can now be modified during runtime. You could even create your own DTM's using DIVI's powerfull DTM AddDTM; function while the script is running!
For this tut, I assume you have (basic) knowledge of DTM 's: knowing what they are, how to make 'm and how to use them.

TDTMPointdef

DTM 's are made of a number of Dynamic Deformable Template Model Point Definitions: TDTMPointdef. These TDTMPointdef records have the following members:
  • TDTMPointdef.x
  • TDTMPointdef.y
  • TDTMPointdef.areasize
  • TDTMPointdef.areashape
  • TDTMPointdef.tolerance
  • TDTMPointdef.color

If you have ever made a DTM, these variables must look familiair, exactly the same can be seen in the DTM-Editor:





There are two kind of TDTMPointdef's: one MainPoint and an arbitrary number of SubPoints. The MainPoint is the DTM's HotSpot, it's the coordinate that is returned by FindDTM. The SubPoints are the DTM's Reference Points grouped together in an array.

So, there can only be one MainPoint but many SubPoints. These indiviual TDTMPointdef are grouped together into the TDTM type.The TDTM consists of:
  • TDTM.MainPoint
  • TDTM.SubPoints
of type TDTMPointdef.

An example

var SubPoints: array[0..2] of TDTMPointDef;
var MainPoint : TDTMPointDef;
var MasterTDTM: TDTM;
var TheDTM:Integer;

procedure AssembleDTM;
begin
MainPoint .x:=625;
MainPoint .y:=34;
MainPoint .areasize:=1
MainPoint .areashape:=0;
MainPoint .color:=6843241;
MainPoint .tolerance:=10;

SubPoints[0].x:=630;
SubPoints[0].y:=31;
SubPoints[0].areasize:=1;
SubPoints[0].areashape:=0;
SubPoints[0].color:=6843241;
SubPoints[0].tolerance:=10;

SubPoints[1].x:=623;
SubPoints[1].y:=30;
SubPoints[1].areasize:=1;
SubPoints[1].areashape:=0;
SubPoints[1].color:=6843241;
SubPoints[1].tolerance:=10;

MasterTDTM.MainPoint := MainPoint;
MasterTDTM.SubPoints := SubPoints;
TheDTM:= AddDTM(MasterTDTM);
end;
We have succesfully made a DTM named TheDTM consisting of one MainPoint and two AnchorPoints. The last lines are most important:
MasterTDTM.MainPoint := MainPoint;
MasterTDTM.SubPoints := SubPoints;
TheDTM:= AddDTM(MasterTDTM);
We assign the individual TDTMPointDef's to the MasterTDTM and convert the MasterTDTM to TheDTM using function AddDTM(DTM: TDTM): Integer;


Advantages


The advantages are numereous. Whilst DTM's where pretty static objects in SCAR 2.03, now you can remodel to your hearts content. Some of the more obvious advantages:
  • Assign variables to any Member of the TDTMPointDef.
  • Assign your own Colors to any Point inside a DTM.
  • Create or Modify Point Coordinates.
  • Adjust the size, shape and tolerance of any given Point.
  • Alter the length of the SubPoint-Array.

You could even write a DTM-maker tool, that scans for common colors and decides upon the best main and subpoints.


Making Dynamic DTM's

Alas, making Dynamic DTM's is still a troublesome process. You first need to make a normal DTM using the DTM-editor, and then you will need to manually fill in each variabe inside your TDTMPointDef's. Too bad SCAR "hangs" with the DTM-Editor open, so you will need a second SCAR open to type in the values into the TDTMPointDef's.



——————————————————-



Full Working RS-Example


Here is a full working Dynamic DTM example as posted before on the inside DIVI… forum.





Stand below Falador above Rimmington Mine. Fill in the RoadColor. The script will find centrepoint (tol 255 thus any color (!)) at almost any angle and move the mouse to the centre of the bifurcation.


program BifurcationFinder;
var CGPT: array[0..2] of TDTMPointDef;
var CGMainPT: TDTMPointDef;
var CG: TDTM;
var CGx, CGy: Integer;
var CGDTM: Integer;
var WhichAngle: Extended;

const RoadColor = 5921377; // ColorPick RoadColor.
const Tolerance = 1;
const AreaSize = 1;
const AreaShape = 0;

procedure SetCGDTM;
begin

CGMainPT.x:=648; // Centre Of Minimap
CGMainPT.y:=83;
CGMainPT.areasize:=1;
CGMainPT.areashape:=0;
CGMainPT.color:=0;
CGMainPT.tolerance:=255; // Any Color

CGPT[0].x:=615;
CGPT[0].y:=59;
CGPT[0].areasize:=AreaSize;
CGPT[0].areashape:=AreaShape;
CGPT[0].color:=RoadColor ;
CGPT[0].tolerance:=Tolerance;

CGPT[1].x:=672;
CGPT[1].y:=75;
CGPT[1].areasize:=AreaSize;
CGPT[1].areashape:=AreaShape;
CGPT[1].color:=RoadColor ;
CGPT[1].tolerance:=Tolerance;

CGPT[2].x:=632;
CGPT[2].y:=105;
CGPT[2].areasize:=AreaSize;
CGPT[2].areashape:=AreaShape;
CGPT[2].color:=RoadColor ;
CGPT[2].tolerance:=Tolerance;
CG.MainPoint := CGMainPT;
CG.SubPoints := CGPT;
end;

begin
SetCGDTM;
CGDTM:=AddDTM(CG);
Repeat
Wait(1000);
if FindDtmRotated(CGDTM, CGx, CGy, MMX1, MMY1, MMX2, MMY2, -PI*2, PI*2, 0.2,
WhichAngle) then
begin
Writeln(IntToStr(CGx)+' '+IntToStr(CGy) + ' at '+FLoatToStr(WhichAngle));
MoveMouse(CGx, CGy);
writeln('DTMRotated Found');
end else writeln('Not Found');
Wait(1000);
until False
end.











Another Example





This DTM is made of three RockColorpixels (= a constant), plus a "any" color MainPoint (color 0 and tol 255)
Provided you know this RockColor, you can callibrate in any direction! I use it in my priv. GoblinTrainer to keep my Players inside the GoblinHouse. Try and see for yourself. Position your Player at the GoblinHouse, Set RoadColor in line 9 and walk a little around the house, you can even walk upwards to the chickenchurn, DIVI checks if our MoveMouse is in Bounds with the MiniMap using the new function rs_OnMinimap. If it discovers the coords are out of bounds, it will move the mouse to the centre of the DTM. It will work from - Pi/2 til Pi/2, a halve circle.


program GoblinRock;
var DTMSubPoints: array[0..2] of TDTMPointDef;
var CGMainPoint: TDTMPointDef;
var RockTDTM: TDTM;
var CGx, CGy: Integer;
var RockDTM: Integer;
var WhichAngle: Extended;

const RoadColor = 6843241; // ColorPick RoadColor.
const Tolerance = 1;
const AreaSize = 1;
const AreaShape = 0;

procedure SetRockDTM;
begin

CGMainPoint.x:=625;
CGMainPoint.y:=34;
CGMainPoint.areasize:=1;
CGMainPoint.areashape:=0;
CGMainPoint.color:=0;
CGMainPoint.tolerance:=255; // Any Color

DTMSubPoints[0].x:=630;
DTMSubPoints[0].y:=31;
DTMSubPoints[0].areasize:=AreaSize;
DTMSubPoints[0].areashape:=AreaShape;
DTMSubPoints[0].color:=RoadColor;
DTMSubPoints[0].tolerance:=Tolerance;

DTMSubPoints[1].x:=623;
DTMSubPoints[1].y:=30;
DTMSubPoints[1].areasize:=AreaSize;
DTMSubPoints[1].areashape:=AreaShape;
DTMSubPoints[1].color:=RoadColor;
DTMSubPoints[1].tolerance:=Tolerance;

DTMSubPoints[2].x:=628;
DTMSubPoints[2].y:=37;
DTMSubPoints[2].areasize:=AreaSize;
DTMSubPoints[2].areashape:=AreaShape;
DTMSubPoints[2].color:=RoadColor;
DTMSubPoints[2].tolerance:=Tolerance;

RockTDTM.MainPoint := CGMainPoint;
RockTDTM.SubPoints := DTMSubPoints;
RockDTM := AddDTM(RockTDTM);
end;


begin
SetRockDTM;
Repeat
Wait(1000);
if FindDtmRotated(RockDTM, CGx, CGy, MMX1, MMY1, MMX2, MMY2, - Pi/2, Pi/2, 0.1,
WhichAngle) then
begin
if rs_OnMinimap(CGx + 10, CGy + 50) then
MoveMouse(CGx + 10, CGy + 50)
else
MoveMouse(CGx, CGy)
writeln('DTMRotated Found');
end
else
writeln('not found');
Wait(1000);
until False
end.

Hobbit

2007-05-12 12:10:32

Wow nice. Very helpful tut thanks.

Edit: First post too :)

WT-Fakawi

2007-05-12 14:12:17

Added another example.

Abyssal

2007-05-12 14:46:56

Ah, thank you so much for this Fawki :) Will help tons.

Smartzkid

2007-05-12 14:48:52

Awesome!

I'm gonna have to spend some time learning these…

Yakman

2007-05-12 14:52:19

very nice fakawi, its very well explainined

tarajunky

2007-05-12 16:05:19

I think this is one of the most powerful new tools available in Divi. I haven't jumped in and tried making use of it yet, but I am excited about the possibilities!

Hugolord

2007-05-12 17:38:09

ohh nice examples Fakawi they are clear to understand

Harled

2007-06-01 10:24:04

Nice tutorial :) Im still not 100% sure how this works but this helped me enough that I have some idea.

YoHoJo

2007-06-07 13:27:57

Great tutorial, quite easy if you already know DTMs, i just learned by looking at the code =). But i bet the words also help :p.
Im going to try to use these also for my mapwalking experiments w/ DTMs.
++rep haha

Pentti

2007-06-07 13:46:29

Thanks for making this tutorial!
This explained me pretty good how to use DDTMs.

…Time to do some tests with them. :D

tim46

2007-06-09 11:10:29

Hmm, dosn't sound to hard. Very interesting :)

Hugolord

2007-06-09 12:09:12

I'm still a little confused between DDTMs and DTMs i mean whats the difference? (sorry about stupid question :( )

3Garrett3

2007-06-09 19:32:30

wow, i actually understand now! i read it before, and didnt, but now i do! So, i can walk with these things too right? :)

the scar noob

2007-06-11 15:25:29

Wt-Fakawi, i beg you writing a tut in dutch cause i really want to learn, but i just don't get it :( plz i'm begging you (aub ik smeek u).

wtf i sp4nk

2007-06-14 08:21:38

I understand the whole dtm part and how to make one and to get it to click there but i dont understand the inside bounds part and i could realy use it for a chicken killer im making if anyone is willing to explain the plz talk to me on msn mine is [email]crazyirishman84@hotmail.com[/email]

Dan Cardin

2007-06-14 08:36:41

i have
procedure AssembleDTM;
begin
MainPoint .x:=821;
MainPoint .y:=242;
MainPoint .areasize:=0;
MainPoint .areashape:=0;
MainPoint .color:=DirtRoadColor;
MainPoint .tolerance:=0;

SubPoints[0].x:=823;
SubPoints[0].y:=256;
SubPoints[0].areasize:=1;
SubPoints[0].areashape:=0;
SubPoints[0].color:=WaterColor;
SubPoints[0].tolerance:=0;

SubPoints[1].x:=823;
SubPoints[1].y:=230;
SubPoints[1].areasize:=1;
SubPoints[1].areashape:=0;
SubPoints[1].color:=WaterColor;
SubPoints[1].tolerance:=0;

SubPoints[2].x:=801;
SubPoints[2].y:=239;
SubPoints[2].areasize:=1;
SubPoints[2].areashape:=0;
SubPoints[2].color:=DirtRoadColor;
SubPoints[2].tolerance:=0;

SubPoints[3].x:=843;
SubPoints[3].y:=241;
SubPoints[3].areasize:=1;
SubPoints[3].areashape:=0;
SubPoints[3].color:=DirtRoadColor;
SubPoints[3].tolerance:=0;

MasterTDTM.MainPoint := MainPoint;
MasterTDTM.SubPoints := SubPoints;
TheDTM:= AddDTM(MasterTDTM);
end;
if FindDtmRotated(CGDTM, CGx, CGy, MMX1, MMY1, MMX2, MMY2, -PI*2, PI*2, 0.2,WhichAngle) then
Mouse(x,y,2,2,true);
…but it keeps clicking above the birdge(by the way this is the bridge between barb village and varrok

YoHoJo

2007-07-01 22:36:29

lol dan i doubt anyone is going to test that for you.
Just make sure you choose more unique points and that its unique.

From: hugolord
I'm still a little confused between DDTMs and DTMs i mean whats the difference? (sorry about stupid question :( )


You make DTMs in the DTM editor and they spit out stuff like:
  KnifeOutline := DTMFromString('78DA63F464626078C8800232E2E318FE03694' +
'620FE0F048C6E986A80C2609A11CA67B407AA7947408D0F50CD13' +
'FC6A001C5C13D6');
Set tolerance, set points, set area, set color.

Now, DDTMs are the same thing, but in human understandable code, allowing us to edit them more easily and adding tolerance and are while the script runs!
Amazing! =)

Junior

2007-07-02 19:06:45

Awesome tutorial. Never understood this but now its pretty easy to understand. Good job!

Nashi

2007-07-03 06:28:07

Awesome tut Fawki, It made sense :D
The second time I read through it xP
I bookmarked it cause, I'll forget it >_<

Anyway, I never realised how useful DTMs could be :O

I'm use this for my Air Crafter :D

(To anyone who thinks "OMG ITS A LEECHER" because I probly have big longevity and low activity and 4 posts now(I think) its because I took a break from scripting okay..)

ZephyrsFury

2007-07-04 08:36:20

From: dan cardin
i have
procedure AssembleDTM;
begin
MainPoint .x:=821;
MainPoint .y:=242;
MainPoint .areasize:=0;
MainPoint .areashape:=0;
MainPoint .color:=DirtRoadColor;
MainPoint .tolerance:=0;

SubPoints[0].x:=823;
SubPoints[0].y:=256;
SubPoints[0].areasize:=1;
SubPoints[0].areashape:=0;
SubPoints[0].color:=WaterColor;
SubPoints[0].tolerance:=0;

SubPoints[1].x:=823;
SubPoints[1].y:=230;
SubPoints[1].areasize:=1;
SubPoints[1].areashape:=0;
SubPoints[1].color:=WaterColor;
SubPoints[1].tolerance:=0;

SubPoints[2].x:=801;
SubPoints[2].y:=239;
SubPoints[2].areasize:=1;
SubPoints[2].areashape:=0;
SubPoints[2].color:=DirtRoadColor;
SubPoints[2].tolerance:=0;

SubPoints[3].x:=843;
SubPoints[3].y:=241;
SubPoints[3].areasize:=1;
SubPoints[3].areashape:=0;
SubPoints[3].color:=DirtRoadColor;
SubPoints[3].tolerance:=0;

MasterTDTM.MainPoint := MainPoint;
MasterTDTM.SubPoints := SubPoints;
TheDTM:= AddDTM(MasterTDTM);
end;
if FindDtmRotated(CGDTM, CGx, CGy, MMX1, MMY1, MMX2, MMY2, -PI*2, PI*2, 0.2,WhichAngle) then
Mouse(x,y,2,2,true);
…but it keeps clicking above the birdge(by the way this is the bridge between barb village and varrok


You've called the DDTM 'TheDTM' while putting 'CGDTM' in the function. If that doesn't solve it, make sure you specify the dirt and water colours just before you run 'AssembleDTM'.

YoHoJo

2007-07-04 17:15:16

@Dan

The name of your dtm is
'TheDTM'
as you said here
TheDTM:= AddDTM(MasterTDTM);

So yo gota do If FindDTM(TheDTM) Then

n3ss3s

2007-07-06 08:06:26

one question: Do I have to make DDTM to find rotated DTMs or do I justed use the FindDTMRotated thingy?
Because if I can just use normal DTMs I wasted some time, but actually it wasnt waste, still learned sumting :)

btw fawki you have endless loop in your script with no break and MOVEMOUSE!

What did you do to the real fawki and where is he!?

the nerd

2007-07-06 08:38:45

Wow. Very clear and concise tut. (Still had to read it twice). This tut will help with mapwalking and find things on the minimap that don't have constant colours or icons.

But is there an easier way to create DDTMS without have to enter all the varables in manualy?

ZephyrsFury

2007-07-06 12:17:46

From: n3ss3s
one question: Do I have to make DDTM to find rotated DTMs or do I justed use the FindDTMRotated thingy?
Because if I can just use normal DTMs I wasted some time, but actually it wasnt waste, still learned sumting :)


The point of a DDTM is that you can create one during a script, ie. you can create one with up-to-date colours such as the road colour at the exactly time and not having to go through the trouble with getting the right colours and tolerances while making a DTM. Of course you can use FindDTMRotated to find normal DTM's. I think its what it was designed for. DDTM's are relatively new.

Infantry001

2007-07-06 14:28:33

Great tut Fakawi! Ill be sure to use this :D

Quick question - Unset variables will result in 0, right?

YoHoJo

2007-07-10 03:39:26

From: n3ss3s
one question: Do I have to make DDTM to find rotated DTMs or do I justed use the FindDTMRotated thingy?
Because if I can just use normal DTMs I wasted some time, but actually it wasnt waste, still learned sumting :)

btw fawki you have endless loop in your script with no break and MOVEMOUSE!

What did you do to the real fawki and where is he!?


DDTMs can be used anywhere DTMs are.
No time was wasted though, as for DDTMs you can enter your down colors and edit them.
It will be hard to make a DTM that will always work for roadcolor.
As for with a DDTM youcan do like
Mainpoint.Color:=GetVarockRoadColor;

Which which work a whole lot better.

itSchRis917

2007-07-12 15:57:21

Thank you so much WT- Fakawi! Awesome tutorial!

Negaal

2007-10-15 10:29:10

well, i did not fully understand but, when looking on your tut same time, i can make ddtm like yours….rofl dtms and bmps are easy… peoples sayng ddtm is bit harder… sigh… anyways big thanks, really thankful:)