SRL Archive - Research & Development Lounge

ItemDTM


Sabzi

2010-02-06 07:16:33

{*******************************************************************************
function ItemDTM(MiddlePoint: TPoint; Box: TBox; SubPoints: Integer): Integer;
By: Sabzi
Description: Will make a dtm of the item in the Box with the amount of
subpoints given.
*******************************************************************************}

function ItemDTM(MiddlePoint: TPoint; Box: TBox; SubPoints: Integer): Integer;

var
TPA, tempTPA: TPointArray;
TP: TPoint;
i, Degree, L: Integer;
dtmMP: TDTMPointDef;
dtmSP: array of TDTMPointDef;
TempTDTM: TDTM;

begin
FindColorsSpiralTolerance(MiddlePoint.x, MiddlePoint.y, TPA, srl_outline_black, Box.x1, Box.y1, Box.x2, Box.y2, 0); //Isn't there one without tolerance? :/

dtmMP.x := MiddlePoint.x;
dtmMP.y := MiddlePoint.y;
dtmMP.Tolerance := 255;

for i := 0 to SubPoints - 1 do
begin
tempTPA := TPA;
Degree := Round(360 / SubPoints * (i + 0.5));
FilterPointsPie(tempTPA, Degree - 2, Degree + 2, 1, Distance(Box.x1, Box.y1, TP.x, TP.y), MiddlePoint.x, MiddlePoint.y);
if Length(tempTPA) > 0 then //Better then nothing. :S
begin
Inc(L);
SetArrayLength(dtmSP, L);
TP := tempTPA[High(tempTPA)]; //We want the outline so we want the farest point.
dtmSP[i].x := TP.x;
dtmSP[i].y := TP.y;
dtmSP[i].Color := srl_outline_black;
end;
end;

TempTDTM.MainPoint := dtmMP;
TempTDTM.SubPoints := dtmSP;
Result := AddDTM(TempTDTM);
end;

With the usage of this even if Jagex decides to update the outline color of the items every week, just one srl update and everything will be fine again(hopefully).

Example usage:
var
DTM, x, y: Integer;
TP: TPoint;
TB: TBox;

begin
SetupSRL;
TP := ItemCoords(1);
TB := InvBox(1);
DTM := ItemDTM(TP, TB, 4);
if FindDTM(DTM, x, y, MSX1, MSY1, MSX2, MSY2) then
begin
WriteLn('Hooooooray!');
MMouse(x, y, 5, 5);
end;
FreeDTM(DTM);
end.

If you wish to use this with stackable items(or items in bank) it may muck up because of the yellow numbers. I originally written this for only inventory(for bars) so I did not count that in. You can use some type of skipping color finder and that would solve it I think.

What do you think?

EDIT: Updated with failsafe.

Naum

2010-02-06 07:32:03

Nice, I remember I made something like this for MSI, however the main problem was in items which had the same outlines, hatchets, pickaxes, runes, weapons etc.

Looks good though :)

Sabzi

2010-02-06 07:41:04

From: Naum
Nice, I remember I made something like this for MSI, however the main problem was in items which had the same outlines, hatchets, pickaxes, runes, weapons etc.

Looks good though :)


Thanks, always good to hear good words from you.

I made this for my smelter that uses bar dtms to count them in inventory. So this isn't for individual items. But I think that can easily changed. Just use a middlepoint that is on the item(preferably with an unique color) then a simple getcolor for the mainpoint and then you have to set a tolerance for the mainpoint too. Still update survival imo.
I just put this out so everyone can modify/upgrade it how they like.

Wanted

2010-02-06 11:20:17

I really like this because it uses SRL_OutLine_Black, but in reference to this post (which is also copied here), I'm not sure using a function result as a location for a DTM is a particularly good idea.

Edit: RM nice catch, I could sworn it wasn't though. :redface:

Perhaps, using a 'var TheDTM: Integer; in the function parameters would avoid this problem?

Sir R. M8gic1an

2010-02-06 11:31:45

That post is in Devs, so here is the quote:

From: Wizzup

From: marpis
Question:


function LoadDTM: Integer;
begin
result := DTMFromString('akjdakjdakjda');
end;

procedure DoTehSex;
begin
if FindDTM(LoadDTM, X, Y, MMX1, MMY1, MMX2, MMY2) then // Here the DTM is loaded...
writeLn('Hasselhoff');
// ...but what happens to it now?
end;


The reference to the DTM is lost, and it will not be freed.
Look for a memory management tutorial made by pups. It's gotta be in here somewhere. :)


~RM

Sabzi

2010-02-06 12:35:10

From: IceFire908
I really like this because it uses SRL_OutLine_Black

That supposed to be the point of this.
I really don't know how scar handles function results. I just copied that part from nielsie's ddtm editor :p. But if you are(and why I shouldn't trust you(you = everybody above me in programming knowledge)) right then this is not good.

Wanted

2010-02-06 12:36:38

From: Sabzi
That supposed to be the point of this.
I really don't know how scar handles function results. I just copied that part from nielsie's ddtm editor :p. But if you are(and why I shouldn't trust you(you = everybody above me in programming knowledge)) right then this is not good.


I'm not a memory handling expert, but I do see the potential for memory leaks in this. I'm sure there is a good way to avoid them (if any) and still use this but I'm not entirely sure what the best option would be.

Sex

2010-02-06 12:52:32

Er.

var
DTM, x, y : integer;

function Blah : integer;
begin
result := DTMFromString('blahblahblah');
end;

begin
DTM := Blah;
if FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2) then
writeln('found..')
else
writeln('not found...');
FreeDTM(DTM);
end.

Sir R. M8gic1an

2010-02-06 12:58:50

From: Sex
Er.

var
DTM, x, y : integer;

function Blah : integer;
begin
result := DTMFromString('blahblahblah');
end;

begin
DTM := Blah;
if FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2) then
writeln('found..')
else
writeln('not found...');
FreeDTM(DTM);
end.


l2read

~RM

Sex

2010-02-06 13:05:46

From: Rasta Magician
l2read

~RM

No memory leak bro.
The handle is not lost and is able to be freed..

mixster

2010-02-06 14:07:14

If you wanted to do a simple method like that you can always have a global integer array and store them in there, then check if they have already been loaded before you do it. Anyway, I did produce something similar to this a while back and it turns out then that something similar to what I did also surfaced at around the same time (I think mine came out after theirs) so may be worth looking back to see if you can learn anything from those 2 to help you improve this (search for SmartDrop to find mine as it was a part of that).