SRL Archive - SRL Archives

Some of my core functions


Richard

2009-04-05 17:58:35

I had no internet connection for the last couple of days and was rather bored, so I made some adjustments/additions to some of the includes. They're not very good, as I've only worked on them for a little while, I may work on them/add more when I feel in the mood.

SRL/SRL/core/AntiBan.scar

{*******************************************************************************
procedure RandomRClickEx(Area: String);
By: Richard
Description: Performs random right click in the specified area. Designed for
use when you don't want a random right click in certain areas (eg you don't want
it to block items in your inventory).
Valid Arguements: main screen/ms, minimap/mm, inventory/invent/mi,
chat/my chat/mc
*******************************************************************************}

procedure RandomRClickEx(Area: string);
Var
MSpeed: Integer;
Begin
If not(LoggedIn) then Exit;
MSpeed := MouseSpeed;
MouseSpeed := 5+random(6);
Case Area of
'main screen','ms': MouseBox(MSX1, MSY1, MSX2, MSY2, 2);
'minimap','mm': MouseBox(MMX1, MMY1, MMX2, MMY2, 2);
'inventory','mi': MouseBox(MIX1, MIY1, MIX2, MIY2, 2);
'chat','my chat','mc': MouseBox(MCX1, MCY1, MCX2, MCY2, 2);
else
srl_Warn('RandomRClickEx', '"' + Area + '" is not a valid area', warn_AllVersions);
end;
MouseSpeed := MSpeed;
end;

I only did this because I've noticed the right click can sometimes cause errors in the script, whether its blocking the minimap for walking, or blocking the inventory to see items. You can now define only certain areas to click.


SRL/SRL/core/Color.scar


{*******************************************************************************
Function FindColorToleranceInc(Color: Integer; var x, y: Integer;
xs, ys, xe, ye: Integer; MaxTolerance: Integer): Boolean;
By: Richard
Description: Searches for the color in the set area and increases the tolerance
until it finds the color or the maximum tolerance is reached.
*******************************************************************************}

Function FindColorToleranceInc(Color: Integer; var x, y: Integer; xs, ys, xe, ye: Integer; MaxTolerance: Integer): Boolean;
Var
tol : Integer;
Begin
If (MaxTolerance <= -1) then
srl_Warn('FindColorToleranceInc', 'Tolerance cannot be below 0', warn_AllVersions);
For tol := 0 to MaxTolerance do
Begin
Result := FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol) then
Begin
If Result then
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;
If (tol >= MaxTolerance) then
Begin
srl_Warn('FindColorToleranceInc', 'couldn'#39't find the color', warn_AllVersions);
Exit;
end;
end;
end;

Just so that you never have to worry about finding the right tolerance for a colour, probably the most accurate way to find a colour. Thanks to Marpis for the fixes.


SRL/SRL/core/Login.scar

{*******************************************************************************
procedure LoginPlayerEx(PVP, SetGraphics: Boolean);
By: SRL Developers modded by Richard
Description: Logs in the Player[CurrentPlayer]. Will log into PVP if wanted,
and will only set graphics options if wanted (for HD scripts).
*******************************************************************************}

procedure LoginPlayerEx(PVP, SetGraphics: Boolean);
var
Mark, Attempts, x, y: Integer;
Actions: TVariantArray;
RetryLogin: Boolean;
label
ProcStart;
begin
ActivateClient;
Wait(100);
TypeByte(vk_Escape);

if (GetColor(212, 327) = 238301) then //At Click To Play screen
begin
Wait(1000 + Random(3000));
MouseBox(227, 337, 555, 364, 1);
MarkTime(Mark);
while (TimeFromMark(Mark) < 30000) and (not(LoggedIn)) do
Wait(1000 + Random(1000));
end;
if (not(RSReady)) then
begin
MarkTime(Mark);
while (not(RSReady)) do
begin
Wait(100);
if (TimeFromMark(Mark) > 180000) then
begin
WriteLn('It has been 3 minutes and Runescape is not yet ready... Terminating.');
TerminateScript;
end;
end;
WriteLn('Welcome to Runescape.');
end;

LoginScreenMusic(True);
if (not(GraphicsSet)) then
if SetGraphics then
begin
SetAutoingDefaults;
GraphicsSet := True;
end;
ProcStart:

if (not(LoggedIn)) then
begin
if (not(Players[CurrentPlayer].Active)) then
begin
WriteLn('Player is not Active...');
NextPlayer(False);
Exit;
end;
Wait(900 + random(60));

//Click 'Log In' on main menu
while (GetColor(343, 175) <> 7750) do //while (GetColor(343, 174) <> 7750) do
begin
MouseBox(360, 180, 400, 185, 1);
Wait(100 + Random(100));
end;

//Type Username
Mouse(315, 272, 10, 5, True);
while (CountColor(7750, 311, 269, 452, 284) > 13) do
begin
KeyDown(vk_Back);
Wait(10 + Random(10));
KeyUp(vk_Back);
Wait(50 + Random(50));
end;
for Mark := 0 to 3 do
begin
KeyDown(vk_Back);
Wait(10 + Random(10));
KeyUp(vk_Back);
Wait(50 + Random(50));
end;
Wait(100 + Random(200));
WriteLn(Capitalize(Players[CurrentPlayer].Name));
TypeSend(Players[CurrentPlayer].Name);
Wait(100+random(50));

//Type Password
Mouse(315, 334, 10, 5, True);
while (CountColor(7750, 311, 337, 452, 352) > 13) do
begin
KeyDown(vk_Back);
Wait(10 + Random(10));
KeyUp(vk_Back);
Wait(50 + Random(50));
end;
for Mark := 0 to 3 do
begin
KeyDown(vk_Back);
Wait(10 + Random(10));
KeyUp(vk_Back);
Wait(50 + Random(50));
end;
Wait(100 + Random(200));
TypeSend(Players[CurrentPlayer].Pass);
Wait(500 + Random(300));

if (not(FindTextTPA(12509695, 0, 288, 205, 475, 247, 'login', StatChars, Nothing))) then //If 'enter' from typesend didn't log us in
begin
MouseBox(355, 359, 403, 372, 1); //Click 'login' login screen
Wait(250 + random(100));
end;
//Clicks PVP login screen
If PVP then
Begin
If FindColor(x, y, 197552, MSX1, MSY1, MSX2, MSY2) then
Mouse(432, 420, 48, 5, true);
end;
MarkTime(Mark);
repeat
SetLength(Actions, 0);

if (TimeFromMark(Mark) > 60000) then
Actions := ['One minute has passed...', 0, 2, 'NextPlayer', 'Login Failed']
else
case (CountColor(12509695, 288, 205, 475, 247)) of //Number of text colour points
// Actions := ['WriteLn Text', TimeToWait, NumberOfRetries, 'FinalAction', 'PlayerStatus'];
760: Actions := ['Too many incorrect logins.', 5 * 60000, 2, 'NextPlayer', ''];
536: Actions := ['Login limit exceeded. Please wait 1 minute and try again.', 60000, 2, 'NextPlayer', ''];
711: Actions := ['Your account has been disabled', 0, 0, 'NextPlayer', 'Acc Disabled'];
598: Actions := ['Invalid Username / Password', 0, 2, 'NextPlayer', 'Wrong User/Pass'];
787: Actions := ['Not a Members Account', 0, 0, 'NextPlayer', 'Non-member'];
408: Actions := ['World is full.', 5000, 20, 'Terminate', ''];
623: Actions := ['Your account is already logged in', 5000, 0, 'RandomNextPlayer', ''];
555: Actions := ['The Server is being updated.', 60000, 4, 'Terminate', 'Server Updating'];
218: Actions := ['Error Connecting.', 20000, 9, 'Terminate', 'Error Connecting'];
335: Actions := ['Unable to connect Login Server offline.',(20000) + Random(6000), 4, 'Terminate', 'Login Server Offline'];
512: Actions := ['RuneScape has been updated. Script Terminated.', 0, 0, 'Terminate', 'RS Updated'];
489: Actions := ['Connection timed out.', 0, 4, 'Terminate', 'Connection Timed Out'];
737: Actions := ['You are standing in a members-only area.', 0, 0, 'NextPlayer', 'In Mems-Only Area'];
//10: Actions := ['Error loading your profile.', 5000, 10, 'NextPlayer', 'Profile Loading Failed']; // Error loading your profile. Will attempt to re-login 5 more times.)
//11: Actions := ['Login server rejected session.', 1000, 10, 'NextPlayer', 'Login Serv. Rejected']; // Login server rejected session.
end;

if (Length(Actions) > 0) then
begin
WriteLn(Actions[0]);
Wait(Actions[1] + Random(100));
if (Actions[2] <> 0) then
if (Attempts < Actions[2]) or (Actions[2] = -1) then
begin
RetryLogin := True;
Break;
end;
if (Actions[4] <> '') then
Players[CurrentPlayer].Loc := Actions[4];
case Actions[3] of
'NextPlayer': NextPlayer(False);
'RandomNextPlayer': RandomNextPlayer(True);
'Terminate': TerminateScript;
end;
Exit;
end;
Wait(100);
until(GetColor(212, 327) = 238301);

if (RetryLogin) then
begin
RetryLogin := False;
Inc(Attempts);
goto ProcStart;
end;

if (GetColor(212, 327) = 238301) then
begin
Wait(1000 + Random(2000));
MouseBox(227, 337, 555, 364, 1);
end;
MarkTime(Mark);
while (TimeFromMark(Mark) < 30000) and (not(LoggedIn)) do
Wait(1000 + Random(1000));
end;

if (LoggedIn) then
begin
PlayerStartTime := (GetSystemTime div 1000); // PlayerStartTime
if Length(Players[CurrentPlayer].NickTPA) < 2 then
begin;
Writeln('Creating the NickTPA.');
if Players[CurrentPlayer].Nick <> '' then
Players[CurrentPlayer].NickTPA := CreateTPAFromText(Players[CurrentPlayer].Nick, UpChars)
else
begin;
Writeln('Nickname isn''t set, taking the username instead..');
Players[CurrentPlayer].NickTPA := CreateTPAFromText(Players[CurrentPlayer].Name, UpChars);
end;
end;
AddToSRLLog('Current player: ' + Capitalize(Players[CurrentPlayer].Name));
end;
end;

So that you can either run on PVP worlds, or run with HD if you have made a script for it.

{*******************************************************************************
procedure LoginPlayer;
By: SRL Developers modded by Richard
Description: Logs in the Player[CurrentPlayer], with default settings.
*******************************************************************************}

Procedure LoginPlayer;
begin
LoginPlayerEx(False, True);
end;

Same as the older LoginPlayer, but shrunk with my procedure.



I'm sure these could be made a lot better, but I thought I'd post to get your opinions on where I can improve.

Nava2

2009-04-05 19:47:18

Hmm, I like RandomRightClickEx, I agree, but what you should look at is the current RandomRClick, does it not select Examine or something along those lines?

The others, aren't really advanced enough, nor necessary. LoginPlayer currently has PVP support ;)

ZephyrsFury

2009-04-06 04:33:47

Maybe have RandomRClickEx take an array so the possible area can be more than just one place. Or make it RandRClickAreaExcept().

Richard

2009-04-06 06:10:45

From: Nava2
Hmm, I like RandomRightClickEx, I agree, but what you should look at is the current RandomRClick, does it not select Examine or something along those lines?

The others, aren't really advanced enough, nor necessary. LoginPlayer currently has PVP support ;)


No, its BoredHuman that does the examining. And I don't think that LoginPlayer has PVP support, and definately not a no-graphics option.

From: ZephyrsFury
Maybe have RandomRClickEx take an array so the possible area can be more than just one place. Or make it RandRClickAreaExcept().


How do you go about moving the mouse in all but a certain area, or just have a random case of it going in one of the other 3 areas?

ZephyrsFury

2009-04-06 07:03:33

LoginPlayer does has PVP support (in the dev svn anyway, not sure about the public one). And yea I mean a random case of the areas that you want to move the mouse in.

marpis

2009-04-06 11:04:06


[B]tol := 0;[/B]
If (MaxTolerance <= -1) then
srl_Warn('FindColorToleranceInc', 'Tolerance cannot be below 0', warn_AllVersions);
[B]For tol := 0 to (MaxTolerance - 1) do[/B]

the first tol:= 0; is not needed. For tol:= 0 does it for you.


If FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol) then
Begin
Result := FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;
There you search for the color 2 times, which is not needed either.
Fix:

result:= FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
if Result then
Begin
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;

Also max tolerance means that the function will look for the color with that tolerance. Your function doesnt.

For tol := 0 to (MaxTolerance - 1) do //why -1?

Here are my fixes: (didn't try if it works, but it should)

Function FindColorToleranceInc(Color: Integer; var x, y: Integer; xs, ys, xe, ye: Integer; MaxTolerance: Integer): Boolean;
Var
tol : Integer;
Begin
If (MaxTolerance < 0) then
begin
srl_Warn('FindColorToleranceInc', 'Tolerance cannot be below 0', warn_AllVersions);
exit;
end;
For tol := 0 to MaxTolerance do
Begin
result:= FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
if Result then
Begin
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
exit;
end;
end;
srl_Warn('FindColorToleranceInc', 'couldn'#39't find the color', warn_AllVersions);
end;

I think someone should add a function like this to SRL!

Richard

2009-04-06 14:11:50

Thanks for the feedbackand the fixes!

Sorry I rushed that function when I made it and made a couple of stupid errors. I'm not sure why I put -1, guess I wasn't thinking.

I hope too it gets added :)

Nava2

2009-04-06 18:40:48

I like some of these, I will look farther into the RandomRClick. But I don't think the Inc Tolerance is necessary, someone feel free to prove me wrong though.

Richard

2009-04-06 19:01:51

I just feel it would help less experienced scripters who don't know what a good tolerance is, makes it simpler not having to worry about finding the right tolerance. And as it tells you what tolerance it ended up with, it helps them learn what's best.

Nava2

2009-04-08 00:38:25

On that note, why would we want to encourage poor scripting when good scripting is not far off.

Sorry, that wasn't meant to be harsh, just a fact. :)

marpis

2009-04-08 01:18:33


[B]tol := 0;[/B]
If (MaxTolerance <= -1) then
srl_Warn('FindColorToleranceInc', 'Tolerance cannot be below 0', warn_AllVersions);
[B]For tol := 0 to (MaxTolerance - 1) do[/B]

the first tol:= 0; is not needed. For tol:= 0 does it for you.


If FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol) then
Begin
Result := FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;
There you search for the color 2 times, which is not needed either.
Fix:

result:= FindColorTolerance(x, y, Color, xs, ys, xe, ye, tol);
if Result then
Begin
WriteLN('FindColorToleranceInc: '+IntToStr(tol)+' was the final tolerance');
Break;
end;

Also max tolerance means that the function will look for the color with that tolerance. Your function doesnt.

For tol := 0 to (MaxTolerance - 1) do //why -1?

Here are my fixes: (didn't try if it works, but it should)

I think someone should add a function like this to SRL!

Richard

2009-04-08 05:28:44

Surely that means that the tolerance won't have any difference, as MaxTolerance+Step is always going to be bigger than MaxTolerance, so it would make step always 0…