SRL Archive - SRL Archives

ClickOption - My suggestion for Text.scar


Coh3n

2009-08-16 02:26:55

I posted this a while back, and it slowly died, so I have improved it slightly, and I'm coming back for round two, hoping to get some more feedback. I have noticed that throughout scripts people like to write some code that randomly right/left clicks when clicking an object.

Therefore, I have come up with this function that does just that, but it also checks the uptext of the object, and chooses the correct option.

Because a human isn't going to right/left click 50% percent of the time, this function is set to right click and choose option once every 10 times it is called.

{*******************************************************************************
function ClickOptionEx(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: TStringArray): Boolean;
By: Coh3n
Description: Will left click an object 9/10 times. Will right click an object
and choose the option accociated with ChooseOpt.
Valid arguments for Option: 'right', 'left', 'random'.
i.e ClickOption(x, y, 0, 0, 'random', ['Door'], ['Open']);
*******************************************************************************}

function ClickOptionEx(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: TStringArray): Boolean;
begin
if not InStrArr(Option, ['random', 'right', 'left'], False) then Exit;
Result := WaitUpTextMulti(UpText, 100 + Random(400));
if not Result then SRL_Warn;
if Option = 'random' then
if Random(10) = 1 then
Option := 'right';
else
Option := 'left';
Mouse(x, y, rx, ry, Option = 'left');
if Option = 'right' then
ChooseOptionMulti(ChooseOpt);
end;

{*******************************************************************************
function ClickOption(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: String): Boolean;
By: Coh3n
Description: Works like ClickOptionEx, but uses Strings instead of TStingArray.
*******************************************************************************}

function ClickOption(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: String): Boolean;
begin
Result := ClickOptionEx(x, y, rx, ry, Option, [UpText], [ChooseOpt]);
end;

*Thanks to Sabzi for the ClickOption idea. ;)

I have used it in my current script project to open a gate and climb-over a stile, and both work like a charm. :) I find this function handy to replace a bunch of lines of code such as:

MMouse(x, y, 4, 4);
if IsUpText('illow') then
begin
Writeln('We have found the Willow tree');
case Random(10) of
1: begin
Mouse(x, y, 0, 0, False);
Wait(80 + Random(100));
ChooseOption('hop');
end;
else
Mouse(x, y, 0, 0, True);
end;
With this much shorter code:

MMouse(x, y, 4, 4);
if ClickOption(x, y, 0, 0, 'random', 'illow', 'hop') then
Writeln('Clicked Willow tree!');
See what I mean? ;)

Well, that's it, thanks for reading. :) Please post comments/suggestions.

Laimonas171

2009-08-16 02:34:16

nice! :)
but i dont like

[COLOR=#000000][B]if[/B][/COLOR] ClickOption(x, y, [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#ff00ff]'random'[/COLOR], [[COLOR=#ff00ff]'illow'[/COLOR]], [[COLOR=#ff00ff]'hop'[/COLOR]]) [COLOR=#000000][B]then[/B][/COLOR]
this [] why 'random' don't have these? i think 'illow' and 'hop' shouldn't have it. :) just for easier writing. :) function is nice really. rep+

EDIT: 1st Post. :)

Coh3n

2009-08-16 02:37:25

From: Laimonas171
nice! :)
but i dont like


if ClickOption(x, y, 0, 0, 'random', ['illow'], ['hop']) then
this [] why 'random' don't have these? i think 'illow' and 'hop' shouldn't have it. :) just for easier writing. :) function is nice really. rep+


Thanks! :) And the reason they have the square brackets is because they are both TStringArrays and can be written like ['Willow', 'illow', 'low']. See what I mean? I can make it simpler if need be, but this way there are more options. Also, 'random' doesn't have square brackets because it is just a normal string, not a TStringArray.

Thanks a lot for the quick feedback. :D

Laimonas171

2009-08-16 02:40:07

From: Coh3n
Thanks! :) And the reason they have the square brackets is because they are both TStringArrays and can be written like ['Willow', 'illow', 'low']. See what I mean? I can make it simpler if need be, but this way there are more options. Also, 'random' doesn't have square brackets because it is just a normal string, not a TStringArray.

Thanks a lot for the quick feedback. :D

Oh ['Willow', 'illow', 'low'] this kind i like much more (Y)

Coh3n

2009-08-16 02:42:18

From: Laimonas171
Oh ['Willow', 'illow', 'low'] this kind i like much more (Y)


Well in the function I use WaitUpTextMulti(); I could just as easy use WaitUpText(); and then you would declare it as 'illow'. However, it is more accurate to use a TStringArray. :p

Sabzi

2009-08-16 03:06:10

As far as I can see in SRL, functions like this are the "Ex" versions.
So your function would be the "Ex" version (ClickOptionEx) and what Laimonas171 wanted first would be the simple version.
It would use the Ex version like:
function ClickOption(x, y, rx, ry: Integer; Option, UpText, ChooseOpt: String): Boolean;

begin
Result := ClickOptionEx(x, y, rx, ry, Option, [UpText], [ChooseOpt]);
end;

I am not sure though.

By the way I really like the idea and the function itself.

Coh3n

2009-08-16 03:08:59

From: Sabzi
As far as I can see in SRL, functions like this are the "Ex" versions.
So your function would be the "Ex" version (ClickOptionEx) and what Laimonas171 wanted first would be the simple version.
It would use the Ex version like:
function ClickOption(x, y, rx, ry: Integer; Option, UpText, ChooseOpt: String): Boolean;

begin
Result := ClickOptionEx(x, y, rx, ry, Option, [UpText], [ChooseOpt]);
end;

I am not sure though.

By the way I really like the idea and the function itself.


Hmm thanks very much, and I think you're right about the "Ex" thing. If this actually gets considered for SRL I think I will do that. :p Or you can, and I'll add it to the first post (crediting you of course). ;)

Sabzi

2009-08-16 03:13:05

Credit yourself Coh3n, the function is written. Your is the "Ex". Just rename it if you want and the "simple" would be what I have posted above. There's nothing to really do anything with it, I was just wondering about that :D

Coh3n

2009-08-27 19:16:56

From: Sabzi
Credit yourself Coh3n, the function is written. Your is the "Ex". Just rename it if you want and the "simple" would be what I have posted above. It's nothing to really do with anything I was just wondering about that :D


Haha well alright, but yeah I'm pretty sure you are correct. ;)

EDIT: Added to the first post. ;)

Bixby Sayz

2009-08-27 20:37:39

From: Coh3n
I have noticed that throughout scripts people like to write some code that randomly right/left clicks when clicking an object./QUOTE]

Talk about timing! I just finished writing code to do just that in my script, but yours is so much nicer! Gonna use this in my script (with full credit of course).

Coh3n

2009-08-27 21:13:15

From: Bixby Sayz
From: Coh3n
I have noticed that throughout scripts people like to write some code that randomly right/left clicks when clicking an object./QUOTE]

Talk about timing! I just finished writing code to do just that in my script, but yours is so much nicer! Gonna use this in my script (with full credit of course).


Hey that's great! I'm glad to see that someone other than me is going to use it. :D

Thanks!

NCDS

2009-08-27 22:00:41

Honestly,

MMouse(x, y, 4, 4);
if IsUpText('illow') then
begin
Writeln('We have found the Willow tree');
case Random(10) of
1: begin
Mouse(x, y, 0, 0, False);
Wait(80 + Random(100));
ChooseOption('hop');
end;
else
Mouse(x, y, 0, 0, True);
end;
Could just be:

MMouse(x, y, 4, 4);
if IsUpText('illow') then
begin
Writeln('We have found the Willow tree');
Bool := Random(10) = 1;
Mouse(x, y, 0, 0, Bool);
WaitOption('hop', 3000);
end;

It's not a bad idea though :)

Sabzi

2009-08-27 22:21:35

From: NCDS
Honestly,

MMouse(x, y, 4, 4);
if IsUpText('illow') then
begin
Writeln('We have found the Willow tree');
case Random(10) of
1: begin
Mouse(x, y, 0, 0, False);
Wait(80 + Random(100));
ChooseOption('hop');
end;
else
Mouse(x, y, 0, 0, True);
end;
Could just be:

MMouse(x, y, 4, 4);
if IsUpText('illow') then
begin
Writeln('We have found the Willow tree');
Bool := Random(10) = 1;
Mouse(x, y, 0, 0, Bool);
WaitOption('hop', 3000);
end;

It's not a bad idea though :)


RBoolEx(10) ;)


MMouse(x, y, 4, 4);
if IsUpText('illow') then
begin
Writeln('We have found the Willow tree');
Mouse(x, y, 0, 0, RBoolEx(10));
WaitOption('hop', 3000);
end;
Any more licit? :D

Coh3n

2009-08-28 00:30:54

From: NCDS
It's not a bad idea though :)


Haha thanks, and wow I never realized you could make it into only a couple lines. :p