PDA

View Full Version : Modify DTM at runtime?



Bixby Sayz
01-31-2014, 01:47 AM
Been dicking around with creating DTMs for items in RS3. Discovered the black outline for items is different in two cases:
- Quick item slot: Different black border, less border points.
- GE: Dark gray border, same border points as quick item slot.

It occurred to me a well designed dtm could cover all three situations provided there was an easy way to modify the dtm points. The lack of documentation makes it somewhat of a challenge. Been poking around the source code and the points property appears to be read only for both the TMDTM and TSDTM types. Can't seem to find a method that modifies the points either.

So...Is there a way to modify a dtm after it has been created (specifically the color of each point)?

tealc
01-31-2014, 01:55 AM
Yep http://villavu.com/forum/showthread.php?t=45346&highlight=ddtm

King
01-31-2014, 02:02 AM
Provided link leads to DDTMS, let me know if you need any help with them. They are pretty easy to work with.

Olly
01-31-2014, 02:18 AM
Lape <> PS.

Try this

var
dtm: TMDTM;
points: TMDTMPointArray;

begin
dtm.init();
dtm.addPoint(createDTMPoint(0, 0, 255, 0, 0, false));

points := dtm.getPoints();

with points[0] do
begin
writeln('before ', c);
c := 16777215;
writeln('after ', c);
end;

dtm.free();
end.

Though, wouldn't you rather have some small tolerance on the black outline?

Bixby Sayz
01-31-2014, 02:25 AM
This post lead me to believe DDTMs are no longer supported: http://villavu.com/forum/showthread.php?t=107554

That tutorial you link to is hideously out of date but I believe it can be adapted to use the TSDTM and TSDTMPointDef types, which is basically what I want to do. The Dtm documentation really needs an overhaul/update. I had to comb through Simba's source code to find the definition of those types.

Olly
01-31-2014, 02:28 AM
Missed my post. :(

Heh, all of Simba's doc is based on pascalscript and when lape came along with no real class support it kinda... gets confusing.

e: TSDTMs aren't exported to Lape.

King
01-31-2014, 02:56 AM
Been gone a while, I'm still catching up on the SRL-6 updates. Talk to Olly, as Olly := Genius.

Bixby Sayz
01-31-2014, 02:58 AM
Though, wouldn't you rather have some small tolerance on the black outline?I agree. And a small tolerance (and the right points) will find all items plus the slightly different item in quick inventory slot. However the same item in the GE has a dark gray border. The tolerance required renders the dtm pretty much useless.

I'm just dicking around to see if it can be done. Just because I can really.

Nebula
01-31-2014, 03:25 AM
When I tried using ddms about a year ago for a salamander hunting script, I spent hours trying to get it to work. followed like 5 tutorials including one by fakawi, tried everything possible, did not work.

I feel like a simple solution would be just to have a few different dtms stored for each of the possible colors... or increase the tolerance of the points using the dtm editor?

That or have a single dtm that only has the points that are constant and never random, then go through all the found dtms and find the one that has one of the changing colors near it.

I havent srl'd in a while so this might look rough but something like this: ( if ur not sure about what a function does just search for it on google like type in this: "site:villavu.com finddtms"

begin
finddtms(DtmTPA)
for i:= 0 to high(DtmTPA) do
for z := 0 to high(changingcolorlist) do
if findcolor(x, y, changingcolorlist[z], dtmtpa.x-5, dtmtpa.y+5, dtmtpa.x+5, dtm.y-5) then
PointWeAreLookingFor := DtmTPA[i];
end;

Bixby Sayz
01-31-2014, 03:31 AM
Yeah I could simply use a couple dtms. But I was trying to see if I could get it to work with just one just because I'm bored and hate letting a problem go unsolved. I'll mess around with it more later. I don't even need the GE version of the item. I just wanted to see if I could do it on the fly well just because.

Olly
01-31-2014, 03:45 AM
Didn't I give a solution tho..?

http://villavu.com/forum/showthread.php?t=107813&p=1282851#post1282851

Bixby Sayz
01-31-2014, 05:14 PM
Didn't I give a solution tho..?

http://villavu.com/forum/showthread.php?t=107813&p=1282851#post1282851You gave the start of a solution.

I'm starting with a regular ol' dtm reference and wanting to modify the color of the subpoints. Which means you have to getDTM to get it into the TMDTM structure. And this appears to be a copy since any changes are not reflected back to the original dtm.

Which means you have to free the original dtm and assign the modified mdtm to it. But this throws an error (of course it does) using mdtm. Works like a charm if you use a TSDTM instead.

This throws an error:

procedure SetDtmSubPointsColor(var ItemDtm: Integer; const Color: Integer);
var
ItemMdtm: TMDTM; // Dtm converted to a TMDTM structure.
DtmPoints: TMDTMPointArray; // Dtm points.
HiPoints: Integer; // Number of subpoints.
PointsIdx: Integer; // Loop counter - current subpoint.
begin
if not dtmExists(ItemDtm) then
Exit;

// Copy dtm into tmdtm record so we can work with it.
ItemMdtm := GetDTM(ItemDtm);
DtmPoints := ItemMdtm.getPoints();

// Loop through the subpoints setting color.
HiPoints := (ItemMdtm.getCount() - 1);
if (HiPoints < 1) then
Exit;
for PointsIdx := 1 to HiPoints do
DtmPoints[PointsIdx].c := Color;

// Assign modified record back to dtm.
FreeDTM(ItemDtm);
ItemDtm := AddDTM(ItemMdtm); // This line throws an error???
end; // proc

But this works quite nicely:

procedure SetDtmSubPointsColor(var ItemDtm: Integer; const Color: Integer);
var
ItemSdtm: TSDTM; // Dtm converted to a TSDTM record.
DtmName: String; // Name of dtm.
HiPoints: Integer; // Number of subpoints.
PointsIdx: Integer; // Loop counter - current subpoint.
begin
if not dtmExists(ItemDtm) then
Exit;

// Copy dtm into tsdtm record so we can work with it.
ItemSdtm := MDTMToSDTM(GetDTM(ItemDtm));

// Loop through the subpoints setting color.
HiPoints := High(ItemSdtm.SubPoints);
if (HiPoints < 0) then
Exit;
for PointsIdx := 0 to HiPoints do
ItemSdtm.SubPoints[PointsIdx].Color := Color;

// Assign modified record back to dtm.
DtmName := GetDTMName(ItemDtm);
FreeDTM(ItemDtm);
ItemDtm := AddSDTM(ItemSdtm);
SetDTMName(ItemDtm, DtmName);
end; // proc

Mission accomplished. I solved the problem even though I most likely will never actually use the code. A good day.


When I tried using ddms about a year ago for a salamander hunting script, I spent hours trying to get it to work. followed like 5 tutorials including one by fakawi, tried everything possible, did not work.
This could perhaps be adapted to whatever you want to do. If you do you may want these functions as well:


function CreateSdtmPoint(const X, Y, Color, Tolerance, AreaSize, AreaShape: Integer): TSDTMPointDef;
begin
Result.X := X;
Result.Y := Y;
Result.Color := Color;
Result.Tolerance := Tolerance;
Result.AreaSize := AreaSize;
Result.AreaShape := AreaShape;
end; // proc

procedure PrintSdtm(const Sdtm: TSDTM);
var
HiPoints: Integer; // Number of subpoints.
PointsIdx: Integer; // Loop counter - current subpoint.
begin
with Sdtm.MainPoint do
WriteLn(Format('MP: (%d,%d) C:%d, T:%d, Sz:%d, Shp:%d', [X, Y, Color, Tolerance, AreaSize, AreaShape]));
HiPoints := High(Sdtm.SubPoints);
if (HiPoints > (-1)) then
for PointsIdx := 0 to HiPoints do
with Sdtm.SubPoints[PointsIdx] do
WriteLn(Format('P%d: (%d,%d) C:%d, T:%d, Sz:%d, Shp:%d', [PointsIdx, X, Y, Color, Tolerance, AreaSize, AreaShape]));
end; // proc

Olly
01-31-2014, 06:18 PM
Heh TSDTMs are exported to lape? Never knew that.