SRL Archive - SRL Archives

WorldSwitcher.scar


Bionicle

2010-03-04 20:17:28

STILL BROKEN:
    GetWorldInfo(fixed by Narcle)

Needs testing to see if they are broken or not (they shouldn't be):
    UpdateWorlds
  • LoadWorldArray
  • ChangeWorld + RandomWorld(probably works, but untested)
  • ChooseWorldBy

I fixed:
    WorldScreen
  • FindWorld
  • SelectWorld
  • OrderWorlds

I rewrote:
    OpenWorldScreen

I added:
    GetLobbyTab
  • LobbyTab

I changed;
    GetWorldInfo
  • WorldScreen
  • FindWorld
  • SelectWorld
  • OrderWorlds
  • OpenWorldScreen

In WorldScreen I changed:
    The mouse coords
  • SmallChars to StatChars

In FindWorld I changed:
    Added to take into account members world text (yellow instead of white)
  • Mouse coords that were off, such as the order world one and the box of the world numbers
  • Added if the World screen is not open, try to open it before it exits the function

In SelectWorld I changed:
    Added to take into account members world text (yellow instead of white)
  • Mouse coords that were off
  • When it moves the mouse over the world to click it, to look for the highlighted grey color before it clicks
  • when it clicks instead of the timer, i changed it to if it finds the highlighted orange color (world switching is hella faster now ;), no need for timer)

In OrderWorlds I changed:
    The coords of the box that surounded the ordering button thingys
  • The array of the TStringArray, lootshare was in the wrong place.

In GetWorldInfo I changed:
    Added to take into account members world text (yellow instead of white)
  • changed SmallChars to StatChars so it would at least run the other functions ^.^ not to sure how to fix it

New WorldSwitcher.scar:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป WorldSwitch routines --//
//-----------------------------------------------------------------//
// * function WorldScreen: Boolean; // by Narcle
// * function GetLobbyTab: Boolean; // by Bionicle1800
// * function LobbyTab: Boolean; // by Bionicle1800
// * function OpenWorldScreen: Boolean; // by Nava2
// * function UpdateWorlds: Boolean; // by mixster & Nava2
// * procedure LoadWorldArrays; // by Narcle
// * function FindWorld(W: integer): Boolean; // by Narcle
// * function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean; // by Narcle
// * function SelectWorld(WorldNumber: Integer): Boolean; // by Narcle & ZephyrsFury
// * function RandomWorld(Members, PvP: Boolean): Integer; // by Narcle & mixster
// * function ChangeWorld(W: Integer): Boolean; // by Nava2
// * Procedure OrderWorlds(by: string; Descending: boolean); // by NaumanAkhlaQ
// * Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: TBooleanArray; Members, PVP: boolean): boolean; // by Rasta Magician

type
TWorld = record
Number, PlayerNo: Integer;
Members: Boolean;
Prefix, Location, Activity, Language: String;
LootShare, QuickChat, PVP: Boolean;
end;
TWorldArray = Array of TWorld;

Var
WorldArray: TWorldArray;
WorldsOrdered: Boolean;

{ const LobbyTab Constants;
Description: Constants representing lobbytab numbers. }

const
PlayerInfo = 1;
WorldSelect = 2;
FriendsList = 3;
ClanChat = 4;
Options = 5;

{*******************************************************************************
function WorldScreen: Boolean;
by: Narcle, edit by NaumanAkhlaQ, edit by Bionicle1800
Description: Returns true if the World screen is open.
*******************************************************************************}
function WorldScreen: Boolean;
begin
Result := FindTextTPA(16777215, 0, 672, 62, 695, 74, 'orld ', StatChars, Nothing);
end;

{*******************************************************************************
function GetLobbyTab: Integer;
By: Bionicle1800
Description: Gets current lobby tab.
*******************************************************************************}
function GetLobbyTab: Integer;
begin
for result := 1 to 5 do
if GetColor(97 + (result-1)*123, 31) = 7375258 then
Exit;
end;

{*******************************************************************************
function LobbyTab(Tab: Integer): Boolean;
By: Bionicle1800
Description: Goes to the lobby tab specified by the integer 'Tab'.
Valid arguments are 1 through 5, as well as PlayerInfo,
WorldSelect, FriendsList, ClanChat and Options.
*******************************************************************************}
function LobbyTab(Tab: Integer): Boolean;
begin
if not InRange(Tab, PlayerInfo, Options) then
begin
Srl_Warn('LobbyTab', 'Tab ' + IntToStr(Tab) + ' is not valid.', warn_AllVersions);
Exit;
end;
result := GetLobbyTab = Tab;
if result then
Exit;
if GetColor(97 + (Tab-1)*123, 31) = 4410194 then
begin
Mouse(97 + (Tab-1)*123, 31, 6, 6, true);
result := true;
end;
end;

{*******************************************************************************
function OpenWorldScreen: Boolean;
by: Bionicle1800
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
begin
if LobbyTab(2) then
if WorldScreen then
result := true;
end;

const
SRL_LG_ENGLISH = 0;
SRL_LG_GERMAN = 1;
SRL_LG_FRENCH = 2;
SRL_LG_PORTUGUESE = 3;
SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH;

{*******************************************************************************
procedure UpdateWorlds;
by: mixster
Description: Parses the worlds page into Worlds.INI
*******************************************************************************}
function UpdateWorlds: Boolean;
var
worldList: TWorldArray;
str, Path: string;
tsa, tsb: TStringArray;
W, I, H, Time: Integer;
begin
try
Result := True;
Path := IncludePath + 'SRL\SRL\misc\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);
if (SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH) then
str := ''
else
str := 'l=' + IntToStr(SRL_WORLDPARSE_LANG) + '/';
str := GetPage('http://www.runescape.com/' + str + 'slu.ws?order=WMPLA');
Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
Delete(str, 1, Pos('<tr', str) + 3);
tsa := srl_Explode(str, '<tr');
H := High(tsa);
SetLength(worldList, H + 1);
for I := 0 to H do
with worldList[I] do
begin
tsb := srl_Explode(tsa[I], '<td');
if High(tsb) < 5 then
begin
Writeln('Skipping world "' + IntToStr(I + 1) + '" because explosion didn''t return enough values');
Continue;
end;
PlayerNo := StrToIntDef(Between('>', '<', tsb[2]), 2000);
if (Between('"', '"', tsb[3]) = 'a') or (Between('"', '"', tsb[3]) = 'a d') then
begin
Location := 'Activity';
Activity := Between('>', '<', tsb[3]);
end
else
begin
Location := Between('>', '<', tsb[3]);
Activity := '';
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
begin
Writeln('Invalid world number produced: ' + Prefix);
Writeln('Assuming has suffix, trying again');
str := Replace(Prefix, 'world', '');
Number := StrToIntDef(Copy(str, 1, Length(str) - 1), -1);
if Number = -1 then
Writeln('Failed to gather a world number')
else
Writeln('Succeeded, got ' + IntToStr(Number));
end;
LootShare := Between('"', '"', tsb[4]) = 'd';
QuickChat := Activity = 'Quick Chat';
PvP := Activity = 'PvP World';
Members := Between('"', '"', tsb[5]) = 'm';
end;
//Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
except
Result := False;
//SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
end;
if not Result then Exit;
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, 'Type', BoolToStr(Members), Path);
if (Members) then
WriteINI(Str, 'Type', 'Members', Path)
else
WriteINI(Str, 'Type', 'Free', 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.');
end;

{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle; Edits by Nava2
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
try
H := StrToInt(ReadINI('Worlds', 'High', IncludePath + 'SRL\SRL\misc\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;
SetArrayLength(WorldArray, H + 1);
for i := 1 to H do
if not (ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\Worlds.ini') = '') then
begin
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\worlds.ini');
WorldArray[Hw].Members := (ReadINI('World' + IntToStr(i), 'Type', IncludePath + 'SRL\SRL\misc\worlds.ini') = 'Members');
WorldArray[Hw].LootShare := StrToBool(ReadINI('World' + IntToStr(i), 'Lootshare', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].QuickChat := StrToBool(ReadINI('World' + IntToStr(i), 'Quickchat', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].PVP := StrToBool(ReadINI('World' + IntToStr(i), 'PvP', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].Language := ReadINI('World' + IntToStr(i), 'ServLang', IncludePath + 'SRL\SRL\misc\worlds.ini');
Inc(Hw);
end;
SetArrayLength(WorldArray, Hw);
end;

{*******************************************************************************
function FindWorld(W: integer): Boolean;
by: Narcle, edit by Bionicle1800
Description: Scrolls to area and returns true if world was found
*******************************************************************************}
function FindWorld(W: integer): Boolean;
Var
WPos, SPos, i, x, y, H: integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
Exit;
Result := FindTextTpaEx(16579836, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
if Result then
Exit;
Result := FindTextTpaEx(6618364, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
if Result then
Exit;
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos / (H+1)*100);
if not WorldsOrdered then
begin
Mouse(103, 129, 3, 3, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 101;//101 compensate for randomness
Mouse(698, Round(SPos/100.0*262.0+152), 3, 3, true);

wait(500+Random(100));

Result := FindTextTpaEx(16579836, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
if Result then
Exit;
Result := FindTextTpaEx(6618364, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
end;

{*******************************************************************************
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
by: Narcle
Description: Records World info into TWorld record, also Results true if world
was found
*******************************************************************************}
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
var
xx, yy, x, y, Color: integer;
begin
if (WorldScreen) then
begin
Color := 16579836;//white
if not FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
begin
Color := 6618364;//yellow
if FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
WorldRec.Members := true
else
Exit;
end;
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(138, y-1, 0, StatChars, False, False, 0, 3, Color, 4, False, tr_Digits)), -1);
WorldRec.Activity := Trim(GetTextAtEx(240, y - 1, 0, StatChars, False, False, 0, 3, Color, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 7711612, 600, y-4, 636, y+14);
WorldRec.QuickChat := Pos('uick', WorldRec.Activity) > 0;
WorldRec.PVP := Pos('ounty', WorldRec.Activity) > 0;
Result := (WorldRec.PlayerNo > 0);
end;
end;

{*******************************************************************************
Function SelectWorld(W: Integer): Boolean;
by: Narcle & ZephyrsFury, edit by Bionicle1800
Description: Switches to the specified world. Returns true if successful.
*******************************************************************************}
function SelectWorld(W: integer): boolean;
var
x, y, xx, yy: integer;
WRec: TWorld;
begin
if OpenWorldScreen then
begin
wait(400+random(200));
if FindWorld(W) then
begin
wait(100+random(100));
if GetWorldInfo(W, WRec) then
begin
Writeln('World: '+inttostr(WRec.Number)+', Players: '+inttostr(WRec.PlayerNo)+', Members: '+Booltostr(WRec.Members)+', PvP: '+Booltostr(WRec.PVP));
if not FindTextTpaEx(16579836, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, nothing) then
if not FindTextTpaEx(6618364, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing) then
Exit;
MMouse(x, y, 500, 4);
GetMousePos(x, y);
wait(300);
if FindColor(xx, yy, 6316128, x-20, y-2, x+20, y+2) then
begin
Mouse(x, y, 0, 0, true);//Final click
Wait(300);
if FindColor(xx, yy, 19890, x-20, y-2, x+20, y+2) then
Result := true;
end;
end else
WriteLn('World ' + IntToStr(W) + ' is either OFFLINE or FULL.');
end else
WriteLn('Failed to find World ' + IntToStr(W) + '!');
if (not(Result)) then TypeByte(vk_Escape);
end;
end;

{*******************************************************************************
function RandomWorld(Members, PvP: Boolean): Integer;
by: Narcle & mixster
Description: Returns a random world by paramaters.
*******************************************************************************}
function RandomWorld(Members, PvP: Boolean): Integer;
var
i, H, l: integer;
wArray: TWorldArray;
begin
if High(WorldArray) < 0 then
LoadWorldArrays;
H := High(WorldArray);
SetLength(wArray, H + 1);
for i := 0 to H do
if (WorldArray[i].Members = Members) and (WorldArray[i].PvP = PvP) and (InStrArr(WorldArray[i].Language, ['English', ''], False)) then
begin
wArray[l] := WorldArray[i];
Inc(l);
end;
Result := wArray[random(l)].Number;
end;

{*******************************************************************************
function ChangeWorld(W: Integer): Boolean;
by: Nava2
Description: Changes to world W. Returns True if successful.
*******************************************************************************}

function ChangeWorld(W: Integer): Boolean;
begin
while LoggedIn do LogOut;
Result := SelectWorld(W);
LoginPlayer;
end;

{*******************************************************************************
Procedure OrderWorlds(by: string; Descending: boolean);
by: NaumanAkhlaQ, edit by Bionicle1800
Description: Orders worlds by 'by' in order 'Descending'
Check function for valid params of 'by'
Descending = true means the left button
*******************************************************************************}
Procedure OrderWorlds(by: string; Descending: boolean);
var
ATPA: T2DPointArray;
Arr: array of tstringarray;
TPA: TPointArray;
I: Byte;
TB: TBox;
Begin
Arr := [TStringArray(['world', 'w', 'worlds']), TStringArray(['players', 'pl', 'player']), TStringArray(['activity', 'location', 'loc', 'act']),
TStringArray(['type', 't']), TStringArray(['ls', 'lootshare']), TStringArray(['ping', 'pi'])];
For I := 0 To High(Arr) Do
If InStrArr(Lowercase(By), Arr[i], False) Then
Break;
FindColorsTolerance(TPA, 1074576, 82, 103, 683, 136, 1);
ATPA := SplitTPA(TPA, 2);
SortATPAFromFirstPoint(ATPA, Point(91, 124));
TB := GetTPABounds(ATPA[(I * 2) + Integer(Descending)]);
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;

{*******************************************************************************
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
by: Rasta Magician
Description: Chooses a world by SettingsNames , ordered by SettingsDescending
Takes into account Members and PVP
Check OrderWorlds for valid params for SettingsNames
*******************************************************************************}
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
var
TPA: TPointArray;
i, C : integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
exit;

if length(SettingsNames) <> length(SettingsDescending) then
begin
srl_warn('ChooseWorldBy', 'Arrays are not the same length', warn_AllVersions);
SelectWorld(RandomWorld(Members, PVP));
exit;
end;

for i:= 0 to High(SettingsNames) do
begin
OrderWorlds(SettingsNames[i], SettingsDescending[i]);
wait(1000+random(200));
end;

wait(1500+random(500));
for i:= 0 to 15 do //16 worlds show up in screen
begin
FindColorsTolerance(TPA, 16777215, 182, 150+18*i, 206, 159+18*i, 0);
C := Length(TPA);
if (C = 0)or(C = 66) then //failed detection or full
Continue;

if (Members)xor(GetColor(620, 157+18*i) <> 11316396) then
Continue;

if (PVP)xor(GetColor(589, 156+18*i) <> 1251528) then
Continue;

MouseBox(79, 148+18*i, 685, 165+18*i, 1);

for c := 0 to 4 do
begin
wait(200);
Result := not WorldScreen;
if Result then exit;
end;

end;
Result := false;
writeln('Failed to sort the worlds. Choosing random world. Members: '+BoolToStr(Members)+'; PVP: '+BoolToStr(PVP)+';');
SelectWorld(RandomWorld(Members, PVP));
end;

Wanted

2010-03-04 20:35:37

I'm confused, why are there [resolved] tags on this thread?

i luffs yeww

2010-03-04 20:40:41

He said he wasn't sure if those were right. ;) If they aren't change them.

Bionicle

2010-03-04 20:46:48

From: IceFire908
I'm confused, why are there [resolved] tags on this thread?


I reported my post asking them to be changed…
I'm hella tired, i make mistakes :p

Wanted

2010-03-04 20:52:08

From: bionicle1800
I reported my post asking them to be changed…
I'm hella tired, i make mistakes :p


Fix'd

I'm looking through this and the entire include now systematically. So it may take a while… but when I'm done expect almost everything if not everything that was working before the update to work after this one.

Bionicle

2010-03-05 17:57:46

From: IceFire908
Fix'd

I'm looking through this and the entire include now systematically. So it may take a while… but when I'm done expect almost everything if not everything that was working before the update to work after this one.


K, thanks. The only thing i'm sure is still a problem in WorldSwitcher.scar is GetWorldInfo..i just couldn't get my head around it at my current state of mind :p

E: just realized that I posted this before I updated my srl, on wed it was updated to fix a problem, direct quote from the log, 'Fixed issues where it would search outside the client.'
probably not that big of a deal, I might have even fixed that in here, maybe not, but just sayin' :p

Narcle

2010-03-05 20:54:47

I'm gradually working on this (bored kinda back). I got GetWorldInfo fixed/working. There is only one problem with their new setup and I haven't figured out a work around this yet.

Because "World " in front of the number is gone it now just searches for the number. ie if you are going to world 1 it'll find 1 no matter what… I tried spacing to compensate this but it seems to automatically remove the space from it.

Working on FindWorld atm but its messing up in the calculations… making me mad.

Here's GetWorldInfo, note I removed Location since its now merged.
{*******************************************************************************
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
by: Narcle
Description: Records World info into TWorld record, also Results true if world
was found
*******************************************************************************}
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
var
xx, yy, x, y, Color: integer;
begin
if (WorldScreen) then
begin
Color := 16579836;//white
if not FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
begin
Color := 6618364;//yellow
if FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
WorldRec.Members := true
else
Exit;
end;
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(138, y-1, 0, StatChars, False, False, 0, 3, Color, 4, False, tr_Digits)), -1);
WorldRec.Activity := Trim(GetTextAtEx(240, y - 1, 0, StatChars, False, False, 0, 3, Color, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 7711612, 600, y-4, 636, y+14);
WorldRec.QuickChat := Pos('uick', WorldRec.Activity) > 0;
WorldRec.PVP := Pos('ounty', WorldRec.Activity) > 0;
Result := (WorldRec.PlayerNo > 0);
end;
end;

Bionicle

2010-03-05 21:01:53

From: Narcle
Working on FindWorld atm but its messing up in the calculations… making me mad.


Um..the one I posted works AFAIK, i only tested it a few times though

Narcle

2010-03-05 21:15:35

From: bionicle1800
Um..the one I posted works AFAIK, i only tested it a few times though


Yea its suppose to work as well but for some reason the SPos keeps returning 0. I only changed it a bit so it was more accurate… even did debugging and the worlds array is loading fine.

I'll mess around with it some more.

Edit:
Figured it out. Apparently Simba doesn't like to handle extended internally very well… Just had to rearrange the equation.

Wanted

2010-03-06 00:49:01

From: Narcle
Yea its suppose to work as well but for some reason the SPos keeps returning 0. I only changed it a bit so it was more accurate… even did debugging and the worlds array is loading fine.

I'll mess around with it some more.

Edit:
Figured it out. Apparently Simba doesn't like to handle extended internally very well… Just had to rearrange the equation.


How's this coming? Are you almost done? Maybe post what you have so far so I can help? :o

Narcle

2010-03-06 01:07:40

From: IceFire908
How's this coming? Are you almost done? Maybe post what you have so far so I can help? :o


If we go with Bionicles tabbing functions for Lobby I think we should use constants for selecting. IE PlayerInfo = 1, WorldSelect = 2 etc.

So I can just go
LobbyTab(WorldSelect);

These are my thoughts. Would be nice to get this lobby fully functioning as the options etc. are all there.

Bionicle has most of it done. I have a updated FindWorld that is more accurate with the new screen, as well I'll be modifying a few other things and adding constants for Lobby tabs.

I'll probably continue tomorrow, getting late.

Bionicle

2010-03-06 09:03:34

From: Narcle
If we go with Bionicles tabbing functions for Lobby I think we should use constants for selecting. IE PlayerInfo = 1, WorldSelect = 2 etc.

So I can just go
LobbyTab(WorldSelect);

These are my thoughts. Would be nice to get this lobby fully functioning as the options etc. are all there.

Bionicle has most of it done. I have a updated FindWorld that is more accurate with the new screen, as well I'll be modifying a few other things and adding constants for Lobby tabs.

I'll probably continue tomorrow, getting late.


I'll add those constants in :p ill post it in a bit, just woke up and i'm hungry so i need to get breakfast :p
E: Changed GetLobbyTab so it looks neater and faster, also added the constants and added a failsafe in LobbyTab.
{ const LobbyTab Constants;
Description: Constants representing lobbytab numbers. }

const
PlayerInfo = 1;
WorldSelect = 2;
FriendsList = 3;
ClanChat = 4;
Options = 5;
{*******************************************************************************
function GetLobbyTab: Integer;
By: Bionicle1800
Description: Gets current lobby tab.
*******************************************************************************}
function GetLobbyTab: Integer;
begin
for result := 1 to 5 do
if GetColor(97 + (result-1)*123, 31) = 7375258 then
Exit;
end;

{*******************************************************************************
function LobbyTab(Tab: Integer): Boolean;
By: Bionicle1800
Description: Goes to the lobby tab specified by the integer 'Tab'.
Valid arguments are 1 through 5, as well as PlayerInfo,
WorldSelect, FriendsList, ClanChat and Options.
*******************************************************************************}
function LobbyTab(Tab: Integer): Boolean;
begin
if not InRange(Tab, PlayerInfo, Options) then
begin
Srl_Warn('LobbyTab', 'Tab ' + IntToStr(Tab) + ' is not valid.', warn_AllVersions);
Exit;
end;
result := GetLobbyTab = Tab;
if result then
Exit;
if GetColor(97 + (Tab-1)*123, 31) = 4410194 then
begin
Mouse(97 + (Tab-1)*123, 31, 6, 6, true);
result := true;
end;
end;

Edited first post with this and Narcle's fix for GetWorldInfo

mixster

2010-03-06 09:57:00

UpdateWorlds was (somewhat) recently updated to fix it and upon retesting it seems to still generate what is sensible output, even under Simba after a bit of tweaking!

Wanted

2010-03-06 12:46:51

Still having trouble getting SelectWorld and ChangeWorld to work.

Moved the lobby tab stuff to gametab.scar, haven't committed anything yet.. appears to be working except for those two.

Bionicle

2010-03-06 12:48:27

From: IceFire908
Still having trouble getting SelectWorld and ChangeWorld to work.

Moved the lobby tab stuff to gametab.scar, haven't committed anything yet.. appears to be working except for those two.


Are you using simba? Cause i'm still using scar, and it worked fine yesterday for me…
If you are using simba I can try fixing it in simba.

Wanted

2010-03-06 12:50:05

From: bionicle1800
Are you using simba? Cause i'm still using scar, and it worked fine yesterday for me…
If you are using simba I can try fixing it in simba.


Using SCAR.

Bionicle

2010-03-06 13:13:58

From: IceFire908
Using SCAR.


That's weird..I'll try it again and get back to you..

E:
{*******************************************************************************
function FindWorld(W: integer): Boolean;
by: Narcle, edit by Bionicle1800
Description: Scrolls to area and returns true if world was found
*******************************************************************************}
function FindWorld(W: integer): Boolean;
Var
WPos, SPos, i, x, y, H: integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
Exit;
if not WorldsOrdered then
begin
Mouse(103, 129, 3, 3, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
Result := FindTextTpaEx(16579836, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
if Result then
Exit;
Result := FindTextTpaEx(6618364, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
if Result then
Exit;
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos / (H+1)*100);
if not WorldsOrdered then
begin
Mouse(103, 129, 3, 3, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 101;//101 compensate for randomness
Mouse(698, Round(SPos/100.0*262.0+152), 3, 3, true);

wait(500+Random(100));

Result := FindTextTpaEx(16579836, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
if Result then
Exit;
Result := FindTextTpaEx(6618364, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing);
end;

It seems to only want to work if the starting tab is not the world tab. I'll look further into it when i get back in about half an hour if no one else finds anything..

WorldScreen works, so that has nothing to do with it coming back false..
OpenWorldScreen works aswell, so that also has nothing to do with it coming back false..
I even deleted the if not WorldScreen then at the beginning, and it still wouldn't work. It works when it uses the LobbyTab function it seems.

Wanted

2010-03-06 13:15:45

Find world is working fine, I'm talking about Select world…

Nava2

2010-03-06 13:16:54

Can we please start using Diffs more often.. o.O This is hard to follow without seeing exactly what is being changed.

Bionicle

2010-03-06 13:32:19

From: IceFire908
Find world is working fine, I'm talking about Select world…


I thought FindWorld is what was messing up SelectWorld. Nvm though.

Narcle

2010-03-06 13:41:41

This is what I got and its working flawlessly for me on Simba.

//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ? WorldSwitch routines --//
//-----------------------------------------------------------------//
// * function WorldScreen: Boolean; // by Narcle
// * function OpenWorldScreen: Boolean; // by Nava2
// * function UpdateWorlds: Boolean; // by mixster & Nava2
// * procedure LoadWorldArrays; // by Narcle
// * function FindWorld(W: integer): Boolean; // by Narcle
// * function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean; // by Narcle
// * function SelectWorld(WorldNumber: Integer): Boolean; // by Narcle & ZephyrsFury
// * function RandomWorld(Members, PvP: Boolean): Integer; // by Narcle & mixster
// * function ChangeWorld(W: Integer): Boolean; // by Nava2
// * Procedure OrderWorlds(by: string; Descending: boolean); // by NaumanAkhlaQ
// * Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: TBooleanArray; Members, PVP: boolean): boolean; // by Rasta Magician

type
TWorld = record
Number, PlayerNo: Integer;
Members: Boolean;
Prefix, Location, Activity, Language: String;
LootShare, QuickChat, PVP: Boolean;
end;
TWorldArray = Array of TWorld;

Var
WorldArray: TWorldArray;
WorldsOrdered: Boolean;

{ const LobbyTab Constants;
Description: Constants representing lobbytab numbers. }

const
PlayerInfo = 1;
WorldSelect = 2;
FriendsList = 3;
ClanChat = 4;
Options = 5;

{*******************************************************************************
function WorldScreen: Boolean;
by: Narcle, edit by NaumanAkhlaQ
Description: Returns true if the World screen is open.
*******************************************************************************}
function WorldScreen: Boolean;
begin
Result := FindTextTPA(16777215, 0, 672, 62, 695, 74, 'orld ', StatChars, Nothing);
end;

{*******************************************************************************
function GetLobbyTab: Integer;
By: Bionicle1800
Description: Gets current lobby tab.
*******************************************************************************}
function GetLobbyTab: Integer;
begin
for result := 1 to 5 do
if GetColor(97 + (result-1)*123, 31) = 7375258 then
Exit;
end;

{*******************************************************************************
function LobbyTab(Tab: Integer): Boolean;
By: Bionicle1800
Description: Goes to the lobby tab specified by the integer 'Tab'.
Valid arguments are 1 through 5, as well as PlayerInfo,
WorldSelect, FriendsList, ClanChat and Options.
*******************************************************************************}
function LobbyTab(Tab: Integer): Boolean;
begin
if not InRange(Tab, PlayerInfo, Options) then
begin
Srl_Warn('LobbyTab', 'Tab ' + IntToStr(Tab) + ' is not valid.', warn_AllVersions);
Exit;
end;
result := GetLobbyTab = Tab;
if result then
Exit;
if GetColor(97 + (Tab-1)*123, 31) = 4410194 then
begin
Mouse(97 + (Tab-1)*123, 31, 6, 6, true);
result := true;
end;
end;

{*******************************************************************************
function OpenWorldScreen: Boolean;
by: Bionicle1800
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
begin
if LobbyTab(2) then
if WorldScreen then
result := true;
end;

const
SRL_LG_ENGLISH = 0;
SRL_LG_GERMAN = 1;
SRL_LG_FRENCH = 2;
SRL_LG_PORTUGUESE = 3;
SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH;

{*******************************************************************************
procedure UpdateWorlds;
by: mixster
Description: Parses the worlds page into Worlds.INI
*******************************************************************************}
function UpdateWorlds: Boolean;
var
worldList: TWorldArray;
str, Path: string;
tsa, tsb: TStringArray;
W, I, H, Time: Integer;
begin
try
Result := True;
Path := IncludePath + 'SRL\SRL\misc\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);
if (SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH) then
str := ''
else
str := 'l=' + IntToStr(SRL_WORLDPARSE_LANG) + '/';
str := GetPage('http://www.runescape.com/' + str + 'slu.ws?order=WMPLA');
Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
Delete(str, 1, Pos('<tr', str) + 3);
tsa := srl_Explode(str, '<tr');
H := High(tsa);
SetLength(worldList, H + 1);
for I := 0 to H do
with worldList[I] do
begin
tsb := srl_Explode(tsa[I], '<td');
if High(tsb) < 5 then
begin
Writeln('Skipping world "' + IntToStr(I + 1) + '" because explosion didn''t return enough values');
Continue;
end;
PlayerNo := StrToIntDef(Between('>', '<', tsb[2]), 2000);
if (Between('"', '"', tsb[3]) = 'a') or (Between('"', '"', tsb[3]) = 'a d') then
begin
Location := 'Activity';
Activity := Between('>', '<', tsb[3]);
end
else
begin
Location := Between('>', '<', tsb[3]);
Activity := '';
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
begin
Writeln('Invalid world number produced: ' + Prefix);
Writeln('Assuming has suffix, trying again');
str := Replace(Prefix, 'world', '');
Number := StrToIntDef(Copy(str, 1, Length(str) - 1), -1);
if Number = -1 then
Writeln('Failed to gather a world number')
else
Writeln('Succeeded, got ' + IntToStr(Number));
end;
LootShare := Between('"', '"', tsb[4]) = 'd';
QuickChat := Activity = 'Quick Chat';
PvP := Activity = 'PvP World';
Members := Between('"', '"', tsb[5]) = 'm';
end;
//Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
except
Result := False;
//SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
end;
if not Result then Exit;
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, 'Type', BoolToStr(Members), Path);
if (Members) then
WriteINI(Str, 'Type', 'Members', Path)
else
WriteINI(Str, 'Type', 'Free', 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.');
end;

{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle; Edits by Nava2
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
try
H := StrToInt(ReadINI('Worlds', 'High', IncludePath + 'SRL\SRL\misc\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;
SetArrayLength(WorldArray, H + 1);
for i := 1 to H do
if not (ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\Worlds.ini') = '') then
begin
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\worlds.ini');
WorldArray[Hw].Members := (ReadINI('World' + IntToStr(i), 'Type', IncludePath + 'SRL\SRL\misc\worlds.ini') = 'Members');
WorldArray[Hw].LootShare := StrToBool(ReadINI('World' + IntToStr(i), 'Lootshare', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].QuickChat := StrToBool(ReadINI('World' + IntToStr(i), 'Quickchat', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].PVP := StrToBool(ReadINI('World' + IntToStr(i), 'PvP', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].Language := ReadINI('World' + IntToStr(i), 'ServLang', IncludePath + 'SRL\SRL\misc\worlds.ini');
Inc(Hw);
end;
SetArrayLength(WorldArray, Hw);
end;

{*******************************************************************************
function FindWorld(W: integer): Boolean;
by: Narcle
Description: Scrolls to area and returns true if world was found
*******************************************************************************}
function FindWorld(W: integer): Boolean;
Var
WPos, SPos, i, x, y, H: integer;
begin
if not WorldScreen then
Exit;
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1));
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true);

wait(300+Random(100));

Result := FindTextTpaEx(16579836, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing) or
FindTextTpaEx(6618364, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing);
end;

{*******************************************************************************
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
by: Narcle
Description: Records World info into TWorld record, also Results true if world
was found
*******************************************************************************}
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
var
xx, yy, x, y, Color: integer;
begin
if (WorldScreen) then
begin
Color := 16579836;//white
if not FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
begin
Color := 6618364;//yellow
if FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
WorldRec.Members := true
else
Exit;
end;
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(138, y-1, 0, StatChars, False, False, 0, 3, Color, 4, False, tr_Digits)), -1);
WorldRec.Activity := Trim(GetTextAtEx(240, y - 1, 0, StatChars, False, False, 0, 3, Color, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 7711612, 600, y-4, 636, y+14);
WorldRec.QuickChat := Pos('uick', WorldRec.Activity) > 0;
WorldRec.PVP := Pos('ounty', WorldRec.Activity) > 0;
Result := (WorldRec.PlayerNo > 0);
end;
end;

{*******************************************************************************
Function SelectWorld(W: Integer): Boolean;
by: Narcle & ZephyrsFury
Description: Switches to the specified world. Returns true if successful.
*******************************************************************************}
function SelectWorld(W: integer): boolean;
var
x, y, xx, yy, T: integer;
WRec: TWorld;
begin
if OpenWorldScreen then
begin
wait(400+random(200));
if FindWorld(W) then
begin
wait(100+random(100));
if GetWorldInfo(W, WRec) then
begin
Writeln('World: '+inttostr(WRec.Number)+', Players: '+inttostr(WRec.PlayerNo)+', Members: '+Booltostr(WRec.Members)+', PvP: '+Booltostr(WRec.PVP));
If not FindTextTpaEx(16579836, 0, 84, 134, 134, 440, x, y, ' '+inttostr(W)+' ', StatChars, Nothing) then
FindTextTpaEx(6618364, 0, 84, 134, 134, 440, x, y, ' '+inttostr(W)+' ', StatChars, Nothing);
if y > 0 then
begin
MMouse(x, y, 500, 4);
GetMousePos(x, y);
wait(400+random(100));
writeln('y='+inttostr(y));
if FindColor(xx, yy, 6316128, x-20, y-2, x+20, y+2) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
T := GetSystemTime;
if FindColor(xx, yy, 19890, x-20, y-2, x+20, y+2) then
begin
Writeln('World '+inttostr(W)+' selected.');
Result := true;
end;
end;
end;
end else
WriteLn('World ' + IntToStr(W) + ' is either OFFLINE or FULL.');
end else
WriteLn('Failed to find World ' + IntToStr(W) + '!');
if (not(Result)) then TypeByte(vk_Escape);
end;
end;

{*******************************************************************************
function RandomWorld(Members, PvP: Boolean): Integer;
by: Narcle & mixster
Description: Returns a random world by paramaters.
*******************************************************************************}
function RandomWorld(Members, PvP: Boolean): Integer;
var
i, H, l: integer;
wArray: TWorldArray;
begin
if High(WorldArray) < 0 then
LoadWorldArrays;
H := High(WorldArray);
SetLength(wArray, H + 1);
for i := 0 to H do
if (WorldArray[i].Members = Members) and (WorldArray[i].PvP = PvP) and (InStrArr(WorldArray[i].Language, ['English', ''], False)) then
begin
wArray[l] := WorldArray[i];
Inc(l);
end;
Result := wArray[random(l)].Number;
end;

{*******************************************************************************
function ChangeWorld(W: Integer): Boolean;
by: Nava2
Description: Changes to world W. Returns True if successful.
*******************************************************************************}

function ChangeWorld(W: Integer): Boolean;
begin
while LoggedIn do LogOut;
Result := SelectWorld(W);
LoginPlayer;
end;

{*******************************************************************************
Procedure OrderWorlds(by: string; Descending: boolean);
by: NaumanAkhlaQ
Description: Orders worlds by 'by' in order 'Descending'
Check function for valid params of 'by'
Descending = true means the left button
*******************************************************************************}
Procedure OrderWorlds(by: string; Descending: boolean);
var
ATPA: T2DPointArray;
Arr: array of tstringarray;
TPA: TPointArray;
I: Byte;
TB: TBox;
Begin
Arr := [TStringArray(['world', 'w', 'worlds']), TStringArray(['players', 'pl', 'player']), TStringArray(['activity', 'location', 'loc', 'act']),
TStringArray(['ls', 'lootshare']), TStringArray(['type', 't']), TStringArray(['ping', 'pi'])];
For I := 0 To High(Arr) Do
If InStrArr(Lowercase(By), Arr[i], False) Then
Break;
FindColorsTolerance(TPA, 1074576, 0, 0, 716, 141, 1);
ATPA := SplitTPA(TPA, 2);
SortATPAFromFirstPoint(ATPA, Point(91, 124));
TB := GetTPABounds(ATPA[(I * 2) + Integer(Descending)]);
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;

{*******************************************************************************
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
by: Rasta Magician
Description: Chooses a world by SettingsNames , ordered by SettingsDescending
Takes into account Members and PVP
Check OrderWorlds for valid params for SettingsNames
*******************************************************************************}
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
var
TPA: TPointArray;
i, C : integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
exit;

if length(SettingsNames) <> length(SettingsDescending) then
begin
srl_warn('ChooseWorldBy', 'Arrays are not the same length', warn_AllVersions);
SelectWorld(RandomWorld(Members, PVP));
exit;
end;

for i:= 0 to High(SettingsNames) do
begin
OrderWorlds(SettingsNames[i], SettingsDescending[i]);
wait(1000+random(200));
end;

wait(1500+random(500));
for i:= 0 to 15 do //16 worlds show up in screen
begin
FindColorsTolerance(TPA, 16777215, 182, 150+18*i, 206, 159+18*i, 0);
C := Length(TPA);
if (C = 0)or(C = 66) then //failed detection or full
Continue;

if (Members)xor(GetColor(620, 157+18*i) <> 11316396) then
Continue;

if (PVP)xor(GetColor(589, 156+18*i) <> 1251528) then
Continue;

MouseBox(79, 148+18*i, 685, 165+18*i, 1);

for c := 0 to 4 do
begin
wait(200);
Result := not WorldScreen;
if Result then exit;
end;

end;
Result := false;
writeln('Failed to sort the worlds. Choosing random world. Members: '+BoolToStr(Members)+'; PVP: '+BoolToStr(PVP)+';');
SelectWorld(RandomWorld(Members, PVP));
end;

Note I didn't test ChangeWorld as I haven't edited Login player functions yet.
Edit:
Nor did I change ChangeWorld :P
And oops I left a debug in there.

Wanted

2010-03-06 13:55:21

Still just scrolls, finds, doesn't click the world, and then enters game.

Bionicle

2010-03-06 14:26:23

K, i found it. traced it all down and found out the color for the mouse coords were wrong when i shortened the code for GetLobbyTab. This is only part of the problem, but it is a start.
(E2)
Tested, works.

@ IceFire, i'm getting the same problem, and I have found out where it is at, but I can't seem to fix it.
        if not FindTextTpaEx(16579836, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, nothing) then
if not FindTextTpaEx(6618364, 0, 103, 135, 122, 438, x, y, IntToStr(W), StatChars, Nothing) then
Exit;
here. it can't find either the white nor the yellow and exits.

E: K fix'd.
(E2)
I think i just expanded the box a bit around the searching area for the text, but i was fooling around with it for a while :p
So that's all that needs to be fixed?

E2:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ? WorldSwitch routines --//
//-----------------------------------------------------------------//
// * function WorldScreen: Boolean; // by Narcle
// * function GetLobbyTab: Boolean; // by Bionicle1800
// * function LobbyTab: Boolean; // by Bionicle1800
// * function OpenWorldScreen: Boolean; // by Bionicle1800
// * function UpdateWorlds: Boolean; // by mixster & Nava2
// * procedure LoadWorldArrays; // by Narcle
// * function FindWorld(W: integer): Boolean; // by Narcle
// * function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean; // by Narcle
// * function SelectWorld(WorldNumber: Integer): Boolean; // by Narcle & ZephyrsFury
// * function RandomWorld(Members, PvP: Boolean): Integer; // by Narcle & mixster
// * function ChangeWorld(W: Integer): Boolean; // by Nava2
// * Procedure OrderWorlds(by: string; Descending: boolean); // by NaumanAkhlaQ
// * Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: TBooleanArray; Members, PVP: boolean): boolean; // by Rasta Magician

type
TWorld = record
Number, PlayerNo: Integer;
Members: Boolean;
Prefix, Location, Activity, Language: String;
LootShare, QuickChat, PVP: Boolean;
end;
TWorldArray = Array of TWorld;

Var
WorldArray: TWorldArray;
WorldsOrdered: Boolean;

{ const LobbyTab Constants;
Description: Constants representing lobbytab numbers. }

const
PlayerInfo = 1;
WorldSelect = 2;
FriendsList = 3;
ClanChat = 4;
Options = 5;

{*******************************************************************************
function WorldScreen: Boolean;
by: Narcle, edit by NaumanAkhlaQ
Description: Returns true if the World screen is open.
*******************************************************************************}
function WorldScreen: Boolean;
begin
Result := FindTextTPA(16777215, 0, 672, 62, 695, 74, 'orld ', StatChars, Nothing);
end;

{*******************************************************************************
function GetLobbyTab: Integer;
By: Bionicle1800
Description: Gets current lobby tab.
*******************************************************************************}
function GetLobbyTab: Integer;
begin
for result := 1 to 5 do
if GetColor(97 + (result-1)*123, 31) = 7441051 then
Exit;
end;

{*******************************************************************************
function LobbyTab(Tab: Integer): Boolean;
By: Bionicle1800
Description: Goes to the lobby tab specified by the integer 'Tab'.
Valid arguments are 1 through 5, as well as PlayerInfo,
WorldSelect, FriendsList, ClanChat and Options.
*******************************************************************************}
function LobbyTab(Tab: Integer): Boolean;
begin
if not InRange(Tab, PlayerInfo, Options) then
begin
Srl_Warn('LobbyTab', 'Tab ' + IntToStr(Tab) + ' is not valid.', warn_AllVersions);
Exit;
end;
result := GetLobbyTab = Tab;
if result then
Exit;
if GetColor(97 + (Tab-1)*123, 31) = 4410194 then
begin
Mouse(97 + (Tab-1)*123, 31, 6, 6, true);
result := true;
end;
end;

{*******************************************************************************
function OpenWorldScreen: Boolean;
by: Bionicle1800
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
begin
if LobbyTab(2) then
if WorldScreen then
result := true;
end;

const
SRL_LG_ENGLISH = 0;
SRL_LG_GERMAN = 1;
SRL_LG_FRENCH = 2;
SRL_LG_PORTUGUESE = 3;
SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH;

{*******************************************************************************
procedure UpdateWorlds;
by: mixster
Description: Parses the worlds page into Worlds.INI
*******************************************************************************}
function UpdateWorlds: Boolean;
var
worldList: TWorldArray;
str, Path: string;
tsa, tsb: TStringArray;
W, I, H, Time: Integer;
begin
try
Result := True;
Path := IncludePath + 'SRL\SRL\misc\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);
if (SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH) then
str := ''
else
str := 'l=' + IntToStr(SRL_WORLDPARSE_LANG) + '/';
str := GetPage('http://www.runescape.com/' + str + 'slu.ws?order=WMPLA');
Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
Delete(str, 1, Pos('<tr', str) + 3);
tsa := srl_Explode(str, '<tr');
H := High(tsa);
SetLength(worldList, H + 1);
for I := 0 to H do
with worldList[I] do
begin
tsb := srl_Explode(tsa[I], '<td');
if High(tsb) < 5 then
begin
Writeln('Skipping world "' + IntToStr(I + 1) + '" because explosion didn''t return enough values');
Continue;
end;
PlayerNo := StrToIntDef(Between('>', '<', tsb[2]), 2000);
if (Between('"', '"', tsb[3]) = 'a') or (Between('"', '"', tsb[3]) = 'a d') then
begin
Location := 'Activity';
Activity := Between('>', '<', tsb[3]);
end
else
begin
Location := Between('>', '<', tsb[3]);
Activity := '';
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
begin
Writeln('Invalid world number produced: ' + Prefix);
Writeln('Assuming has suffix, trying again');
str := Replace(Prefix, 'world', '');
Number := StrToIntDef(Copy(str, 1, Length(str) - 1), -1);
if Number = -1 then
Writeln('Failed to gather a world number')
else
Writeln('Succeeded, got ' + IntToStr(Number));
end;
LootShare := Between('"', '"', tsb[4]) = 'd';
QuickChat := Activity = 'Quick Chat';
PvP := Activity = 'PvP World';
Members := Between('"', '"', tsb[5]) = 'm';
end;
//Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
except
Result := False;
//SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
end;
if not Result then Exit;
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, 'Type', BoolToStr(Members), Path);
if (Members) then
WriteINI(Str, 'Type', 'Members', Path)
else
WriteINI(Str, 'Type', 'Free', 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.');
end;

{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle; Edits by Nava2
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
try
H := StrToInt(ReadINI('Worlds', 'High', IncludePath + 'SRL\SRL\misc\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;
SetArrayLength(WorldArray, H + 1);
for i := 1 to H do
if not (ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\Worlds.ini') = '') then
begin
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\worlds.ini');
WorldArray[Hw].Members := (ReadINI('World' + IntToStr(i), 'Type', IncludePath + 'SRL\SRL\misc\worlds.ini') = 'Members');
WorldArray[Hw].LootShare := StrToBool(ReadINI('World' + IntToStr(i), 'Lootshare', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].QuickChat := StrToBool(ReadINI('World' + IntToStr(i), 'Quickchat', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].PVP := StrToBool(ReadINI('World' + IntToStr(i), 'PvP', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].Language := ReadINI('World' + IntToStr(i), 'ServLang', IncludePath + 'SRL\SRL\misc\worlds.ini');
Inc(Hw);
end;
SetArrayLength(WorldArray, Hw);
end;

{*******************************************************************************
function FindWorld(W: integer): Boolean;
by: Narcle
Description: Scrolls to area and returns true if world was found
*******************************************************************************}
function FindWorld(W: integer): Boolean;
Var
WPos, SPos, i, x, y, H: integer;
begin
if not WorldScreen then
Exit;
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1));
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true);

wait(300+Random(100));

Result := FindTextTpaEx(16579836, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing) or
FindTextTpaEx(6618364, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing);
end;

{*******************************************************************************
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
by: Narcle
Description: Records World info into TWorld record, also Results true if world
was found
*******************************************************************************}
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
var
xx, yy, x, y, Color: integer;
begin
if (WorldScreen) then
begin
Color := 16579836;//white
if not FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
begin
Color := 6618364;//yellow
if FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
WorldRec.Members := true
else
Exit;
end;
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(138, y-1, 0, StatChars, False, False, 0, 3, Color, 4, False, tr_Digits)), -1);
WorldRec.Activity := Trim(GetTextAtEx(240, y - 1, 0, StatChars, False, False, 0, 3, Color, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 7711612, 600, y-4, 636, y+14);
WorldRec.QuickChat := Pos('uick', WorldRec.Activity) > 0;
WorldRec.PVP := Pos('ounty', WorldRec.Activity) > 0;
Result := (WorldRec.PlayerNo > 0);
end;
end;

{*******************************************************************************
Function SelectWorld(W: Integer): Boolean;
by: Narcle & ZephyrsFury, edit by Bionicle1800
Description: Switches to the specified world. Returns true if successful.
*******************************************************************************}
function SelectWorld(W: integer): boolean;
var
x, y, xx, yy: integer;
WRec: TWorld;
begin
if OpenWorldScreen then
begin
wait(400+random(200));
if FindWorld(W) then
begin
wait(100+random(100));
if GetWorldInfo(W, WRec) then
begin
Writeln('World: '+inttostr(WRec.Number)+', Players: '+inttostr(WRec.PlayerNo)+', Members: '+Booltostr(WRec.Members)+', PvP: '+Booltostr(WRec.PVP));
if not FindTextTpaEx(16579836, 0, 102, 135, 133, 438, x, y, IntToStr(W), StatChars, nothing) then
if not FindTextTpaEx(6618364, 0, 102, 135, 133, 438, x, y, IntToStr(W), StatChars, nothing) then
Exit;
MMouse(x, y, 500, 4);
GetMousePos(x, y);
wait(300);
if FindColor(xx, yy, 6316128, x-20, y-2, x+20, y+2) then
begin
Mouse(x, y, 0, 0, true);//Final click
Wait(300);
if FindColor(xx, yy, 19890, x-20, y-2, x+20, y+2) then
Result := true;
end;
end else
WriteLn('World ' + IntToStr(W) + ' is either OFFLINE or FULL.');
end else
WriteLn('Failed to find World ' + IntToStr(W) + '!');
if (not(Result)) then TypeByte(vk_Escape);
end;
end;

{*******************************************************************************
function RandomWorld(Members, PvP: Boolean): Integer;
by: Narcle & mixster
Description: Returns a random world by paramaters.
*******************************************************************************}
function RandomWorld(Members, PvP: Boolean): Integer;
var
i, H, l: integer;
wArray: TWorldArray;
begin
if High(WorldArray) < 0 then
LoadWorldArrays;
H := High(WorldArray);
SetLength(wArray, H + 1);
for i := 0 to H do
if (WorldArray[i].Members = Members) and (WorldArray[i].PvP = PvP) and (InStrArr(WorldArray[i].Language, ['English', ''], False)) then
begin
wArray[l] := WorldArray[i];
Inc(l);
end;
Result := wArray[random(l)].Number;
end;

{*******************************************************************************
function ChangeWorld(W: Integer): Boolean;
by: Nava2
Description: Changes to world W. Returns True if successful.
*******************************************************************************}

function ChangeWorld(W: Integer): Boolean;
begin
while LoggedIn do LogOut;
Result := SelectWorld(W);
LoginPlayer;
end;

{*******************************************************************************
Procedure OrderWorlds(by: string; Descending: boolean);
by: NaumanAkhlaQ
Description: Orders worlds by 'by' in order 'Descending'
Check function for valid params of 'by'
Descending = true means the left button
*******************************************************************************}
Procedure OrderWorlds(by: string; Descending: boolean);
var
ATPA: T2DPointArray;
Arr: array of tstringarray;
TPA: TPointArray;
I: Byte;
TB: TBox;
Begin
Arr := [TStringArray(['world', 'w', 'worlds']), TStringArray(['players', 'pl', 'player']), TStringArray(['activity', 'location', 'loc', 'act']),
TStringArray(['ls', 'lootshare']), TStringArray(['type', 't']), TStringArray(['ping', 'pi'])];
For I := 0 To High(Arr) Do
If InStrArr(Lowercase(By), Arr[i], False) Then
Break;
FindColorsTolerance(TPA, 1074576, 0, 0, 716, 141, 1);
ATPA := SplitTPA(TPA, 2);
SortATPAFromFirstPoint(ATPA, Point(91, 124));
TB := GetTPABounds(ATPA[(I * 2) + Integer(Descending)]);
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;

{*******************************************************************************
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
by: Rasta Magician
Description: Chooses a world by SettingsNames , ordered by SettingsDescending
Takes into account Members and PVP
Check OrderWorlds for valid params for SettingsNames
*******************************************************************************}
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
var
TPA: TPointArray;
i, C : integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
exit;

if length(SettingsNames) <> length(SettingsDescending) then
begin
srl_warn('ChooseWorldBy', 'Arrays are not the same length', warn_AllVersions);
SelectWorld(RandomWorld(Members, PVP));
exit;
end;

for i:= 0 to High(SettingsNames) do
begin
OrderWorlds(SettingsNames[i], SettingsDescending[i]);
wait(1000+random(200));
end;

wait(1500+random(500));
for i:= 0 to 15 do //16 worlds show up in screen
begin
FindColorsTolerance(TPA, 16777215, 182, 150+18*i, 206, 159+18*i, 0);
C := Length(TPA);
if (C = 0)or(C = 66) then //failed detection or full
Continue;

if (Members)xor(GetColor(620, 157+18*i) <> 11316396) then
Continue;

if (PVP)xor(GetColor(589, 156+18*i) <> 1251528) then
Continue;

MouseBox(79, 148+18*i, 685, 165+18*i, 1);

for c := 0 to 4 do
begin
wait(200);
Result := not WorldScreen;
if Result then exit;
end;

end;
Result := false;
writeln('Failed to sort the worlds. Choosing random world. Members: '+BoolToStr(Members)+'; PVP: '+BoolToStr(PVP)+';');
SelectWorld(RandomWorld(Members, PVP));
end;

Wanted

2010-03-06 14:46:07

Same problem.

Bionicle

2010-03-06 14:55:19

From: IceFire908
Same problem.


Restart SCAR?
Cause it works for me..
program New;
{.include srl/srl.scar}
begin
SetupSRL;
ActivateClient;
If SelectWorld(50) Then
Writeln('Did it :)')
Else
Writeln('Didnt to it :(');
end.
Successfully compiled (7444 ms)
SRL Compiled in 47 msec
World: 50, Players: 919, Members: False, PvP: False
Did it :)
Successfully executed

Wanted

2010-03-06 14:58:33

Just for you then, it starts to work now after Narcle told me to change GetWorldInfo to this

http://pastebin.org/102405

not sure if he's done yet with that… I haven't tested if this works for all worlds yet, but in combination with the last WorldSwitch.scar you posted and that it seems to work.

Bionicle

2010-03-06 15:02:28

From: IceFire908
Just for you then, it starts to work now after Narcle told me to change GetWorldInfo to this

http://pastebin.org/102405

not sure if he's done yet with that… I haven't tested if this works for all worlds yet, but in combination with the last WorldSwitch.scar you posted and that it seems to work.


So does anything else need to be fixed or is that it?

Wanted

2010-03-06 15:06:02

Well there's a huge dilemma right now because in the past everything has been LogOut -> Switch Worlds -> Login

and now it's

LogOut -> Login To Lobby -> Switch Worlds -> Click Play

So Loginplayer is messed, and everything in relation to LogInPlayer and Switchworlds needs to arranged accordingly, usually when making a change like this it is polled by active devs to decide the most popular way of doing it.

Any ideas?

Bionicle

2010-03-06 15:09:09

From: IceFire908
Well there's a huge dilemma right now because in the past everything has been LogOut -> Switch Worlds -> Login

and now it's

LogOut -> Login To Lobby -> Switch Worlds -> Click Play

So Loginplayer is messed, and everything in relation to LogInPlayer and Switchworlds needs to arranged accordingly, usually when making a change like this it is polled by active devs to decide the most popular way of doing it.

Any ideas?


Wouldn't it be
Exit To Lobby (basically the old LogOut) -> Switch Worlds -> Click Play

E: Why don't we make a ClickToPlay function along side LoginPlayer? That way when you log out to switch worlds, instead of calling LoginPlayer again, you do ClickToPlay?
could be something like:
function ClickToPlay: Boolean;
begin
if LobbyTab(PlayerInfo) Then
if GetColor(*, *) = ****** then //color/coords for the click to play box
begin
Mouse(***, ***, ***, ***, 1); //coords of the click to play box
result := true;
end;
end;

Wanted

2010-03-06 15:10:29

From: bionicle1800
Wouldn't it be
Exit To Lobby (basically the old LogOut) -> Switch Worlds -> Click Play


Not the point.

Login player takes you from the front screen to ingame, and switchworlds needs to be between that.

Narcle

2010-03-06 15:12:04

I think we might actually need a Click to play function it would be used for both LoginPlayer and world switching. I think when you switch worlds you expect it to completely switch worlds and click play…

We'll have to talk about it and see how we'll do LoginPlayers etc. like Icefire said.

Bionicle

2010-03-06 15:19:14

From: Narcle
I think we might actually need a Click to play function it would be used for both LoginPlayer and world switching. I think when you switch worlds you expect it to completely switch worlds and click play…

We'll have to talk about it and see how we'll do LoginPlayers etc. like Icefire said.


Aha, see my edit. I was making that before I saw this btw :p

Wanted

2010-03-06 15:21:15

Here's what I'm thinking

We add a new type to the player record


WorldInfo: TBooleanArray;

Players[0].WorldInfo := [RandomWorld, Members, PVP];

then in LoginPlayer we have

if (Length(Players[CurrentPlayer].WorldInfo) = 3) then
begin
if (Players[CurrentPlayer].WorldInfo[1]) then
ClickRightLogin
else
ClickLeftLogin;
if (Players[CurrentPlayer].WorldInfo[0]) then
ChangeWorld(RandomWorld(Players[CurrentPlayer].WorldInfo[1], Players[CurrentPlayer].WorldInfo[2]));
end
else
ClickLeftLogin;

No need for click to play.

Bionicle

2010-03-06 15:24:33

function ClickToPlay: Boolean;
begin
if LobbyTab(PlayerInfo) then
if GetColor(468, 452) = 6931174 then
begin
MouseBox(74, 446, 568, 477, 1);
result := true;
end;
end;

Just cause i made that before i saw icefire's post :/

Wanted

2010-03-08 19:49:18

Worldswitcher.scar so far is as below

There is a problem with the world# -> scroll cord maths that I can't seem to crack, Narcle help pl-0x?? (SCAR/simba is irrelevant in this case)

Also, the text clicking for the worlds stopped working as well. (using SCAR)

I haven't tested simba, and I don't intent to until I get SCAR's working first.

//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ? WorldSwitch routines --//
//-----------------------------------------------------------------//
// * function WorldScreen: Boolean; // by Narcle
// * function OpenWorldScreen: Boolean; // by Bionicle1800
// * function UpdateWorlds: Boolean; // by mixster & Nava2
// * procedure LoadWorldArrays; // by Narcle
// * function FindWorld(W: integer): Boolean; // by Narcle
// * function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean; // by Narcle
// * function WS_CurrentWorld(var World: Integer): Boolean; // by IceFire908
// * function SelectWorld(WorldNumber: Integer): Boolean; // by Narcle & ZephyrsFury
// * function RandomWorld(Members, PvP: Boolean): Integer; // by Narcle & mixster
// * function ChangeWorld(W: Integer): Boolean; // by Nava2
// * Procedure OrderWorlds(by: string; Descending: boolean); // by NaumanAkhlaQ
// * Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: TBooleanArray; Members, PVP: boolean): boolean; // by Rasta Magician

type
TWorld = record
Number, PlayerNo: Integer;
Members: Boolean;
Prefix, Location, Activity, Language: String;
LootShare, QuickChat, PVP: Boolean;
end;
TWorldArray = Array of TWorld;

Var
WorldArray: TWorldArray;
WorldsOrdered: Boolean;

function ExitToLobby: Boolean; forward;
procedure LoginPlayer; forward;

{*******************************************************************************
function WorldScreen: Boolean;
by: IceFire908
Description: Returns true if the World screen is open.
*******************************************************************************}
function WorldScreen: Boolean;
begin
Result := (GetLobbyTab = L_WorldSelect);
end;

{*******************************************************************************
function OpenWorldScreen: Boolean;
by: Bionicle1800
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
begin
if LobbyTab(2) then
if WorldScreen then
result := true;
end;

const
SRL_LG_ENGLISH = 0;
SRL_LG_GERMAN = 1;
SRL_LG_FRENCH = 2;
SRL_LG_PORTUGUESE = 3;
SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH;

{*******************************************************************************
procedure UpdateWorlds;
by: mixster
Description: Parses the worlds page into Worlds.INI
*******************************************************************************}
function UpdateWorlds: Boolean;
var
worldList: TWorldArray;
str, Path: string;
tsa, tsb: TStringArray;
W, I, H, Time: Integer;
begin
try
Result := True;
Path := IncludePath + 'SRL\SRL\misc\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);
if (SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH) then
str := ''
else
str := 'l=' + IntToStr(SRL_WORLDPARSE_LANG) + '/';
str := GetPage('http://www.runescape.com/' + str + 'slu.ws?order=WMPLA');
Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
Delete(str, 1, Pos('<tr', str) + 3);
tsa := srl_Explode(str, '<tr');
H := High(tsa);
SetLength(worldList, H + 1);
for I := 0 to H do
with worldList[I] do
begin
tsb := srl_Explode(tsa[I], '<td');
if High(tsb) < 5 then
begin
Writeln('Skipping world "' + IntToStr(I + 1) + '" because explosion didn''t return enough values');
Continue;
end;
PlayerNo := StrToIntDef(Between('>', '<', tsb[2]), 2000);
if (Between('"', '"', tsb[3]) = 'a') or (Between('"', '"', tsb[3]) = 'a d') then
begin
Location := 'Activity';
Activity := Between('>', '<', tsb[3]);
end
else
begin
Location := Between('>', '<', tsb[3]);
Activity := '';
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
begin
Writeln('Invalid world number produced: ' + Prefix);
Writeln('Assuming has suffix, trying again');
str := Replace(Prefix, 'world', '');
Number := StrToIntDef(Copy(str, 1, Length(str) - 1), -1);
if Number = -1 then
Writeln('Failed to gather a world number')
else
Writeln('Succeeded, got ' + IntToStr(Number));
end;
LootShare := Between('"', '"', tsb[4]) = 'd';
QuickChat := Activity = 'Quick Chat';
PvP := Activity = 'PvP World';
Members := Between('"', '"', tsb[5]) = 'm';
end;
//Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
except
Result := False;
//SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
end;
if not Result then Exit;
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, 'Type', BoolToStr(Members), Path);
if (Members) then
WriteINI(Str, 'Type', 'Members', Path)
else
WriteINI(Str, 'Type', 'Free', 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.');
end;

{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle; Edits by Nava2
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
try
H := StrToInt(ReadINI('Worlds', 'High', IncludePath + 'SRL\SRL\misc\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;
SetArrayLength(WorldArray, H + 1);
for i := 1 to H do
if not (ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\Worlds.ini') = '') then
begin
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\worlds.ini');
WorldArray[Hw].Members := (ReadINI('World' + IntToStr(i), 'Type', IncludePath + 'SRL\SRL\misc\worlds.ini') = 'Members');
WorldArray[Hw].LootShare := StrToBool(ReadINI('World' + IntToStr(i), 'Lootshare', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].QuickChat := StrToBool(ReadINI('World' + IntToStr(i), 'Quickchat', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].PVP := StrToBool(ReadINI('World' + IntToStr(i), 'PvP', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].Language := ReadINI('World' + IntToStr(i), 'ServLang', IncludePath + 'SRL\SRL\misc\worlds.ini');
Inc(Hw);
end;
SetArrayLength(WorldArray, Hw);
end;

{*******************************************************************************
function WS_CurrentWorld(var World: Integer): Boolean;
by: IceFire908
Description: Results true if the current world is members,returns world number.
World returns -1 if failed. Only works at world screen.
*******************************************************************************}

function WS_CurrentWorld(var World: Integer): Boolean;
var
P: TPoint;
begin
World := -1;
if (not (WorldScreen)) then
Exit;
if (IsTextInAreaEx(618, 74, 705, 96, P.X, P.Y, 'orld', 0, SmallChars, False, False, 0, 1, clWhite)) then
World := StrToIntDef(GetNumbers(Trim(GetTextAtEx(P.X, P.Y, 0, SmallChars, False, False, 0, 1, clWhite, 15, False, tr_AllChars))), -1);
Result := SimilarColors(GetColor(645, 83), 3141117, 15);
end;

{*******************************************************************************
function FindWorld(W: integer): Boolean;
by: Narcle
Description: Scrolls to area and returns true if world was found
*******************************************************************************}
function FindWorld(W: integer): Boolean;
Var
WPos, SPos, i, x, y, H, CurW: integer;
begin
if not WorldScreen then
Exit;
WS_CurrentWorld(CurW);
if (W = CurW) then
begin
Result := True;
WriteLn('Already on world ' + IntToStr(W));
Exit;
end;
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1));
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true);

wait(300+Random(100));

Result := FindTextTpaEx(16579836, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing) or
FindTextTpaEx(6618364, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing);
end;

{*******************************************************************************
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
by: Narcle
Description: Records World info into TWorld record, also Results true if world
was found
*******************************************************************************}
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
var
xx, yy, x, y, Color: integer;
begin
if (WorldScreen) then
begin
Color := 16579836;//white
if not FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
begin
Color := 6618364;//yellow
if FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
WorldRec.Members := true
else
Exit;
end;
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(137, y-2, 0, StatChars, False, False, 0, 3, Color, 6, False, tr_Digits)), -1);
WorldRec.Activity := Trim(GetTextAtEx(238, y-2, 0, StatChars, False, False, 0, 3, Color, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 7711612, 600, y-4, 636, y+14);
WorldRec.QuickChat := Pos('uick', WorldRec.Activity) > 0;
WorldRec.PVP := Pos('ounty', WorldRec.Activity) > 0;
Result := (WorldRec.PlayerNo > 0);
end;
end;

{*******************************************************************************
Function SelectWorld(W: Integer): Boolean;
by: Narcle & ZephyrsFury, edit by Bionicle1800
Description: Switches to the specified world. Returns true if successful.
*******************************************************************************}
function SelectWorld(W: integer): boolean;
var
x, y, xx, yy, CurW: integer;
WRec: TWorld;
begin
if OpenWorldScreen then
begin
wait(400+random(200));
if FindWorld(W) then
begin
wait(100+random(100));
WS_CurrentWorld(CurW);
Result := (W = CurW);
begin
Result := True;
Exit;
end;
if GetWorldInfo(W, WRec) then
begin
Writeln('World: '+inttostr(WRec.Number)+', Players: '+inttostr(WRec.PlayerNo)+', Members: '+Booltostr(WRec.Members)+', PvP: '+Booltostr(WRec.PVP));
if not FindTextTpaEx(16579836, 0, 102, 135, 133, 438, x, y, IntToStr(W), StatChars, nothing) then
if not FindTextTpaEx(6618364, 0, 102, 135, 133, 438, x, y, IntToStr(W), StatChars, nothing) then
Exit;
MMouse(x, y, 500, 4);
GetMousePos(x, y);
wait(300);
if FindColor(xx, yy, 6316128, x-20, y-2, x+20, y+2) then
begin
Mouse(x, y, 0, 0, true);//Final click
Wait(300);
if FindColor(xx, yy, 19890, x-20, y-2, x+20, y+2) then
Result := true;
end;
end else
WriteLn('World ' + IntToStr(W) + ' is either OFFLINE or FULL.');
end else
WriteLn('Failed to find World ' + IntToStr(W) + '!');
if (not(Result)) then TypeByte(vk_Escape);
end;
end;

{*******************************************************************************
function RandomWorld(Members, PvP: Boolean): Integer;
by: Narcle & mixster
Description: Returns a random world by paramaters.
*******************************************************************************}
function RandomWorld(Members, PvP: Boolean): Integer;
var
i, H, l{, CurW}: integer;
wArray: TWorldArray;
begin
if High(WorldArray) < 0 then
LoadWorldArrays;
H := High(WorldArray);
SetLength(wArray, H + 1);
for i := 0 to H do
if (WorldArray[i].Members = Members) and (WorldArray[i].PvP = PvP) and (InStrArr(WorldArray[i].Language, ['English', ''], False)) then
begin
wArray[l] := WorldArray[i];
Inc(l);
end;
Result := wArray[random(l)].Number;
end;

{*******************************************************************************
function ChangeWorld(W: Integer): Boolean;
by: Nava2
Description: Changes to world W. Returns True if successful.
*******************************************************************************}

function ChangeWorld(W: Integer): Boolean;
begin
while LoggedIn do ExitToLobby;
Result := SelectWorld(W);
LoginPlayer;
end;

{*******************************************************************************
Procedure OrderWorlds(by: string; Descending: boolean);
by: NaumanAkhlaQ
Description: Orders worlds by 'by' in order 'Descending'
Check function for valid params of 'by'
Descending = true means the left button
*******************************************************************************}
Procedure OrderWorlds(by: string; Descending: boolean);
var
ATPA: T2DPointArray;
Arr: array of tstringarray;
TPA: TPointArray;
I: Byte;
TB: TBox;
Begin
Arr := [TStringArray(['world', 'w', 'worlds']), TStringArray(['players', 'pl', 'player']), TStringArray(['activity', 'location', 'loc', 'act']),
TStringArray(['ls', 'lootshare']), TStringArray(['type', 't']), TStringArray(['ping', 'pi'])];
For I := 0 To High(Arr) Do
If InStrArr(Lowercase(By), Arr[i], False) Then
Break;
FindColorsTolerance(TPA, 1074576, 0, 0, 716, 141, 1);
ATPA := SplitTPA(TPA, 2);
SortATPAFromFirstPoint(ATPA, Point(91, 124));
TB := GetTPABounds(ATPA[(I * 2) + Integer(Descending)]);
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;

{*******************************************************************************
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
by: Rasta Magician
Description: Chooses a world by SettingsNames , ordered by SettingsDescending
Takes into account Members and PVP
Check OrderWorlds for valid params for SettingsNames
*******************************************************************************}
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
var
TPA: TPointArray;
i, C : integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
exit;

if length(SettingsNames) <> length(SettingsDescending) then
begin
srl_warn('ChooseWorldBy', 'Arrays are not the same length', warn_AllVersions);
SelectWorld(RandomWorld(Members, PVP));
exit;
end;

for i:= 0 to High(SettingsNames) do
begin
OrderWorlds(SettingsNames[i], SettingsDescending[i]);
wait(1000+random(200));
end;

wait(1500+random(500));
for i:= 0 to 15 do //16 worlds show up in screen
begin
FindColorsTolerance(TPA, 16777215, 182, 150+18*i, 206, 159+18*i, 0);
C := Length(TPA);
if (C = 0)or(C = 66) then //failed detection or full
Continue;

if (Members)xor(GetColor(620, 157+18*i) <> 11316396) then
Continue;

if (PVP)xor(GetColor(589, 156+18*i) <> 1251528) then
Continue;

MouseBox(79, 148+18*i, 685, 165+18*i, 1);

for c := 0 to 4 do
begin
wait(200);
Result := not WorldScreen;
if Result then exit;
end;

end;
Result := false;
writeln('Failed to sort the worlds. Choosing random world. Members: '+BoolToStr(Members)+'; PVP: '+BoolToStr(PVP)+';');
SelectWorld(RandomWorld(Members, PVP));
end;

Bionicle

2010-03-08 20:28:25

From: IceFire908
Worldswitcher.scar so far is as below

There is a problem with the world# -> scroll cord maths that I can't seem to crack, Narcle help pl-0x?? (SCAR/simba is irrelevant in this case)

Also, the text clicking for the worlds stopped working as well. (using SCAR)

I haven't tested simba, and I don't intent to until I get SCAR's working first.

//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ? WorldSwitch routines --//
//-----------------------------------------------------------------//
// * function WorldScreen: Boolean; // by Narcle
// * function OpenWorldScreen: Boolean; // by Bionicle1800
// * function UpdateWorlds: Boolean; // by mixster & Nava2
// * procedure LoadWorldArrays; // by Narcle
// * function FindWorld(W: integer): Boolean; // by Narcle
// * function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean; // by Narcle
// * function WS_CurrentWorld(var World: Integer): Boolean; // by IceFire908
// * function SelectWorld(WorldNumber: Integer): Boolean; // by Narcle & ZephyrsFury
// * function RandomWorld(Members, PvP: Boolean): Integer; // by Narcle & mixster
// * function ChangeWorld(W: Integer): Boolean; // by Nava2
// * Procedure OrderWorlds(by: string; Descending: boolean); // by NaumanAkhlaQ
// * Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: TBooleanArray; Members, PVP: boolean): boolean; // by Rasta Magician

type
TWorld = record
Number, PlayerNo: Integer;
Members: Boolean;
Prefix, Location, Activity, Language: String;
LootShare, QuickChat, PVP: Boolean;
end;
TWorldArray = Array of TWorld;

Var
WorldArray: TWorldArray;
WorldsOrdered: Boolean;

function ExitToLobby: Boolean; forward;
procedure LoginPlayer; forward;

{*******************************************************************************
function WorldScreen: Boolean;
by: IceFire908
Description: Returns true if the World screen is open.
*******************************************************************************}
function WorldScreen: Boolean;
begin
Result := (GetLobbyTab = L_WorldSelect);
end;

{*******************************************************************************
function OpenWorldScreen: Boolean;
by: Bionicle1800
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
begin
if LobbyTab(2) then
if WorldScreen then
result := true;
end;

const
SRL_LG_ENGLISH = 0;
SRL_LG_GERMAN = 1;
SRL_LG_FRENCH = 2;
SRL_LG_PORTUGUESE = 3;
SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH;

{*******************************************************************************
procedure UpdateWorlds;
by: mixster
Description: Parses the worlds page into Worlds.INI
*******************************************************************************}
function UpdateWorlds: Boolean;
var
worldList: TWorldArray;
str, Path: string;
tsa, tsb: TStringArray;
W, I, H, Time: Integer;
begin
try
Result := True;
Path := IncludePath + 'SRL\SRL\misc\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);
if (SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH) then
str := ''
else
str := 'l=' + IntToStr(SRL_WORLDPARSE_LANG) + '/';
str := GetPage('http://www.runescape.com/' + str + 'slu.ws?order=WMPLA');
Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
Delete(str, 1, Pos('<tr', str) + 3);
tsa := srl_Explode(str, '<tr');
H := High(tsa);
SetLength(worldList, H + 1);
for I := 0 to H do
with worldList[I] do
begin
tsb := srl_Explode(tsa[I], '<td');
if High(tsb) < 5 then
begin
Writeln('Skipping world "' + IntToStr(I + 1) + '" because explosion didn''t return enough values');
Continue;
end;
PlayerNo := StrToIntDef(Between('>', '<', tsb[2]), 2000);
if (Between('"', '"', tsb[3]) = 'a') or (Between('"', '"', tsb[3]) = 'a d') then
begin
Location := 'Activity';
Activity := Between('>', '<', tsb[3]);
end
else
begin
Location := Between('>', '<', tsb[3]);
Activity := '';
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
begin
Writeln('Invalid world number produced: ' + Prefix);
Writeln('Assuming has suffix, trying again');
str := Replace(Prefix, 'world', '');
Number := StrToIntDef(Copy(str, 1, Length(str) - 1), -1);
if Number = -1 then
Writeln('Failed to gather a world number')
else
Writeln('Succeeded, got ' + IntToStr(Number));
end;
LootShare := Between('"', '"', tsb[4]) = 'd';
QuickChat := Activity = 'Quick Chat';
PvP := Activity = 'PvP World';
Members := Between('"', '"', tsb[5]) = 'm';
end;
//Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
except
Result := False;
//SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
end;
if not Result then Exit;
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, 'Type', BoolToStr(Members), Path);
if (Members) then
WriteINI(Str, 'Type', 'Members', Path)
else
WriteINI(Str, 'Type', 'Free', 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.');
end;

{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle; Edits by Nava2
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
try
H := StrToInt(ReadINI('Worlds', 'High', IncludePath + 'SRL\SRL\misc\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;
SetArrayLength(WorldArray, H + 1);
for i := 1 to H do
if not (ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\Worlds.ini') = '') then
begin
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', IncludePath + 'SRL\SRL\misc\worlds.ini');
WorldArray[Hw].Members := (ReadINI('World' + IntToStr(i), 'Type', IncludePath + 'SRL\SRL\misc\worlds.ini') = 'Members');
WorldArray[Hw].LootShare := StrToBool(ReadINI('World' + IntToStr(i), 'Lootshare', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].QuickChat := StrToBool(ReadINI('World' + IntToStr(i), 'Quickchat', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].PVP := StrToBool(ReadINI('World' + IntToStr(i), 'PvP', IncludePath + 'SRL\SRL\misc\worlds.ini'));
WorldArray[Hw].Language := ReadINI('World' + IntToStr(i), 'ServLang', IncludePath + 'SRL\SRL\misc\worlds.ini');
Inc(Hw);
end;
SetArrayLength(WorldArray, Hw);
end;

{*******************************************************************************
function WS_CurrentWorld(var World: Integer): Boolean;
by: IceFire908
Description: Results true if the current world is members,returns world number.
World returns -1 if failed. Only works at world screen.
*******************************************************************************}

function WS_CurrentWorld(var World: Integer): Boolean;
var
P: TPoint;
begin
World := -1;
if (not (WorldScreen)) then
Exit;
if (IsTextInAreaEx(618, 74, 705, 96, P.X, P.Y, 'orld', 0, SmallChars, False, False, 0, 1, clWhite)) then
World := StrToIntDef(GetNumbers(Trim(GetTextAtEx(P.X, P.Y, 0, SmallChars, False, False, 0, 1, clWhite, 15, False, tr_AllChars))), -1);
Result := SimilarColors(GetColor(645, 83), 3141117, 15);
end;

{*******************************************************************************
function FindWorld(W: integer): Boolean;
by: Narcle
Description: Scrolls to area and returns true if world was found
*******************************************************************************}
function FindWorld(W: integer): Boolean;
Var
WPos, SPos, i, x, y, H, CurW: integer;
begin
if not WorldScreen then
Exit;
WS_CurrentWorld(CurW);
if (W = CurW) then
begin
Result := True;
WriteLn('Already on world ' + IntToStr(W));
Exit;
end;
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1));
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true);

wait(300+Random(100));

Result := FindTextTpaEx(16579836, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing) or
FindTextTpaEx(6618364, 0, 84, 134, 134, 440, x, y, inttostr(W)+' ', StatChars, Nothing);
end;

{*******************************************************************************
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
by: Narcle
Description: Records World info into TWorld record, also Results true if world
was found
*******************************************************************************}
function GetWorldInfo(World: Integer; var WorldRec: TWorld): Boolean;
var
xx, yy, x, y, Color: integer;
begin
if (WorldScreen) then
begin
Color := 16579836;//white
if not FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
begin
Color := 6618364;//yellow
if FindTextTpaEx(Color, 0, 84, 134, 134, 440, x, y, ' '+inttostr(World)+' ', StatChars, Nothing) then
WorldRec.Members := true
else
Exit;
end;
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(137, y-2, 0, StatChars, False, False, 0, 3, Color, 6, False, tr_Digits)), -1);
WorldRec.Activity := Trim(GetTextAtEx(238, y-2, 0, StatChars, False, False, 0, 3, Color, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 7711612, 600, y-4, 636, y+14);
WorldRec.QuickChat := Pos('uick', WorldRec.Activity) > 0;
WorldRec.PVP := Pos('ounty', WorldRec.Activity) > 0;
Result := (WorldRec.PlayerNo > 0);
end;
end;

{*******************************************************************************
Function SelectWorld(W: Integer): Boolean;
by: Narcle & ZephyrsFury, edit by Bionicle1800
Description: Switches to the specified world. Returns true if successful.
*******************************************************************************}
function SelectWorld(W: integer): boolean;
var
x, y, xx, yy, CurW: integer;
WRec: TWorld;
begin
if OpenWorldScreen then
begin
wait(400+random(200));
if FindWorld(W) then
begin
wait(100+random(100));
WS_CurrentWorld(CurW);
Result := (W = CurW);
begin
Result := True;
Exit;
end;
if GetWorldInfo(W, WRec) then
begin
Writeln('World: '+inttostr(WRec.Number)+', Players: '+inttostr(WRec.PlayerNo)+', Members: '+Booltostr(WRec.Members)+', PvP: '+Booltostr(WRec.PVP));
if not FindTextTpaEx(16579836, 0, 102, 135, 133, 438, x, y, IntToStr(W), StatChars, nothing) then
if not FindTextTpaEx(6618364, 0, 102, 135, 133, 438, x, y, IntToStr(W), StatChars, nothing) then
Exit;
MMouse(x, y, 500, 4);
GetMousePos(x, y);
wait(300);
if FindColor(xx, yy, 6316128, x-20, y-2, x+20, y+2) then
begin
Mouse(x, y, 0, 0, true);//Final click
Wait(300);
if FindColor(xx, yy, 19890, x-20, y-2, x+20, y+2) then
Result := true;
end;
end else
WriteLn('World ' + IntToStr(W) + ' is either OFFLINE or FULL.');
end else
WriteLn('Failed to find World ' + IntToStr(W) + '!');
if (not(Result)) then TypeByte(vk_Escape);
end;
end;

{*******************************************************************************
function RandomWorld(Members, PvP: Boolean): Integer;
by: Narcle & mixster
Description: Returns a random world by paramaters.
*******************************************************************************}
function RandomWorld(Members, PvP: Boolean): Integer;
var
i, H, l{, CurW}: integer;
wArray: TWorldArray;
begin
if High(WorldArray) < 0 then
LoadWorldArrays;
H := High(WorldArray);
SetLength(wArray, H + 1);
for i := 0 to H do
if (WorldArray[i].Members = Members) and (WorldArray[i].PvP = PvP) and (InStrArr(WorldArray[i].Language, ['English', ''], False)) then
begin
wArray[l] := WorldArray[i];
Inc(l);
end;
Result := wArray[random(l)].Number;
end;

{*******************************************************************************
function ChangeWorld(W: Integer): Boolean;
by: Nava2
Description: Changes to world W. Returns True if successful.
*******************************************************************************}

function ChangeWorld(W: Integer): Boolean;
begin
while LoggedIn do ExitToLobby;
Result := SelectWorld(W);
LoginPlayer;
end;

{*******************************************************************************
Procedure OrderWorlds(by: string; Descending: boolean);
by: NaumanAkhlaQ
Description: Orders worlds by 'by' in order 'Descending'
Check function for valid params of 'by'
Descending = true means the left button
*******************************************************************************}
Procedure OrderWorlds(by: string; Descending: boolean);
var
ATPA: T2DPointArray;
Arr: array of tstringarray;
TPA: TPointArray;
I: Byte;
TB: TBox;
Begin
Arr := [TStringArray(['world', 'w', 'worlds']), TStringArray(['players', 'pl', 'player']), TStringArray(['activity', 'location', 'loc', 'act']),
TStringArray(['ls', 'lootshare']), TStringArray(['type', 't']), TStringArray(['ping', 'pi'])];
For I := 0 To High(Arr) Do
If InStrArr(Lowercase(By), Arr[i], False) Then
Break;
FindColorsTolerance(TPA, 1074576, 0, 0, 716, 141, 1);
ATPA := SplitTPA(TPA, 2);
SortATPAFromFirstPoint(ATPA, Point(91, 124));
TB := GetTPABounds(ATPA[(I * 2) + Integer(Descending)]);
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
end;

{*******************************************************************************
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
by: Rasta Magician
Description: Chooses a world by SettingsNames , ordered by SettingsDescending
Takes into account Members and PVP
Check OrderWorlds for valid params for SettingsNames
*******************************************************************************}
Function ChooseWorldBy(SettingsNames:TStringArray; SettingsDescending: array of boolean; Members, PVP: boolean): boolean;
var
TPA: TPointArray;
i, C : integer;
begin
if not WorldScreen then
if not OpenWorldScreen then
exit;

if length(SettingsNames) <> length(SettingsDescending) then
begin
srl_warn('ChooseWorldBy', 'Arrays are not the same length', warn_AllVersions);
SelectWorld(RandomWorld(Members, PVP));
exit;
end;

for i:= 0 to High(SettingsNames) do
begin
OrderWorlds(SettingsNames[i], SettingsDescending[i]);
wait(1000+random(200));
end;

wait(1500+random(500));
for i:= 0 to 15 do //16 worlds show up in screen
begin
FindColorsTolerance(TPA, 16777215, 182, 150+18*i, 206, 159+18*i, 0);
C := Length(TPA);
if (C = 0)or(C = 66) then //failed detection or full
Continue;

if (Members)xor(GetColor(620, 157+18*i) <> 11316396) then
Continue;

if (PVP)xor(GetColor(589, 156+18*i) <> 1251528) then
Continue;

MouseBox(79, 148+18*i, 685, 165+18*i, 1);

for c := 0 to 4 do
begin
wait(200);
Result := not WorldScreen;
if Result then exit;
end;

end;
Result := false;
writeln('Failed to sort the worlds. Choosing random world. Members: '+BoolToStr(Members)+'; PVP: '+BoolToStr(PVP)+';');
SelectWorld(RandomWorld(Members, PVP));
end;


K well the scroll thingy works fine, don't know whats wrong with yours…
Workin on the reading the text in SCAR atm..

Wanted

2010-03-08 20:31:15

I can probably fix that part, I'm having trouble converting the current algorithm for the scroll bar points. I tried rewriting my own but it isn't anywhere near as good as one in place was before the update =/

Bionicle

2010-03-08 20:37:20

From: IceFire908
I can probably fix that part, I'm having trouble converting the current algorithm for the scroll bar points. I tried rewriting my own but it isn't anywhere near as good as one in place was before the update =/


It works fine for me…tested out a number of worlds, it scrolls down but then doesn't click it due to the text not working in scar.

Wanted

2010-03-08 20:41:40

From: bionicle1800
It works fine for me…tested out a number of worlds, it scrolls down but then doesn't click it due to the text not working in scar.


Try with worlds near the bottom/top… i.e 148-171ish, 15-30.

Bionicle

2010-03-08 20:49:38

From: IceFire908
Try with worlds near the bottom/top… i.e 148-171ish, 15-30.


hmm…just tried a few more…they all work…
the only weird thing was when it tried 15 it clicked the scroll bar, but on top of the scroll bar so it didn't move.

Wanted

2010-03-08 20:51:35

From: bionicle1800
hmm…just tried a few more…they all work…
the only weird thing was when it tried 15 it clicked the scroll bar, but on top of the scroll bar so it didn't move.


15 is visible from the uppermost

So, 17 and 148 work for you?

Bionicle

2010-03-08 20:55:34

From: IceFire908
15 is visible from the uppermost

So, 17 and 148 work for you?


Oh wtf..
17 works, but 148 doesn't. 154-171 does, that was what i was trying between.

Wanted

2010-03-08 20:58:27

From: bionicle1800
Oh wtf..
17 works, but 148 doesn't. 154-171 does, that was what i was trying between.


Well, the old maths work because there is a high amount of margin for error since it can fit 14/15 worlds at a time on the screen. The solution is to fix math all together for the new interface… but I'm having trouble decrypting the code. I think it's these lines in FindWorld



  if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1));
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true);

Bionicle

2010-03-08 21:01:33

if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1)); //this is where it sets the position on the scroll bar via W (world #) and H (the highest world)
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true); //this line is the math for the point on the scroll bar

I had to extend the + at the end inside the round procedure to fit inside the the newer, bigger scroll when i did my edits. I thought it worked, and, for the most part it did :/

Wanted

2010-03-08 21:03:12

From: bionicle1800
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Number = W) then
begin
WPos := i+1;
Break;
end;
SPos := Round(WPos*100/(H+1));
if not WorldsOrdered then
begin
Mouse(101, 128, 4, 4, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 16) then SPos := 0;
if (W > H-9) then SPos := 100;
Mouse(699, Round(SPos/100.0*262.0+156), 3, 0, true); //this line

I had to extend the + at the end inside the round procedure to fit inside the the newer, bigger scroll when i did my edits. I thought it worked, and, for the most part it did :/


I need a full fix, it's giving me major issues =/ maybe narcle can help.

Bionicle

2010-03-08 21:04:41

From: IceFire908
I need a full fix, it's giving me major issues =/ maybe narcle can help.


Look at my edit, kind of fucked it over.
But i have no idea how to write a new math algorithm, but i know how the current one works, i just can't explain things that well :p
E: Also what i ment of extending the + in the round procedure, i ment when i first made this thread i 'thought' i fixed that by extending the y coord in the last line to fit the new scroll bar length.

Narcle

2010-03-08 22:42:24

The algorithm should be fine. Is it loading the world array correct for you guys? I can't check it out right now not at home. But i'll test it with the new stuff when I get home.

Also if this one goes wrong
SPos := Round(WPos*100/(H+1));

then the final algorithm won't work

Edit:
Try adding Writeln('Spos = '+inttostr(SPos)); for debug I bet its not working right… I had the problem in Simba as well… idk whats up with it. I changed it from the original which was SPos := Round(WPos/(H+1)*100);