SRL Archive - SRL Archives

SmartDrop and DTMFromInv


mixster

2008-10-04 19:52:45

procedure DTMFromInv(var oDTM: Integer; slot, refPts: Integer);
var
Skel: TDTM;
mainPt: TDTMPointDef;
subPts: array of TDTMPointDef;
outPts: TPointArray;
invBoxC: TBox;
i, outRat, rI: Integer;
begin
invBoxC := InvBox(slot);
if not FindColorsTolerance(outPts, 65536, invBoxC.x1 + 2, invBoxC.y1 + 2, invBoxC.x2 - 2, invBoxC.y2 - 2, 1) then
begin
Writeln('Unable to create DTM from inventory slot as no outline colours found');
Exit;
end;
with mainPt do
begin
x := (invBoxC.x1 + invBoxC.x2) div 2;
y := (invBoxC.y1 + invBoxC.y2) div 2;
areasize:= 0;
areashape:= 0;
color:= GetColor(mainPt.x, mainPt.y);
tolerance:= 422;
end;
SetArrayLength(subPts, refPts);
outRat := GetArrayLength(outPts) div refPts;
for i := 0 to refPts - 1 do
begin
rI := Random(Random(Round(outRat)));
with subPts[i] do
begin
x := outPts[round(i * outRat) + rI].x;
y := outPts[round(i * outRat) + rI].y;
areasize:= 0;
areashape:= 0;
color:= 65536;
tolerance:= 1;
end;
end;
Skel.MainPoint := mainPt;
Skel.SubPoints := subPts;
oDTM := AddDTM(Skel);
end;

function CompStrWArr(str: string; strArr: array of string): boolean;
var
i: Integer;
begin
for i := 0 to High(strArr) do
if Result then
Exit;
if str = strArr[i] then
Result := True;
end;

function SmartDrop(var iDtmArr: array of Integer; var sDtmArr: array of string; sItemsArr: array of string; bDropMatched: Boolean): Integer;
var
iX, iY, iItemX, iItemY, iItem, iDtm, iStr, iItemOffset: Integer;
bDir, bDropSet: Boolean;
tbItem: TBox;
begin
bDir := RBool;
for iItemY := 1 to 7 do
begin
for iItemX := 1 to 4 do
begin
bDropSet := False;
if((bDir)and(iItemY mod 2 = 1))or((not(bDir))and(iItemY mod 2 = 0))then
iItemOffset := 5 - iItemX
else
iItemOffset := iItemX;
iItem := ((iItemY - 1) * 4) + iItemOffset;
if(not(ExistsItem(iItem)))then
begin
Continue;
end;
tbItem := InvBox(iItem);
if(High(iDtmArr) >= 0) then
begin
for iDtm := 0 to High(iDtmArr) do
begin
if((CompStrWArr(sDtmArr[iDtm], sItemsArr)) and (FindDtm(iDtmArr[iDtm], iX, iY, tbItem.x1, tbItem.y1, tbItem.x2, tbItem.y2))and(not(bDropSet)))then
begin
bDropSet := True;
end;
end;
end;
if(not(bDropSet))then
begin
MMouseItem(iItem);
Wait(250+Random(Random(1000)));
for iStr := 0 to High(sItemsArr) do
begin
if(IsUpText(sItemsArr[iStr])and(not(bDropSet)))then
begin
bDropSet := True;
SetArrayLength(iDtmArr, High(iDtmArr) + 2);
SetArrayLength(sDtmArr, High(sDtmArr) + 2);
DTMFromInv(iDtmArr[High(iDtmArr)], iItem, 15);
sDtmArr[High(sDtmArr)] := sItemsArr[iStr];
end;
end;
end;
if(not(bDropSet xor bDropMatched))then
begin
GetMousePos(iX, iY);
if(not((iX >= tbItem.x1) and (iX <= tbItem.x2) and (iY >= tbItem.y1) and (iY <= tbItem.y2)))then
DropItem(iItem)
else
begin
Mouse(iX, iY, 1, 1, False);
Wait(150 + Random(75));
if(not(ChooseOption('Drop')))then
Dec(Result)
else
Wait(100 + Random(50));
end;
Inc(Result);
Wait(Random(Random(500)));
end;
end;
end;
end;

DTMFromInv: generates a DTM and places in oDTM made from slot slot with refPts number of reference points. May be disgruntled by stacks - haven't tested extensively with stacks - but shouldn't have a problem, if so should be easy enough to fix.
CompStrWArr: small function that SmartDrop uses - returns true is string str is in the string array strArr.
SmartDrop: iDTMArr holds the DTM's it creates - should be empty as function fills it out. sDTMArr holds the item that the same index of iDTMArr holds - should also be blank as function fills it out. sItemsArr should be filled out with the items it should drop or keep (depending on bDropMatched). bDropMatched should be true if you want it to drop items that it matches UpText to and/or DTM or false if you want it to drop all others.

Hoping for feedback - especially as it is my only RuneScape related procedures. Also hoping that one bit may get added in even a small way :)

Blumblebee

2008-10-05 05:18:23

didnt really loook over the code, but by the sounds of it seems impressive, nice work!

-Blumblebee

Wizzup?

2008-10-05 06:25:27

Maybe store what invspot's actually have an item, make a boolean array of that, and when you drop an item, set that value in the boolean array to false. (Will save you alot of ExistItem)

mixster

2008-10-05 06:33:19

But then what happens if the player is changed or something like that? Also, I would still have to check empty spaces, which would be near all most of the time, so it wouldn't save that much ExistItem in the long run :)

HyperSecret

2008-10-09 20:01:29

very nice man, i tried something of this sort quite a while ago! I can't seem to find what I had eventually finished with…

Nava2

2008-10-21 18:14:05

Yours is better than myles, unsure as to why his gets the attention. :)

I remember trying todo this myself, but failing miserably.

Good Job!

Tootoot222

2008-10-27 04:02:18

i think that in CompStrWArr you'd only be checking the last strArr value, as you don't have a begin/1 statement:


//You have:

function CompStrWArr(str: string; strArr: array of string): boolean;
var
i: Integer;
begin
for i := 0 to High(strArr) do
if Result then
Exit;
if str = strArr[i] then
Result := True;
end;

//Should be:

function CompStrWArr(str: string; strArr: array of string): boolean;
var
i: Integer;
begin
for i := 0 to High(strArr) do
begin
if Result then
Exit;
if str = strArr[i] then
Result := True;
end;
end;

//Or

function CompStrWArr(str: string; strArr: array of string): boolean;
var
i: Integer;
begin
for i := 0 to High(strArr) do
if str = strArr[i] then
begin
Result := True;
Exit;
end;
end;


Narcle

2008-10-27 06:50:36

I have an inventory array in Nautilus that records all the uptexts of all the items and records their stack amount etc.

I like the create DTM method, I might actually look at this more closely when I'm not sleepy… /yawn

Yeah, CompStrWArr is wrong, but that isn't the focus of this thread. :p

Nava2

2008-10-27 08:28:42

I already told him but he, in true mixster style, is too lazy to update it :)