Tootoot222
2008-12-03 03:55:59
These are a bunch of things I have in my MageSmither.
Mostly they have to do with the inventory, but there is a bank one, and a TimeRunningEx.
Mostly they have to do with the inventory, but there is a bank one, and a TimeRunningEx.
{*******************************************************************************
function TimeRunningEx(From: Integer): String;
By: from Phalanx's script/RsN modified by Tootoot222
Description: Returns the time From is in hours, minutes and seconds and milliseconds.
Example: TimeRunningEx(70023) = '1 Minutes, 10 Seconds and 23 Milliseconds.'
*******************************************************************************}
function TimeRunningEx(From: Integer): String;
var
H, M, S, MS: LongInt;
begin
MS:= StrToInt(Right(IntToStr(From), 3));
S:= From div 1000;
M:= S div 60;
H:= M div 60;
Result:= IntToStr(MS) + ' Milliseconds.';
if(not(S = 0)) then
Result := IntToStr(S) + ' Seconds and ' + IntToStr(MS) + ' Milliseconds.';
if(not(M = 0)) then
Result := IntToStr(M) + ' Minutes, ' + IntToStr(S mod (M * 60)) +
' Seconds and ' + IntToStr(MS) + ' Milliseconds.';
if(not(H = 0)) then
Result := IntToStr(H) + ' Hours, ' + IntToStr(M mod (H * 60)) +
' Minutes, ' + IntToStr(S mod (M * 60)) + ' Seconds and ' +
IntToStr(MS) + ' Milliseconds.';
end;
{*******************************************************************************
function FT(var X, Y: Integer; Thing: Integer; ThingType: String;
X1, Y1, X2, Y2: Integer; Tol: array of Integer): Boolean;
By: Tootoot222
Description: Finds "Thing" in x1, y1, x2, y2 and stores the coords in x, y;
*******************************************************************************}
function FT(var X, Y: Integer; Thing: Integer; ThingType: String;
X1, Y1, X2, Y2: Integer; Tol: array of Integer): Boolean;
begin
case Lowercase(ThingType) of
'b', 'bmp', 'bitmap':
Result:= FindBitmapToleranceIn(Thing, X, Y, X1, Y1, X2, Y2, Tol[0]);
'c', 'clr', 'color':
Result:= FindColorTolerance(X, Y, Thing, X1, Y1, X2, Y2, Tol[0]);
'd', 'dtm':
Result:= FindDTM(Thing, X, Y, X1, Y1, X2, Y2);
'm', 'msk', 'bmpmask', 'bitmapmask', 'bmp mask', 'bitmap mask', 'mask':
Result:= FindBitmapMaskTolerance(Thing, X, Y, X1, Y1, X2, Y2, Tol[0], Tol[1]);
end;
end;
{*******************************************************************************
function FindLastInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
By: Tootoot222
Description: Returns the inv slot of the last occurrence of Thing in inventory
Returns 0 if Thing is not found
*******************************************************************************}
function FindLastInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
var
B: TBox;
X, Y: Integer;
begin
for Result:= 28 downto 1 do
begin
B:= InvBox(Result);
if(ExistsItem(Result)) then
if(FT(X, Y, Thing, ThingType, B.X1, B.Y1, B.X2, B.Y2, Tol)) then
Exit;
end;
Result:= 0;
end;
{*******************************************************************************
function FindFirstInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
By: Tootoot222
Description: Returns the inv slot of the first occurrence of Thing in inventory
Returns 0 if Thing is not found
*******************************************************************************}
function FindFirstInv(Thing: Integer; ThingType: String; Tol: TIntegerArray): Integer;
var
B: TBox;
X, Y: Integer;
begin
for Result:= 1 to 28 do
begin
B:= InvBox(Result);
if(ExistsItem(Result)) then
if(FT(X, Y, Thing, ThingType, B.X1, B.Y1, B.X2, B.Y2, Tol)) then
Exit;
end;
Result:= 0;
end;
{*******************************************************************************
function GetItemCount(B: TBox): Integer;
By: Tootoot222
Description: Returns the amount of stacked items in B.
Returns 0 if nothing is there, 1 if non-stackable.
*******************************************************************************}
function GetItemCount(B: TBox): Integer;
var
X, Y, Z, T: Integer;
begin
Result:= 0;
if(FindColor(X, Y, 65536, B.X1, B.Y1, B.X2, B.Y2)) then
begin
Result:= 1;
try
if(FindColor(X, Y, 65535, B.X1, B.Y1, B.X2, B.Y2)) then
if(FindColorSpiral(Z, T, 65535, B.X1, B.Y1, B.X2, B.Y2)) then
Result:= StrToInt(TrimLetters(Replace(Replace(Lowercase(Trim(TrimOthers(GetTextAtEx(Z, Y - 1, 6, StatChars, False, False, 0, 3, 65535, 5, False, tr_AllChars)))), 'k', '000'), 'm', '000000')));
except
end;
end;
end;
{*******************************************************************************
function GetBankItemCount(Index: Integer): Integer;
By: Tootoot222
Description: Returns the amount of stacked items in the bank slot "Index".
Returns 0 if nothing is there, 1 if non-stackable.
*******************************************************************************}
function GetBankItemCount(Index: Integer): Integer;
begin
Result:= GetItemCount(BankIndexToMSBox(Index));
end;
{*******************************************************************************
function GetInvItemCount(Slot: Integer): Integer;
By: Tootoot222
Description: Returns the amount of stacked items in the inv slot "Slot".
Returns 0 if nothing is there, 1 if non-stackable.
*******************************************************************************}
function GetInvItemCount(Slot: Integer): Integer;
begin
Result:= GetItemCount(InvBox(Slot));
end;
{*******************************************************************************
function GetInvCountEx(Thing: Integer; ThingType: String; Tol: TIntegerArray): Variant;
By: Tootoot222
Description: Returns the amount of stacked items matching "Thing".
Returns False if nothing is there, True if non-stackable;
an integer if there is something.
*******************************************************************************}
function GetInvCountEx(Thing: Integer; ThingType: String; Tol: TIntegerArray): Variant;
var
X, Y: Integer;
begin
Result:= False;
X:= FindFirstInv(Thing, ThingType, Tol);
if(not(X < 1)) then
begin
if(ExistsItem(X)) then
begin
Result:= True;
Y:= GetInvItemCount(X);
case Y of
0: Result:= False;
1: Result:= True;
else
Result:= Y;
end;
end;
end;
end;