SRL Archive - SRL Archives

WaitUptext() and WaitOption()


marpis

2009-06-18 20:19:52

i hate useless 100ms waiting, like
mouse(x, y, 0, 0, false);
wait(100+random(50));
if ChooseOption('lol') then …

this is much better. alot can happen in 100ms and these functions also tolerate lagspikes

function WaitUptext(s: string; maxtime: integer): boolean;
var
t: integer;
begin
t := getsystemtime;
repeat
result := IsUptext(s);
wait(1+random(10));
until(result or ((getsystemtime - t) > maxtime));
end;

function WaitOption(s: string; maxtime:integer): boolean;
var
t: integer;
begin
t := getsystemtime;
repeat
result := OptionsExist([s]);
wait(1+random(10));
until(result or ((getsystemtime - t) > maxtime));
ChooseOption(s);
end;

EDIT: added randomness to waits

ShowerThoughts

2009-06-18 20:33:33

Add the random in the loops and they are the same as mine.

Nava2

2009-06-20 21:19:44

Zeph and I were just talking about this…

What does everyone else think?

ShowerThoughts

2009-06-20 21:28:06

Ehm, it is maybe to fast… there must be added randomness.
+ some wait after it, if wanted.

Cazax

2009-06-20 21:29:07

I agree, most of scripts have this included and adding them to SRL would shorten lines.

Nava2

2009-06-20 21:40:27

function UpTextM(s: TStringArray): Boolean;
var
c: Integer;
begin
c := GetTimeRunning + 3000;
while (c > GetTimeRunning) and not Result do
begin
Result := IsUpTextMultiCustom(s);
Wait(20 + Random(40));
end;
end;

function UpText(s: String): Boolean;
begin
Result := UpTextM([s]);
end;

Thats what I have.

NCDS

2009-06-20 21:44:39

I agree that every script uses it, but it is so simple. It almost seems useless to add it because everyone would just use their own.
Would be a useful addition though for some.

Claymore

2009-06-20 22:06:19

this was already brought up LOOOOONG ago. There was a function called UTWait.

function UTWait(Maxtime: LongInt; Text: TStringArray): Boolean;
var
Timer: LongInt;
begin
MarkTime(Timer);
while (TimeFromMark(Timer) < (MaxTime + Random(55))) do
begin
if (IsUpTextMultiCustom(Text)) then
begin
Result := True;
Exit;
end;
Wait(75 + Random(25));
end;
Exit;
end;

ShowerThoughts

2009-06-20 22:12:37

They can add the wait in their own script if they want to.

Sir R. M8gic1an

2009-06-20 22:40:10

From: Nava2
Zeph and I were just talking about this…

What does everyone else think?


I am guessing you and Zeph were thinking of including it, and I'd agree with that.

Gj Marpis. Nice use of OptionsExit :) ;)

~RM

Naum

2009-06-20 22:44:04

I agree with Hermen, people suited to the old method might not use this.
Plus it has been suggested before and people have got round without it.

Sir R. M8gic1an

2009-06-20 22:58:04

From: NaumanAkhlaQ
I agree with Hermen, people suited to the old method might not use this.
Plus it has been suggested before and people have got round without it.


This way is the best way. Much of srl is this way. just recently i changed functios in srl to use this way. this is the most efficient way. If my hunch is correct, this will be in very, very soon.

~RM

Naum

2009-06-20 23:37:29

From: Rasta Magician
This way is the best way. Much of ssrl is this way. just recently i changed functios in srl to use this way. this is the most efficient way. If my hunch is correct, this will be in very, very soon.

~RM

Much of ssrl is this way?

Of course I am entitled to an opinion. Tbh, I do not mind as I won't use it much. Your hunchs are always correct (mainly because you'r a dev :p)

Sir R. M8gic1an

2009-06-20 23:40:49

From: NaumanAkhlaQ
Much of ssrl is this way?

Of course I am entitled to an opinion. Tbh, I do not mind as I won't use it much. Your hunchs are always correct (mainly because you'r a dev :p)


i actually meant srl, as you can see by the context.

~RM

Naum

2009-06-20 23:47:54

From: Rasta Magician
i actually meant srl, as you can see by the context.

~RM


I actually thought you didn't, honestly if you want to commit this then at least add a few waits after other procedures such as click text - as this helps whilst in NPC chat.

Claymore

2009-06-21 00:35:36

we should just let people put this function into their scripts. This isn't even crucial at all… its just to save us some few extra lines.

Nava2

2009-06-21 09:13:05

From: Deathscytex
we should just let people put this function into their scripts. This isn't even crucial at all… its just to save us some few extra lines.


How isnt it crucial….

Aldo, if so many people have it in their scripts, isn't that more of a reason to include it in srl?

Da 0wner

2009-06-21 09:16:43

I believe this should be added to SRL :).

Simtoon

2009-06-21 10:10:33

this is very good.

Daniel

2009-06-21 13:05:35

I don't think this'll work properly. You'd only need to cal IsUpText once instead of the repeat.

So, if you DO include this, then you move the mouse to a specified coordinate, then call this and it can't find the uptext it'll just keep repeating until the the time has reached MaxWait. So, basically there's no point.. Unless you're trying to click a monster and that then moves to your mouse cursor, which i doubt :p

ShowerThoughts

2009-06-21 13:35:22

The joke is like everyone has made this once or not, but it is very efficient; the only problem is who gets the credit??? :p.

;)

marpis

2009-06-21 14:03:49

[QUOTE=Dan's The Man;589338]I don't think this'll work properly. You'd only need to cal IsUpText once instead of the repeat.

So, if you DO include this, then you move the mouse to a specified coordinate, then call this and it can't find the uptext it'll just keep repeating until the the time has reached MaxWait. So, basically there's no point.. Unless you're trying to click a monster and that then moves to your mouse cursor, which i doubt :p

wtf?

yes, it will repeat it for 70ms when you set maxtime to 70?
when you put it like this:

MMouse(x, y, 0, 0);
wait(70);
If IsUptext() then...
it always waits the 70ms, my function waits a maximum of 70ms.
so if the uptext appears in 10ms, it will not wait longer than 10ms.

From: Hermen
The joke is like everyone has made this once or not, but it is very efficient; the only problem is who gets the credit??? :p.

;)

ME ME ME!!!
heh not rly, just put credits to SRL team? ^^

Daniel

2009-06-21 14:58:41

From: marpis
wtf?

yes, it will repeat it for 70ms when you set maxtime to 70?
when you put it like this:

MMouse(x, y, 0, 0);
wait(70);
If IsUptext() then...
it always waits the 70ms, my function waits a maximum of 70ms.
so if the uptext appears in 10ms, it will not wait longer than 10ms.


Wouldn't it appear straight away when you move the mouse to the location though?

Sir R. M8gic1an

2009-06-21 16:15:19

[QUOTE=Dan's The Man;589374]Wouldn't it appear straight away when you move the mouse to the location though?

this is what you usually do:


MMouse(x, y, 3, 3);
wait(300+random(50));
GetMousePos(x, y);
if IsUpText('lol') then
Mouse(x, y, 0, 0, true);

this is what you'd do now:

MMouse(x, y, 3, 3);
if WaitUpText('lol', 300) then
begin
wait(Random(50));
GetMousePos(x,y);
Mouse(x, y, 0, 0);
end;

the Difference is that instead of waiting 300 ms to check for uptext, you wait in cycles, meaning that as soon as it is up you mvoe on.

~RM

Da 0wner

2009-06-21 18:39:49

You are missing the maxtime parameter :p.

Naike

2009-06-22 01:22:21

Should be added, but It should be made into Multi functions.. Like this


Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := OptionsExist(S, False);
Wait(10+Random(10));
until(Result)or(GetSystemTime > T);
Result := ChooseOptionMulti(S);
end;


Function WaitOption(S: String; Time: Integer): Boolean;
begin
Result := WaitOptionMulti([S], Time);
end;


Function WaitUptextMulti(S: TStringArray; Time: integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := IsUpTextMultiCustom(S);
Wait(10+Random(10));
until(Result)or(GetSystemTime > T);
end;


Function WaitUptext(S: String; Time: Integer): Boolean;
begin
Result := WaitUptextMulti([S], Time);
end;

Otherwise the "Multi" functions will just end up being added later on..

Simtoon

2009-06-22 12:16:26

N1ke is a beast.

Sir R. M8gic1an

2009-06-22 13:18:50


//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Waiting Routines --//
//-----------------------------------------------------------------//
// * Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean; // By Marpis & N1ke! & Rasta Magician
// * Function WaitOption(S: String; Time: Integer): Boolean; // By Marpis edited by N1ke!
// * Function WaitUptextMulti(S: TStringArray; Time: integer): Boolean; // By Marpis & N1ke!
// * Function WaitUptext(S: String; Time: Integer): Boolean; // By Marpis edited by N1ke!
// * Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean; // By Rasta Magician
// * Function WaitColorCount(x1, y1, x2, y2, Color, Tol, MinCount, MaxCount, MaxTime: integer):boolean; // By Rasta Magician


{*******************************************************************************
Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis & N1ke! & Rasta Magician
Description: Waits for a TStringArray of options and selects one of them
*******************************************************************************}
Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T, a, b, c: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := OptionsExist(S, True);
Wait(10+Random(10));
until(Result)or(GetSystemTime > T);
//from Mouse, but to be faster so we don't call GetMousePos twice.
Wait(60 + Random(30));
GetMousePos(b, c);
HoldMouse(b, c, left);
repeat
Wait(20 + Random(30));
a := a + 1;
until (a > 4);
GetMousePos(b, c);
ReleaseMouse(b, c, left);
Wait(100 + Random(100));
end;


{*******************************************************************************
Function WaitOption(S: String; Time: Integer): Boolean;
By: Marpis edited by N1ke!
Description: Waits for an Option and selects it
*******************************************************************************}
Function WaitOption(S: String; Time: Integer): Boolean;
begin
Result := WaitOptionMulti([S], Time);
end;

{*******************************************************************************
Function WaitUptextMulti(S: TStringArray; Time: integer): Boolean;
By: Marpis & N1ke!
Description: Waits for a TStringArray of UpText, returns true if found
*******************************************************************************}
Function WaitUptextMulti(S: TStringArray; Time: integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := IsUpTextMultiCustom(S);
Wait(10+Random(10));
until(Result)or(GetSystemTime > T);
end;

{*******************************************************************************
Function WaitUptext(S: String; Time: Integer): Boolean;
By: Marpis edited by N1ke!
Description: Waits for an UpText, returns true if found
*******************************************************************************}
Function WaitUptext(S: String; Time: Integer): Boolean;
begin
Result := WaitUptextMulti([S], Time);
end;

{*******************************************************************************
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
By: Rasta Magician
Description: Waits for a color at (x, y) with tolerance Tol, returns true if found
*******************************************************************************}
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
var
Time: integer;
begin
Time := GetSystemTime;
while GetSystemTime - Time < MaxTime do
if SimilarColors(GetColor(x, y), Color, Tol) then
begin
Result := true;
exit;
end;
end;

{*******************************************************************************
Function WaitColorCount(x1, y1, x2, y2, Color, Tol, MinCount, MaxCount, MaxTime: integer):boolean;
By: Rasta Magician
Description: Waits Color count in box (x1, y1, x2, y2) with Tol
*******************************************************************************}
Function WaitColorCount(x1, y1, x2, y2, Color, Tol, MinCount, MaxCount, MaxTime: integer):boolean;
var
Time: integer;
TPA: TPointArray;
begin
Time := GetSystemTime;
while GetSystemTime - Time < MaxTime do
if FindColorsTolerance(TPA, Color, x1, y1, x2, y2, Tol) then
if InRange(Length(TPA), MinCount, MaxCount) then
begin
Result := true;
exit;
end;
end;

Waiting.scar being discussed in devs.

~RM

marpis

2009-06-22 18:12:36

From: Rasta Magician

Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T, a, b, c: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := OptionsExist(S, True);
Wait(10+Random(10));
until(Result)or(GetSystemTime > T);
//from Mouse, but to be faster so we don't call GetMousePos twice.
Wait(60 + Random(30));
GetMousePos(b, c);
HoldMouse(b, c, left);
repeat
Wait(20 + Random(30));
a := a + 1;
until (a > 4);
GetMousePos(b, c);
ReleaseMouse(b, c, left);
Wait(100 + Random(100));
end;


you forgot "if result then" ?

why not just use chooseoption? you should use chooseoption even if the option was not found, because chooseoption moves the mouse away making the optionbox disappear, and that is what we want, no?

Sir R. M8gic1an

2009-06-22 18:46:27

From: marpis
you forgot "if result then" ?

why not just use chooseoption? you should use chooseoption even if the option was not found, because chooseoption moves the mouse away making the optionbox disappear, and that is what we want, no?


I ended up re-writting it, because OptionsExist and ChooseOption are basically the same thing except for the clicking, but the detection is all the same.

so it just simply chooses option


Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis & N1ke! & Rasta Magician
Description: Waits for a TStringArray of options and selects one of them
*******************************************************************************}
Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T, a, b, c: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := ChooseOptionMultiEx(S, 'all', ClickLeft);
Wait(30+Random(10));
until(Result)or(GetSystemTime > T)
end;

~RM

marpis

2009-06-22 23:13:53

From: Rasta Magician
I ended up re-writting it, because OptionsExist and ChooseOption are basically the same thing except for the clicking, but the detection is all the same.

so it just simply chooses option


Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis & N1ke! & Rasta Magician
Description: Waits for a TStringArray of options and selects one of them
*******************************************************************************}
Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T, a, b, c: Integer;
begin
T := GetSystemTime + Time;
repeat
Result := ChooseOptionMultiEx(S, 'all', ClickLeft);
Wait(30+Random(10));
until(Result)or(GetSystemTime > T)
end;

~RM


doesn't ChooseOptionMultiEx move the mouse away closing the optionbox if the option wasn't found? because ChooseOption does. If so, then that will check only once if the option is there, then move the mouse away and continue the loop.

plus, no use for 30+random(10), it could as well be 1+random(10) because the randomness will be the same but less waiting :)

Sir R. M8gic1an

2009-06-22 23:22:25

From: marpis
doesn't ChooseOptionMultiEx move the mouse away closing the optionbox if the option wasn't found? because ChooseOption does. If so, then that will check only once if the option is there, then move the mouse away and continue the loop.

plus, no use for 30+random(10), it could as well be 1+random(10) because the randomness will be the same but less waiting :)


if it was 1+random(10) it would call random(10) more often than if it were 30 + random(10), therefore making a difference :p

Also, i've been using WaitChooseOption, so i know it works. if the box is not open then it won't search for the option, exiting immediately, so it'll continue if the loop until the box is open, and only then will it actually search for the text. if the text is not there then it is not an option. Also, just fyi, chooseOption calls ChooseOptionsMultiEx ;)

also, added to svn in timing.scar , check tut island for the tutorial in the new "Newly Added to SRL" section

~RM