PDA

View Full Version : More functions



Cazax
04-19-2008, 07:13 PM
I made more functions:

function CountItemsDtm2(DtmName : Integer): Integer;
var
Slots : TBoxArray;
i,x,y : Integer;
begin
SetLength(Slots, 0);
for i := 0 to 27 do
begin
SetLength(Slots, Length(Slots) + 1);
Slots[i] := InvBox(i + 1);
if FindDTM(DtmName, x, y, Slots[i].X1, Slots[i].Y1, Slots[i].X2, Slots[i].Y2) then
Result := Result + 1;
end;
end;
function CountItemsBmp2(BmpName,Tol : Integer): Integer;
var
Slots : TBoxArray;
i,x,y : Integer;
begin
SetLength(Slots, 0);
for i := 0 to 27 do
begin
SetLength(Slots, Length(Slots) + 1);
Slots[i] := InvBox(i + 1);
if FindBitmapToleranceIn(BmpName, x, y, Slots[i].X1, Slots[i].Y1, Slots[i].X2, Slots[i].Y2, Tol) then
Result := Result + 1;
end;
end;
They are the same as CountItemsDtm and CountItemsBmp but mine counts them only at the inventory and they are 20-50 ms faster than SRL functions.

function FindGrassColor: Integer;
var
R,G,B,TestColor,i,C2 : Integer;
H,S,L,X,Y,Z : Extended;
TPA : TPointArray;
C1 : TIntegerArray;
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3179133, MMX1, MMY1, MMX2, MMY2, 60);
C1 := GetColors(TPA);
C2 := High(C1);
for i := 0 to C2 do
begin
if RS_OnMinimap(TPA[i].X, TPA[i].Y) then
begin
TestColor := GetColor(TPA[i].X, TPA[i].Y);
if SimilarColors(TestColor, 3179133, 50) then
begin
ColorToRGB(TestColor, R, G, B);
ColorToHSL(TestColor, H, S, L);
ColorToXYZ(TestColor, X, Y, Z);
if InRange(R - G, -20, 10) then
if InRange(R - B, 62, 92) then
if InRange(G - B, 67, 97) then
if InRange(Round(S) - Round(H), 13, 43) then
if InRange(Round(L) - Round(H), 2, 32) then
if InRange(Round(S) - Round(L), -4, 26) then
if InRange(Round(X) - Round(Y), -19, 11) then
if InRange(Round(Y) - Round(Z), 0, 30) then
if SimilarColors(GetColor(TPA[i].X + 2, TPA[i].Y + 2), TestColor, 40) then
if SimilarColors(GetColor(TPA[i].X + 1, TPA[i].Y + 1), TestColor, 40) then
begin
Writeln('GrassColor = '+Inttostr(TestColor));
Result := TestColor;
Exit;
end;
end;
end;
end;
Writeln('Couldnt find Grass Color!');
Result := 0;
end;
Will find the nearest grass color and supports any grass color ;) .


function BoxArrtoPointArr(var ArrB : TBoxArray): TpointArray;
var
ArrT : Integer;
begin
SetLength(Result, 0);
for ArrT := 0 to High(ArrB) do
begin
SetLength(Result, Length(Result) + 1);
Result[ArrT].X := ArrB[ArrT].X1 + ArrB[ArrT].Y1 div 2;
Result[ArrT].Y := ArrB[ArrT].X2 + ArrB[ArrT].Y2 div 2;
end;
end;
function BoxtoPoint(var b : TBox): TPoint;
begin
Result.X := b.X1 + b.Y1 div 2;
Result.Y := b.X2 + b.Y2 div 2;
end;
Simple functions i made. TBoxArray to TPointArray and TBox to TPoint.