SCAR Code:
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');
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;
{ benchmark for five 1000 runs in a row
DTMFromInv works at 1.375ms
DTMFromInv works at 1.422ms
DTMFromInv works at 1.5ms
DTMFromInv works at 1.515ms
DTMFromInv works at 1.516ms
}
function CompStrWArr(str: string; strArr: array of string): boolean;
var
i: Integer;
begin
for i := 0 to High(strArr) do
begin
Result := str = strArr[i];
if(Result)then
Break;
end;
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;
The top two functions are required for SmartDrop to work. What it does is take in 2 arrays - an integer and string - which store information about DTM's it makes. The next TStringArray stores all of the UpText checks you want to use to check then the last boolean is whether you want to drop matched items or keep matched items.
The function works by first comparing the item box against all DTM's it has pre-stored, though first checks if the DTM string for that matches one of the inputted strings. If none of them match, then it moves to the item and compares all of the inputted strings against the UpText and if it matches, it will then make a new DTM for it and add it onto the previous list of DTM's. Not only that, but it also drops in a more human fashion by going from checking items 1,2,3,4 then checking 8,7,6,5 which means it goes from right to left, down one, right to left and continues, though it does randomly decide which direction to go in so can go 1,2,3,4 or 4,3,2,1 
This is a second draft function (first draft was the initial design with this one being tested to make sure it works) so hasn't got many failsafes and I really am just posting this for more input into it