SRL Archive - SRL Archives

WorldSwitcher.scar


Nava2

2009-03-06 12:03:34

{*******************************************************************************
Function OpenWorldScreen: Boolean;
by: Nava2
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
var
TPA: array [0..1] of TPointArray;
W, TheDC, iTime: Integer;
Box: TBox;
begin
Result := WorldScreen;
if Result then Exit;

W := BitmapFromString(17, 13, 'beNpjYKAb+I8ESBXBNAfTcDwK' +
'CGrBVIPmDEz15GlB1oWVgSfokBUQ1EKM8whqwRV0eIIRv5OIBQByA' +
'K1T');
TheDC := GetTargetDC;
SetTargetDC(GetBitmapDc(w));
FindColorsTolerance(TPA[0], clWhite, 0, 0, 17, 13, 0);
SetTargetDC(TheDC);
FindColorsTolerance(TPA[1], 13158, 305, 239, 368, 272, 3);
if FindTPAinTPA(TPA[0], TPA[1], TPA[0]) then
begin
Box := GetTPABounds(TPA[0]);
Box := IntToBox(Box.x1, Box.y1, Box.x1 + 82, Box.y2);
MouseBox(Box.x1, Box.y1, Box.x2, Box.y2, 1);
iTime := GetTimeRunning + 2000;
while not Result do
begin
if GetTimeRunning > iTime then Exit;
Wait(RandomRange(40, 80));
Result := WorldScreen;
end;
end;
end;


This works regardless of if you have a favourited world now, or if there is already a world picked.

Edit:

I was getting annoyed with my worlds.INI always being out of date, so I wrote these up. Not sure about the current policy on accessing the Jagex website but here is what I fixed up. mixster's world's parser was the Key base for this.

function UpdateWorlds: Boolean;
var
worldList: TWorldArray;
str, Path: string;
tsa, tsb: TStringArray;
W, I, H, Time: Integer;
begin
try
Result := True;
Path := AppPath + 'Includes\SRL\SCSS\Worlds.INI';
Writeln('NOTE: Attempting to update the Worlds.INI, please allow the script to access this file.');
Time := GetTimeRunning;
W := RewriteFile(Path, False);
CloseFile(W);
str := GetPage('http://www.runescape.com/slu.ws?order=WMPLA');
Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
Delete(str, 1, Pos('<tr', str) + 3);
tsa := m_Explode(str, '<tr');
SetLength(worldList, High(tsa) + 1);
H := High(tsa);
for I := 0 to H do
with worldList[I] do
begin
tsb := m_Explode(tsa[I], '<td');
if High(tsb) <= 7 then
begin
Writeln('Skipping world ' + IntToStr(I + 1) + ' because explosion didn''t return enough values');
Continue;
end;
PlayerNo := StrToIntDef(Copy(tsb[2], 2, Pos(' Players', tsb[2]) - 2), 2000);
case Uppercase(Between('"', '"', tsb[3])) of
'US': Location := 'United States';
'NL': Location := 'Netherlands';
'CA': Location := 'Canada';
'AU': Location := 'Australia';
'SE': Location := 'Sweden';
'FI': Location := 'Finland';
'GB': Location := 'Great Britain';
'NZ': Location := 'New Zealand';
'DK': Location := 'Denmark';
'BE': Location := 'Belguim';
'BR': Location := 'Brazil';
'MX': Location := 'Mexico';
'IE': Location := 'Ireland';
'NO': Location := 'Norway';
else
Writeln('Location: ' + Between('"', '"', tsb[3]) + ' unknown. Please notify someone of this.');
end;
Prefix := Between('http://', '.runescape', tsb[1]);
if Prefix = '' then
Prefix := Replace(Lowercase(Between('>' + #10, #10 + #10, tsb[1])), ' ', '');
Number := StrToIntDef(Replace(Prefix, 'world', ''), -1);
if Number = -1 then
Writeln(tsb[1] + ' || ' + Prefix);
Activity := Between('>', '<', tsb[4]);
if Activity = '-' then
Activity := '';
LootShare := Between('title="', '"', tsb[5]) = 'Y';
QuickChat := Between('title="', '"', tsb[6]) = 'Y';
PvP := Between('title="', '"', tsb[7]) = 'Y';
Members := Between('>', '<', tsb[8]) = 'Members';
end;
//Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
WriteINI('Worlds', 'Count', IntToStr(High(worldList) + 1), Path);
WriteINI('Worlds', 'High', IntToStr(worldList[High(worldList)].Number) + #13#10, Path);
H := High(worldList);
for I := 0 to H do
with worldList[I] do
begin
Str := 'World' + IntToStr(Number);
DeleteINI(Str, '', Path);
WriteINI(Str, 'Prefix', Prefix, Path);
WriteINI(Str, 'Activity', Activity, Path);
WriteINI(Str, 'Members', BoolToStr(Members), Path);
//WriteINI(Str, 'Flag', fla + 'Flag', Path);
WriteINI(Str, 'Location', Location, Path);
WriteINI(Str, 'LootShare', BoolToStr(LootShare), Path);
WriteINI(Str, 'QuickChat', BoolToStr(QuickChat), Path);
WriteINI(Str, 'PvP', BoolToStr(PvP) + #13#10, Path);
end;
Writeln('Parsed Worlds Page into Worlds.INI. Took ' + IntToStr(GetTimeRunning - Time) + ' ms.');
except
Result := False;
SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
end;
end;

{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle; Edits by Nava2
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
// Edit: Changed to use Members as a boolean to go w/ the previous Parser function.. Also added StrToBool; As well as try..except
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
try
H := StrToInt(ReadINI('Worlds', 'High', AppPath + 'includes\SRL\SCSS\worlds.ini'));
except
Writeln('LoadWorldArrays: Could not load world arrays, attempting to rewrite Worlds.INI');
if not UpdateWorlds then
begin
SRL_Warn('LoadWorldArrays', 'Could not Load World arrays, please download mixster''s world parser, and replace Worlds.ini', Warn_AllVersions);
Exit;
end;
end;
for i := 1 to H do
begin
if not (ReadINI('World' + IntToStr(i), 'Prefix', AppPath + 'includes\SRL\SCSS\worlds.ini') = '') then
begin
SetArrayLength(WorldArray, Length(WorldArray)+1);
Hw := High(WorldArray);
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', AppPath + 'includes\SRL\SCSS\worlds.ini');
WorldArray[Hw].Members := StrToBool(ReadINI('World' + IntToStr(i), 'Members', AppPath + 'includes\SRL\SCSS\worlds.ini'));
WorldArray[Hw].LootShare := StrToBool(ReadINI('World' + IntToStr(i), 'Lootshare', AppPath + 'includes\SRL\SCSS\worlds.ini'));
WorldArray[Hw].QuickChat := StrToBool(ReadINI('World' + IntToStr(i), 'Quickchat', AppPath + 'includes\SRL\SCSS\worlds.ini'));
WorldArray[Hw].PVP := StrToBool(ReadINI('World' + IntToStr(i), 'PvP', AppPath + 'includes\SRL\SCSS\worlds.ini'));
end;
end;
end;

Sir R. M8gic1an

2009-03-06 12:18:57

looking good.

~RM

ZaSz

2009-03-06 12:24:19

No procedure to actually switch worlds?

Nava2

2009-03-06 15:25:39

Nah, the current ones work absolutely fine :)

Smarter Child

2009-03-07 12:46:57

Lol, i could use this, is this being added to SRL?

ZephyrsFury

2009-03-07 21:09:31

Nice, added. Thanks nava. :)

Nava2

2009-03-08 01:17:29

Yay :) there are issues with the rest of the functions.

ZephyrsFury

2009-03-08 01:38:27

From: Nava2
Yay :) there are issues with the rest of the functions.


Such as…?

Narcle

2009-03-08 07:27:14

From: Nava2
Yay :) there are issues with the rest of the functions.


Well the one I know of should be fixed… but its in the dev svn and it hasn't been released for awhile now.

Nava2

2009-03-08 14:50:54

It doesn't always select the world. Says its not there kinda thing, when it is. :)

Try this:
if not LoggedIn then
begin
if not SelectWorld(44) then
if not SelectWorld(143) then
if not SelectWorld(145) then
begin
Writeln('Could not select worlds 44, 143, or 145. Terminating.');
TerminateScript;
end;
//LoginPlayer;
end;

ZephyrsFury

2009-03-09 04:10:46

From: Nava2
It doesn't always select the world. Says its not there kinda thing, when it is. :)

Try this:
if not LoggedIn then
begin
if not SelectWorld(44) then
if not SelectWorld(143) then
if not SelectWorld(145) then
begin
Writeln('Could not select worlds 44, 143, or 145. Terminating.');
TerminateScript;
end;
//LoginPlayer;
end;


I think thats the error that Narcle fixed.

Nava2

2009-03-09 08:08:24

From: ZephyrsFury
I think thats the error that Narcle fixed.


Awesome :)

Nava2

2009-03-23 17:24:39

Sorry for double, but added more stuff. :)

E: Thanks to mixster, added new flag types.

Narcle

2009-03-23 19:00:37

Well I would of done this myself. But I was under the impression that using online resources in the actually SRL svn was against one of the "rules/guidelines." But times have changes and I personally would love to have this in SRL. /shrug

Nava2

2009-03-23 19:23:31

Same, I just did it because I wasn't sure anyone had thought of it. I think its a good idea, but I guess my opinion doesn't matter :(

ZephyrsFury

2009-03-24 01:20:39

You could just use FAWG Online.

lordsaturn

2009-03-24 08:36:30

{*******************************************************************************
procedure LowestWorld;
by: lordsaturn
Description: Chooses the f2p world with the least amount of players
*******************************************************************************}
procedure LowestWorld;
var
a, c, i, x, y: integer;
begin
if LoggedIn then
Logout;
OpenWorldScreen;
c := CountColor(16777215, 57, 148, 691, 456);
Mouse(195, 121, 3, 3, True);
a := GetSystemTime;
while c = CountColor(16777215, 57, 148, 691, 456) do
begin
Wait(100);
if GetSystemTime - a > 5000 then
Break;
end;
Wait(50+Random(50));
for i := 0 to 16 do
if Trim(GetTextAtEx(631, 149+i*8, 0, SmallChars, False, False, 0, 2, clWhite, 8,
False, tr_AllChars)) = 'Free' then
if not FindColor(x, y, 4027205, 582, 148+i*8, 602, 155+i*8) then
begin
Mouse(85, 148+i*8, 600, 7, True);
while WorldScreen do
Wait(100);
Exit;
end;
TypeByte(VK_ESCAPE);
end;