PDA

View Full Version : Some Wait Functions



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. :)

Olly
08-24-2012, 05:12 PM
Nice functions as always :P. Should make a function that compares a old bitmap to a new one (in a set box) and waits for a jump for more than x. Think of if you successfully started cutting a tree you could grab a small bitmap around the middletpa and then wait for a jump(because over time the rs screen moves and slowly the pixel shift will add up) and when the jump is > 1000 you know the tree has been cut down.

Runaway
08-24-2012, 05:28 PM
Nice functions as always :P. Should make a function that compares a old bitmap to a new one (in a set box) and waits for a jump for more than x. Think of if you successfully started cutting a tree you could grab a small bitmap around the middletpa and then wait for a jump(because over time the rs screen moves and slowly the pixel shift will add up) and when the jump is > 1000 you know the tree has been cut down.

Thanks! Interesting idea... I think the current PixelShift functions use bitmaps. I actually don't know if there's much of a difference between the two, but I'm going to look into it :)

Olly
08-24-2012, 05:35 PM
Thanks! Interesting idea... I think the current PixelShift functions use bitmaps. I actually don't know if there's much of a difference between the two, but I'm going to look into it :)

Yeah they do, but you cant track a old bitmap without editing and making a new function :P

litoris
08-24-2012, 05:57 PM
WaitXPChange is nice, you wait for XP to change a lot, never thought of making it a function :D

Janilabo
08-24-2012, 07:07 PM
Good job with WaitPixelShift[Ex], I miiiight have some use for those 2 soon (working on some walking stuff in another MMORPG).
Nice little snippets. ;)

Much appreciated!

-Jani

Runaway
08-29-2012, 06:48 AM
I added a few new ones: WaitMoving, WaitMessage and WaitMessageMulti.

Solar
08-29-2012, 08:15 AM
They look great, but I think my favourite one WaitXpChange. Good work.