SRL Archive - Research & Development Lounge

FT + GetItemCount


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.


{*******************************************************************************
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;

NiCbaZ

2008-12-03 05:45:05

TimeRunningEx, srl already has

ConvertTime(2000, H, Oh, S);

Tootoot222

2008-12-03 08:03:09

then why does SRL have TimeRunning? i just put it here because i was putting the other stuff

marpis

2008-12-03 11:54:25

where do you need timerunningex?
I think ItemAmount would be better name than itemcount, otherwise great job
:)
FindThing is kinda weird, why not just use already existing Find-functions?
Everything is not good to be 1-fits-for-all. I don't actually see an actual need for that function.

Tootoot222

2008-12-03 12:36:37

i didn't call it "ItemAmount" because thats already taken, unless you were being sarcastic

I use FT so that when i have to find a bmp/dtm/mask/color to find in alot of different places, and all i have to do is update 1 string and the Integer of the bmp to make ALL of those change over to what is needed, instead of having to go through EVERY SINGLE place that FindBitmapToleranceIn is called, check if its calling the bmp, and change it to FindDTM

Kyle Undefined

2008-12-03 12:50:16

Using it in my Range Guilder, but you already know that :p I'm going to test it out tonight, I'll tell you how it does.

~Camo