Runaway
08-24-2012, 04:08 PM
Just a compilation of some functions I've found useful.
WaitStatus
procedure WaitStatus(Time: Integer; Loop: Boolean);
var
t: Integer;
Ticker: String;
begin
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Ticker := MSToTime(Time - TimeFromMark(t), Time_Abbrev);
Status('Time remaining: '+ Ticker);
if not Loop then
Exit;
Wait(500);
end;
end;
WaitMoving
procedure WaitMoving(Time: Integer);
var
t: Integer;
begin
MarkTime(t);
while (IsMoving or FlagPresent) and (TimeFromMark(t) < Time) do
Wait(50+Random(100));
end;
WaitMessage & WaitMessageMulti
function WaitMessage(Time: Integer; Text: String; Line: TIntegerArray): Boolean;
var
hLine, t, i: Integer;
begin
Result := False;
hLine := High(Line);
FixChat;
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
for i := 0 to hLine do
begin
Result := (Pos(Text, GetChatBoxText(Line[i], clMessage)) <> 0);
if Result then
Exit;
end;
Wait(25);
end;
end;
function WaitMessageMulti(Time: Integer; Text: TStringArray; Line: TIntegerArray): Boolean;
var
EachWait, hText, t, i: Integer;
begin
Result := False;
hText := High(Text);
EachWait := Round((Time / 5) / (hText + 1));
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
for i := 0 to hText do
begin
Result := WaitMessage(EachWait, Text[i], Line);
if Result then
Exit;
end;
end;
end;
WaitPixelShift & WaitPixelShiftEx
function WaitPixelShift(Time, Min, Tol: Integer; Box: TBox): Integer;
var
Color: array[0..1] of TIntegerArray;
hColor, Res, t, i: Integer;
begin
Result := 0;
Color[0] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
hColor := High(Color[0]);
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
Color[1] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
Res := 0;
for i := 0 to hColor do
begin
if SimilarColors(Color[0][i], Color[1][i], Tol) then
Continue;
Inc(Res);
end;
if (Res > Min) then
begin
Result := Res;
Exit;
end;
end;
end;
function WaitPixelShiftEx(var Pixels: TIntegerArray; Time, Min, Tol: Integer; Box: TBox): Integer;
var
Color: array[0..1] of TIntegerArray;
hColor, Res, t, i: Integer;
begin
Result := 0;
if (Length(Pixels) = 0) then
begin
Color[0] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
Pixels := Color[0];
end else
Color[0] := Pixels;
hColor := High(Color[0]);
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
Color[1] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
Res := 0;
for i := 0 to hColor do
begin
if SimilarColors(Color[0][i], Color[1][i], Tol) then
Continue;
Inc(Res);
end;
if (Res > Min) then
begin
Result := Res;
Exit;
end;
end;
end;
WaitXPChange & WaitXPChangeEx
function WaitXPChange(Time, Min: Integer): Integer;
var
XP: array[0..1] of Integer;
Diff, t: Integer;
begin
Result := 0;
ToggleXPBar(True);
XP[0] := GetXPBarTotal;
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
XP[1] := GetXPBarTotal;
Diff := XP[1] - XP[0];
if (Diff >= Min) then
begin
Result := Diff;
Exit;
end;
end;
end;
function WaitXPChangeEx(var StartXP: Integer; Time, Min: Integer): Integer;
var
XP: array[0..1] of Integer;
Diff, t: Integer;
begin
Result := 0;
ToggleXPBar(True);
if (StartXP = 0) then
begin
XP[0] := GetXPBarTotal;
StartXP := XP[0];
end else
XP[0] := StartXP;
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
XP[1] := GetXPBarTotal;
Diff := XP[1] - XP[0];
if (Diff >= Min) then
begin
Result := Diff;
Exit;
end;
end;
end;
I'll probably end up adding more in the future. :)
WaitStatus
procedure WaitStatus(Time: Integer; Loop: Boolean);
var
t: Integer;
Ticker: String;
begin
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Ticker := MSToTime(Time - TimeFromMark(t), Time_Abbrev);
Status('Time remaining: '+ Ticker);
if not Loop then
Exit;
Wait(500);
end;
end;
WaitMoving
procedure WaitMoving(Time: Integer);
var
t: Integer;
begin
MarkTime(t);
while (IsMoving or FlagPresent) and (TimeFromMark(t) < Time) do
Wait(50+Random(100));
end;
WaitMessage & WaitMessageMulti
function WaitMessage(Time: Integer; Text: String; Line: TIntegerArray): Boolean;
var
hLine, t, i: Integer;
begin
Result := False;
hLine := High(Line);
FixChat;
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
for i := 0 to hLine do
begin
Result := (Pos(Text, GetChatBoxText(Line[i], clMessage)) <> 0);
if Result then
Exit;
end;
Wait(25);
end;
end;
function WaitMessageMulti(Time: Integer; Text: TStringArray; Line: TIntegerArray): Boolean;
var
EachWait, hText, t, i: Integer;
begin
Result := False;
hText := High(Text);
EachWait := Round((Time / 5) / (hText + 1));
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
for i := 0 to hText do
begin
Result := WaitMessage(EachWait, Text[i], Line);
if Result then
Exit;
end;
end;
end;
WaitPixelShift & WaitPixelShiftEx
function WaitPixelShift(Time, Min, Tol: Integer; Box: TBox): Integer;
var
Color: array[0..1] of TIntegerArray;
hColor, Res, t, i: Integer;
begin
Result := 0;
Color[0] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
hColor := High(Color[0]);
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
Color[1] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
Res := 0;
for i := 0 to hColor do
begin
if SimilarColors(Color[0][i], Color[1][i], Tol) then
Continue;
Inc(Res);
end;
if (Res > Min) then
begin
Result := Res;
Exit;
end;
end;
end;
function WaitPixelShiftEx(var Pixels: TIntegerArray; Time, Min, Tol: Integer; Box: TBox): Integer;
var
Color: array[0..1] of TIntegerArray;
hColor, Res, t, i: Integer;
begin
Result := 0;
if (Length(Pixels) = 0) then
begin
Color[0] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
Pixels := Color[0];
end else
Color[0] := Pixels;
hColor := High(Color[0]);
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
Color[1] := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
Res := 0;
for i := 0 to hColor do
begin
if SimilarColors(Color[0][i], Color[1][i], Tol) then
Continue;
Inc(Res);
end;
if (Res > Min) then
begin
Result := Res;
Exit;
end;
end;
end;
WaitXPChange & WaitXPChangeEx
function WaitXPChange(Time, Min: Integer): Integer;
var
XP: array[0..1] of Integer;
Diff, t: Integer;
begin
Result := 0;
ToggleXPBar(True);
XP[0] := GetXPBarTotal;
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
XP[1] := GetXPBarTotal;
Diff := XP[1] - XP[0];
if (Diff >= Min) then
begin
Result := Diff;
Exit;
end;
end;
end;
function WaitXPChangeEx(var StartXP: Integer; Time, Min: Integer): Integer;
var
XP: array[0..1] of Integer;
Diff, t: Integer;
begin
Result := 0;
ToggleXPBar(True);
if (StartXP = 0) then
begin
XP[0] := GetXPBarTotal;
StartXP := XP[0];
end else
XP[0] := StartXP;
MarkTime(t);
while (TimeFromMark(t) < Time) do
begin
Wait(100);
XP[1] := GetXPBarTotal;
Diff := XP[1] - XP[0];
if (Diff >= Min) then
begin
Result := Diff;
Exit;
end;
end;
end;
I'll probably end up adding more in the future. :)