SRL Archive - SRL Archives

text.scar


Coh3n

2009-07-11 02:55:12

Okay so this is my first attempt at contributing to SRL, and I wanted to know what you guys think. It's nothing advanced at all, it was just something that I found easier when making a script, as I used the same coding more than once.

It would be used in situations like opening a door/gate, or climbing a stile/rock wall.

{*******************************************************************************
function ClickMouseOption(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: TStringArray): Boolean;
By: Coh3n
Description: Either clicks the specified option, or right clicks and chooses the
option, or random click/right click, and chooses the option.
i.e ClickMouseOption(x, y, 4, 4, 'Random', ['Gate'], ['Open']);
*******************************************************************************}

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

//Reflection version, basically the same thing.
function R_ClickMouseOption(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: TStringArray): Boolean;
begin
if not InStrArr(Option, ['random', 'right', 'left'], False) then SRL_Warn;
Result := WaitUpTextMulti(UpText, 100 + Random(400));
if not Result then SRL_Warn;
if Option = 'random' then
case Random(2) of
0: Option := 'left';
1: Option := 'right';
end;
Mouse(x, y, rx, ry, Option = 'left');
if Option = 'right' then
R_ChooseActionMulti(ChooseOpt);
end;

Thanks to Da 0wner for helping me shorten it A LOT. :)

Don't be too hard on me. ;)

Da 0wner

2009-07-11 05:48:39

Could be shortened.

Btw, get on MSN :p.

senrath

2009-07-11 07:34:56

You can remove all the lines of Wait(80 + Random(500)), as sufficient wait time is already included in the WaitUpTextMulti.

Coh3n

2009-07-11 07:36:03

From: senrath
You can remove all the lines of Wait(80 + Random(500)), as sufficient wait time is already included in the WaitUpTextMulti.


Yeah I've got a much shorter version after talking to Kyle, I'll update it soon.

ShowerThoughts

2009-07-11 12:42:34


if not InStrArr(Option, ['random', 'right', 'left'], False) then Exit;
It is InStrARRAY, If I'm correct so wouldn't Option be ChooseOption?
Or is it you check 1 string by an array of strings and it will result true or false.

Da 0wner

2009-07-11 15:39:41

Don't question my methods Hermen :p.

That returns true if it is a valid option. Returns false if it is not.

Coh3n

2009-07-14 20:54:27

From: Hermen

It is InStrARRAY, If I'm correct so wouldn't Option be ChooseOption?


Don't think so, got it straight from the manual + what Da 0wner said. :p

EDIT: Added the Reflection version, which is basically the same thing.

mixster

2009-07-14 21:04:14

Look up SRL error throwing - rather than just exiting, it should clearly shout at the scripter for being silly not to pass a valid argument. Possibly a numeric argument instead :)

Da 0wner

2009-07-14 21:08:45

Yes, my version had SRL_Warn in it, but he decided not to use :p.

Coh3n

2009-07-14 21:11:25

From: Da 0wner
Yes, my version had SRL_Warn in it, but he decided not to use :p.


What? :o

Lol, it did? :confused:

From: mixster
Look up SRL error throwing - rather than just exiting, it should clearly shout at the scripter for being silly not to pass a valid argument. Possibly a numeric argument instead :)


Thanks, added.

Da 0wner

2009-07-14 21:13:47

Yep. Doesn't matter, you can add your own in :D.