SRL Archive - SRL Archives

MouseEx


NCDS

2009-06-29 08:43:22

I had assumed it was posted before but when I looked I didn't see it anywhere soo…


{*******************************************************************************
procedure MouseEx(mousex, mousey, ranx, rany: Integer; UpText: String; left: Boolean);
By: Mutant Squirrle, hy71194, and NCDS
Description: Moves mouse, Checks for UpText, Then Click's.
*******************************************************************************}
procedure MouseEx(mousex, mousey, ranx, rany: Integer; UpText: String; left: Boolean);
var
a, b, c: Integer;
begin
MMouse(mousex, mousey, ranx, rany);
Wait(60 + Random(30));
if Pos(UpText, RS_GetUpText) > 0 then
begin
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;
end;

I just use it to eliminate the

MMouse();
if IsUpText() then
Mouse();
that every script has.

All I added is an extra parameter to check the uptext before clicking.

Out of curiosity..do you find this useful?

Sir R. M8gic1an

2009-06-29 11:18:43

meh might as well make it use WaitUpText then. I think it's just too much. you're just trying to skip a couple of lines without a real need or purpose except to skip them.

sounds like RWait(500, 50) instead of wait(500+random(50)); i mean yeah, it makes it faster for you, but not more efficient nor better for srl nor anything very noticeable.

~RM

Coh3n

2009-06-29 20:07:52

I like the idea, and I would certainly use it myself, but I do agree with RM, it's only skipping a couple lines for your own convenience.

NCDS

2009-06-29 23:03:45

From: Rasta Magician
meh might as well make it use WaitUpText then. I think it's just too much. you're just trying to skip a couple of lines without a real need or purpose except to skip them.

sounds like RWait(500, 50) instead of wait(500+random(50)); i mean yeah, it makes it faster for you, but not more efficient nor better for srl nor anything very noticeable.

~RM


Out of curiosity..what is then the difference between FindTextTPA and FindTextTPAEx, or ChooseOptionEx and ChooseOption etc.

It seems like there is an abundance of functions in SRL that do exactly what you say is not necessary to be done.

I agree with what you said, but why, if that is the outlook we are supposed to have, do these other functions that are comparable in the same way, continue to exist in SRL?

Sir R. M8gic1an

2009-06-29 23:24:43

From: NCDS
Out of curiosity..what is then the difference between FindTextTPA and FindTextTPAEx, or ChooseOptionEx and ChooseOption etc.

It seems like there is an abundance of functions in SRL that do exactly what you say is not necessary to be done.

I agree with what you said, but why, if that is the outlook we are supposed to have, do these other functions that are comparable in the same way, continue to exist in SRL?


Indeed, they are comparable. FindTextTPAEx requires you to have 2 vars which you would not need further on, while FindTextTPA declares those vars for you and frees them as soon as it is done instead of you having the vars throughout your whole procedure, increasing efficiency.

And ChooseOptionEx and ChooseOption simplify things for you, and increases readability, and most new scripters would not grasp the concept of have a TStringArray with only one string, especially as arrays are more complicated than simple variables.

Finally, Removing these said functions would break an awful lot of scripts and would make them backwards imcompatible, which is the same reason for which we have some routines with just one line, so we don't break scripts.

Last but not least, this would not make your script anymore efficient, just a bit shorter, and maybe you weren't around before SRL 4, but i wouldn't like to go back to SRL 3.xx where we had OpenBank, OpenBank2, OpenBank3, OpenBankQuiet, OpenBankFast and OpenBankGlass, if you understand what i mean. Each of them having a slight difference between themselves.

However, if another developer finds this to be a good addition they will add it, but i won't.

~RM

NCDS

2009-06-29 23:40:22

From: Rasta Magician
Indeed, they are comparable. FindTextTPAEx requires you to have 2 vars which you would not need further on, while FindTextTPA declares those vars for you and frees them as soon as it is done instead of you having the vars throughout your whole procedure, increasing efficiency.

And ChooseOptionEx and ChooseOption simplify things for you, and increases readability, and most new scripters would not grasp the concept of have a TStringArray with only one string, especially as arrays are more complicated than simple variables.

Finally, Removing these said functions would break an awful lot of scripts and would make them backwards imcompatible, which is the same reason for which we have some routines with just one line, so we don't break scripts.

Last but not least, this would not make your script anymore efficient, just a bit shorter, and maybe you weren't around before SRL 4, but i wouldn't like to go back to SRL 3.xx where we had OpenBank, OpenBank2, OpenBank3, OpenBankQuiet, OpenBankFast and OpenBankGlass, if you understand what i mean. Each of them having a slight difference between themselves.

However, if another developer finds this to be a good addition they will add it, but i won't.

~RM


No, I agree with you. Everything you said make's sense and is backed up by a valid point.

I just enjoy these little "Q and A" discussions to make sure I am on the same page as everyone else.

tbh I didn't post this with the intention of it being added to SRL, more so to just share ideas with people :)

Awkwardsaw

2009-06-30 00:10:06

honestly, i would use it if it was added :P any thing to shorten up a script by just a few lines, and save a little bit of time is well worth it right?

NCDS

2009-06-30 00:31:28

From: akwardsaw
honestly, i would use it if it was added :P any thing to shorten up a script by just a few lines, and save a little bit of time is well worth it right?


My thought's as well, but RM does have a good point.

Awkwardsaw

2009-07-01 08:56:43

From: NCDS
My thought's as well, but RM does have a good point.


yes, he does :P i just like being lazy when i just want to finish a script(bad habbit i know):p

Da 0wner

2009-07-05 16:13:40

From: Rasta Magician
Indeed, they are comparable. FindTextTPAEx requires you to have 2 vars which you would not need further on, while FindTextTPA declares those vars for you and frees them as soon as it is done instead of you having the vars throughout your whole procedure, increasing efficiency.

And ChooseOptionEx and ChooseOption simplify things for you, and increases readability, and most new scripters would not grasp the concept of have a TStringArray with only one string, especially as arrays are more complicated than simple variables.

Finally, Removing these said functions would break an awful lot of scripts and would make them backwards imcompatible, which is the same reason for which we have some routines with just one line, so we don't break scripts.

Last but not least, this would not make your script anymore efficient, just a bit shorter, and maybe you weren't around before SRL 4, but i wouldn't like to go back to SRL 3.xx where we had OpenBank, OpenBank2, OpenBank3, OpenBankQuiet, OpenBankFast and OpenBankGlass, if you understand what i mean. Each of them having a slight difference between themselves.

However, if another developer finds this to be a good addition they will add it, but i won't.

~RM


I was also told by somebody that ChooseOptionEx was faster.

Richard

2009-07-05 17:03:24

From: Da 0wner
I was also told by somebody that ChooseOptionEx was faster.


Well, look at it this way, when you use ChooseOption, it has to access ChooseOptionEx, like this:

Function called –> ChooseOption –> ChooseOptionEx

But when you use ChooseOptionEx, its gets rid of the ChooseOption:

Function called –> ChooseOptionEx

And if you really wanted efficiency, then you could have your own function of which the colours and everything were set to your liking, saving accessing the include.

Da 0wner

2009-07-05 17:11:16

ChooseOption wasn't just ChooseOptionEx last time I saw it. They modified it.

ChooseOption was a whole different procedure.

Richard

2009-07-05 17:19:15

{*******************************************************************************
function ChooseOptionMultiEx(Texts: TStringArray; TextType: String; Action: fnct_ActionOptions): Boolean;
By: Wizzup?, Nava2, and modified by N1ke!
Description: Finds Popup menu, then clicks on it.
Will look for the first string first and so on.
It will search for the Text Type you input valid arguments are
'action', 'player': The white text
'npc': The yellow text
'object': The cyan text
'all': Searches for all colors of text.
Will default to 'all'.
*******************************************************************************}
function ChooseOptionMultiEx(Texts: TStringArray; TextType: String; Action: fnct_ActionOptions): Boolean;
var
B, T: TBox;
TPA, TextTPA: TPointArray;
aTPA: T2DPointArray;
I, C, H, HH, ii, L: Integer;
P: TPoint;
Occurances: array [0..4] of TPointArray;
Colors: TIntegerArray;
begin
Result := False;
GetClientDimensions(B.X2, B.Y2);
B.X1 := 0;
B.Y1 := 0;
FindColorsTolerance(TPA, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
If Length(TPA) < 10 Then
Exit;
B.X2 := 0;
B.Y2 := 0;

P := TPA[0];
H := High(TPA);
Dec(H);
For I := 0 To H Do
If TPA[i].X = TPA[I+1].X - 1 Then
Begin
If C > 5 Then
Begin
B.X1 := P.X;
B.Y1 := P.Y;
Break;
End Else
C := C + 1;
End
Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;
InvertTPA(TPA);
C := 0;
P := TPA[0];
H := High(TPA);
Dec(H);
For I := 0 To H Do
If TPA[i].X = TPA[I+1].X + 1 Then
Begin
If C > 5 Then
Begin
B.X2 := P.X;
B.Y2 := P.Y;
Break;
End Else
C := C + 1;
End Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;

TPA := [];
Colors := [16777215, 4231423, 2070783, 65535, 16776960];
case LowerCase(TextType) of
'action', 'player': FindColorsTolerance(Occurances[0], Colors[0], B.x1, B.y1, B.x2, B.y2, 3);
'item' : begin
FindColorsTolerance(Occurances[1], Colors[1], B.x1, B.y1, B.x2, B.y2, 3);
FindColorsTolerance(Occurances[2], Colors[2], B.x1, B.y1, B.x2, B.y2, 3);
end;
'npc' : FindColorsTolerance(Occurances[3], Colors[3], B.x1, B.y1, B.x2, B.y2, 3);
'object': FindColorsTolerance(Occurances[4], Colors[4], B.x1, B.y1, B.x2, B.y2, 3);
else
begin
FindColorsTolerance(Occurances[0], 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(Occurances[1], clBlack, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(Occurances);

ClearDoubleTPA(TPA);
TPA := ReturnPointsNotInTPA(TPA, B);
end;
end;
if High(TPA) < 1 then TPA := MergeATPA(Occurances);
aTPA := SplitTPAEx(TPA, 7, 1);
SortATPAFromFirstPoint(aTPA, Point(B.x1, B.y1));

H := High(Texts);
L := High(aTPA);

For I :=0 To H do
begin
TextTPA := LoadTextTPA(Texts[I], UpChars, HH);
for ii := 0 to L do
If FindTextTPAInTPA(HH, TextTPA, aTPA[ii], TPA) Then
Begin
T := GetTPABounds(TPA);
Result := True;
Case Action of
ClickLeft: MouseBox(B.x1 + 5, T.y1 + 2, B.x2 - 5, T.y2 - 2, 1);
Move: MouseBox(B.x1 + 5, T.y1 + 2, B.x2 - 5, T.y2 - 2, 3);
Nothing: begin end;
else
srl_warn('ChooseOptionMultiEx', 'ClickRight not a valid click for RS menus!', warn_AllVersions);
end;
Exit;
End;
end;

MMouse(B.X1 - 50, B.Y1 - 50, 40, B.Y2 - B.Y1);
Wait(200 + Random(100));
end;

{*******************************************************************************
function ChooseOptionMulti(Text: TStringArray): Boolean;
By: Wizzup? modified by N1ke!
Description: Finds Popup menu, then clicks on it.
Will look for the first string first and so on.
*******************************************************************************}
function ChooseOptionMulti(Txt: TStringArray): Boolean;
begin
Result := ChooseOptionMultiEx(Txt, 'All', ClickLeft);
end;

{*******************************************************************************
function ChooseOptionEx(Txt, TextType: string): Boolean;
By: Wizzup?
Description: Finds an option in a popup menu, then clicks on it. Searches for
TextType. See ChooseOptionMultiEx for valid options.
Default is 'all'.
*******************************************************************************}
function ChooseOptionEx(Txt, TextType: string): Boolean;
begin
Result := ChooseOptionMultiEx([Txt], TextType, ClickLeft);
end;

{*******************************************************************************
function ChooseOption(txt: String): Boolean;
By: Wizzup?
Description: Finds an option in a popup menu, then clicks on it.
*******************************************************************************}
function ChooseOption(Txt: String): Boolean;
begin
Result := ChooseOptionMultiEx([Txt], 'All', ClickLeft);
end;

Its all based around ChooseOptionMultiEx

bugger0001

2009-07-09 23:23:34

Well, ChooseOption uses 'all' as TextType where instead you could speed things up by using ChooseOptionEx with a specific TextType ;)

For example I use in my Fally smelter ChooseOptionMultiEx with 'action' to withdraw ores from bank. It's almost a second faster for me…

EDIT: [OnTopic] I like the idea, but I don't think it's really something that's really needed…[/OnTopic]

The Little

2009-07-09 23:42:49

We're getting a little of topic XD?

Anyway, I think its a great function, yes it is just skipping a couple of lines, but how many times do you use that in a script? Well I do quite a lot…