SRL Archive - Reflection Development

R_ChooseOptionEx


traveler

2010-12-07 21:32:52

Just thought i would make a function like the srl's choose option. What this function does, it searches for all the text in the array.

for example:
if your searching for 'Use-quickly Bank Booth'
You input this into the function ['booth','quickly','Use'] and it will find the first menu option, which in this case would be 'Use-quickly Bank Booth' and it will select it.

If it can not find all the options inputted, it will select the first option matching one of the inputed strings.

{*******************************************************************************
function R_ChooseOptionEx(Options: TStringArray): Boolean;
By: traveler - moddified from R_ChooseOptionMulti
Description: Selects the first option that matches all the inputted strings.
If None match, chooses first option with a matching string.
*******************************************************************************}
function R_ChooseOptionEx(Options: TStringArray): Boolean;
var
T, I, I2, xOff, yOff: Integer;
PT: TPoint;
MenuOptions: TStringArray;
begin
Result := False;
if not IsMenuOpen then
begin
MarkTime(T);
while(TimeFromMark(T) < 1000)do
wait(50);
if not IsMenuOpen then
Exit;
end;
PT := Point(SmartGetFieldInt(0, hook_static_MenuX) + 4, SmartGetFieldInt(0, hook_static_MenuY) + 4);
MenuOptions := GetMenuText;
// Cstrike's failsafe
if (high(MenuOptions) < 0) or (high(Options) < 0) then
begin
Writeln('Warning: High array size for MenuOptions/Options is < 0, aborting R_ChooseOptionMulti to prevent crash');
Exit;
end;
for I:=0 to High(MenuOptions) do
begin
for I2:=0 to High(Options) do
begin
if (Pos(Lowercase(Options[I2]),Lowercase(MenuOptions[I])) <= 0) then
Continue;
if (I2 = (High(Options)-1)) then
begin
xOff := RandomRange(4, 4 + Random(Length(MenuOptions[i]) * 4 - 4));
yOff := 21 + (16 * i) + RandomRange(2, 10);
Mouse(PT.x + xOff, PT.y + yOff, 0, 0, True);
Wait(RandomRange(80, 100));
Result := not IsMenuOpen;
Exit;
end;
end;
end;
Result := R_ChooseOptionMulti(Options);
end;

mormonman

2010-12-07 22:48:17

It looks nice, but why would you want that? With reflection you don't need to filter out any letters or even spaces. Just use 'Use-Quickly Bank Booth'.

traveler

2010-12-07 22:51:03

true, but ive run into problems with the dashes and it just not working 100% when you do something like 'Use-Quickly Bank Booth'

Cstrike

2010-12-07 23:24:58

From: traveler
true, but ive run into problems with the dashes and it just not working 100% when you do something like 'Use-Quickly Bank Booth'


Yeah I get this too :( , great that this will be fixed

Feroc1ty

2010-12-08 01:23:28

Me too, but that's why I simply type in 'ly Ba', and it will pretty much always find that.

Frement

2010-12-08 01:47:28

I remember someone asking for stuff so you could search with wildcards etc. For example:
preg_getUpText('Att?ck');
And that would work for "Att4ck" etc.

Cstrike

2010-12-08 14:42:54

From: Frement
I remember someone asking for stuff so you could search with wildcards etc. For example:
preg_getUpText('Att?ck');
And that would work for "Att4ck" etc.


The wildcard idea would be cool, if you retrieve the string you can just try all the different letters/numbers, or even check relative positions of stuff before and after the ?

Bad Boy JH

2010-12-08 19:13:22

could you have something like
UpTextWild('Attack', 1);
Which would return true for Att4ck or 4ttack, basically as many incorrect characters as the second variable. might be useful if it keeps screwing up (moreso for the colour one)