SRL Archive - Reflection Development

[New] Useful function R_ClickContinue (commit?)


Cstrike

2010-10-15 18:29:08

For some reason, R_ClickToContinue seems to be messed up and not work half time (and never seems to work in randoms anymore).

Therefore, I propose that these two functions be added:

Function #1 (not mine):
This function is essential for Interfaces.simba, because we can't access the components of children interfaces, but only the components of interfaces:
{*******************************************************************************
function GetComponentText(ParentI, ChildI, CompI: Integer): String;
by: ZephyrsFury
Description: Gets the text of child components that GetInterfaceText cannot.
*******************************************************************************}
function GetComponentText(ParentI, ChildI, CompI: Integer): String;
var
Text, Child, Comp: Integer;
begin
Child := GetInterface(ParentI, ChildI);
Comp := SmartGetFieldArrayObject(Child, hook_interface_GetChildren, compI); //Getting the children components of the Child component
Text := SmartGetFieldObject(Comp, hook_interface_GetText);
Result := GetJavaString(Text, 255);
SmartFreeObject(Text);
SmartFreeObject(Comp);
SmartFreeObject(Child);
end;

I made this function which I've tested and it's worked good so far. It may need more rigorous testing, or at least input on why you disagree on it being useful [constructive criticism please :)]
Of course if there's a way to cut down on code/time, I'm all for it.
*Note: The above function HAS to be committed before thinking about committing this.
{*******************************************************************************
function R_ClickContinue (Parent_Child_Component : TIntegerArray; initialWaitMS, randomWaitMS, timeoutMS : Integer) : Boolean;
by: Cstrike
Description: Clicks continue. Create an array with 2 numbers if the click cont
button can be found with parent/child numbers only. Use three variables if the
click cont button requires the third index to reach into a child's component.
TimeoutMS is in milliseconds, there are failsafes. InitialWaitMS is how long the
procedure should wait at the beginning (so it doesnt instantly click, which is
very bot-like), and then randomWaitMS is how much random time in milliseconds
that should be added on to make it even less bot-like. If you put in the wrong
length of an array there are failsafes.
*******************************************************************************}
function R_ClickContinue (Parent_Child_Component : TIntegerArray; initialWaitMS, randomWaitMS, timeoutMS : Integer) : Boolean;
var t : Integer;
begin
result := false;
wait (initialWaitMS+random(randomWaitMS));
if high(Parent_Child_Component) = 2 then
begin
MarkTime (t);
if GetComponentText(Parent_Child_Component[0], Parent_Child_Component[1], Parent_Child_Component[2]) = 'Click here to continue' then
begin
Mouse (303, 452, 172, 7, true);
repeat
wait (25+random(25));
repeat
wait (25+random(25));
until not (GetComponentText(Parent_Child_Component[0], Parent_Child_Component[1], Parent_Child_Component[2]) = 'Please wait') or (TimeFromMark(t) > timeoutMS)
until (TimeFromMark(t) > timeoutMS) or not (GetComponentText(Parent_Child_Component[0], Parent_Child_Component[1], Parent_Child_Component[2]) = 'Click here to continue')
if TimeFromMark(t) > timeoutMS then writeln ('Timeout R_ClickContinue reached!') else
begin
writeln ('Sucessfully clicked continue');
result := true;
end;
end;
end else
if high(Parent_Child_Component) = 1 then
begin
MarkTime (t);
if GetInterfaceText(Parent_Child_Component[0], Parent_Child_Component[1]) = 'Click here to continue' then
begin
Mouse (303, 452, 172, 7, true);
repeat
wait (50+random(25));
repeat
wait (25+random(25));
until not (GetInterfaceText(Parent_Child_Component[0], Parent_Child_Component[1]) = 'Please wait') or (TimeFromMark(t) > timeoutMS)
until (TimeFromMark(t) > timeoutMS) or not (GetInterfaceText(Parent_Child_Component[0], Parent_Child_Component[1]) = 'Click here to continue')
if TimeFromMark(t) > timeoutMS then writeln ('Timeout R_ClickContinue reached!') else
begin
writeln ('Sucessfully clicked continue');
result := true;
end;
end;
end else
begin
writeln ('The array size for R_ClickContinueArray is wrong (you have '+inttostr(high(Parent_Child_Component)+1)+', you should have 2 or 3)');
end;
end;

The reason why I made this thread, is that randoms keep having this click to continue stuff. When I was in a random, I had a bit of lag for some reason and it screwed everything up with the click to continue. Some scripts walk ahead and think they've clicked continue, but then the random NPC will say "no dont do that, talk to me first", upon which the bot either fixes itself or fails.

This code is also universal. Failsafes work great too!! Try it and be amazed, or I'll be damned. This can support theoretically as many sub-indexes as can be coded due to the first variable being a TIntegerArray (of course the reflection code would need to be updated).

Try it on a bank (draynor for example):
if R_ClickContinue([241, 5], 1500, 1000, 10000) then writeln ('True, clicked continue successfully') else writeln ('False, failed or timed out');