SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » WorldSwitch routines --//
//-----------------------------------------------------------------//
//
// * Function WorldScreen: Boolean; // by Narcle
// * Function OpenWorldScreen: Boolean; // by ZephyrsFury & Narcle
// * 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
type
TWorld = record
Number, PlayerNo: Integer;
Members: Boolean;
Prefix, Location, Activity: String;
LootShare, QuickChat, PVP: Boolean;
end;
TWorldArray = Array of TWorld;
Var
WorldArray: TWorldArray;
WorldsOrdered: Boolean;
{*******************************************************************************
function WorldScreen: Boolean;
by: Narcle
Description: Returns true if the World screen is open.
*******************************************************************************}
function WorldScreen: Boolean;
var
x, y: integer;
begin
Result := FindTextTpaEx(16777215, 0, 57, 130, 162, 458, x, y, 'orld ', SmallChars, Nothing);
end;
{*******************************************************************************
Function OpenWorldScreen: Boolean;
by: ZephyrsFury & Narcle
Description: Opens the world screen. Returns true if world screen is opened.
*******************************************************************************}
function OpenWorldScreen: Boolean;
var
T: Integer;
begin
if (WorldScreen) then
begin
Result := True;
Exit;
end;
if (CountColor(7750, 343, 253, 419, 264) = 138) then
begin
MouseBox(361, 243, 403, 249, 1);
T := GetSystemTime + 60000;
Repeat
wait(100);
if GetSystemTime > T then
Exit;
Result := WorldScreen;
until Result;
end;
end;
{*******************************************************************************
procedure LoadWorldArrays;
by: Narcle
Description: Loads the world array into WorldArray from Worlds.ini
*******************************************************************************}
procedure LoadWorldArrays;
var
i, H, Hw: integer;
begin
H := StrToInt(ReadINI('Worlds', 'High', AppPath + 'includes\SRL\SCSS\worlds.ini'));
for i := 1 to H do
begin
if not (ReadINI('World' + IntToStr(i), 'Prefix', AppPath + 'includes\SRL\SCSS\worlds.ini') = '') then
begin
SetArrayLength(WorldArray, Length(WorldArray)+1);
Hw := High(WorldArray);
WorldArray[Hw].Number := i;
WorldArray[Hw].Prefix := ReadINI('World' + IntToStr(i), 'Prefix', AppPath + 'includes\SRL\SCSS\worlds.ini');
WorldArray[Hw].Members := ReadINI('World' + IntToStr(i), 'Type', AppPath + 'includes\SRL\SCSS\worlds.ini') = 'Members';
WorldArray[Hw].LootShare := ReadINI('World' + IntToStr(i), 'Lootshare', AppPath + 'includes\SRL\SCSS\worlds.ini') = 'True';
WorldArray[Hw].QuickChat := ReadINI('World' + IntToStr(i), 'Quickchat', AppPath + 'includes\SRL\SCSS\worlds.ini') = 'True';
WorldArray[Hw].PVP := ReadINI('World' + IntToStr(i), 'PvP', AppPath + 'includes\SRL\SCSS\worlds.ini') = 'True';
end;
end;
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;
Result := FindTextTpaEx(16777215, 0, 57, 130, 162, 458, x, y, 'orld '+inttostr(W)+' ', SmallChars, 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(121, 119, 6, 6, true);//makes them drop down
WorldsOrdered := true;
wait(500+random(500));
end;
if (W < 11) then SPos := 0;
if (W > H-9) then SPos := 101;//101 compensate for randomness
Mouse(698, Round(SPos/100.0*262.0+162), 3, 3, true);
Result := FindTextTpaEx(16777215, 0, 57, 130, 162, 458, x, y, 'orld '+inttostr(W)+' ', SmallChars, 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: integer;
begin
if (WorldScreen) then
begin
FindTextTpaEx(16777215, 0, 57, 130, 162, 458, x, y, 'orld '+inttostr(World)+' ', SmallChars, Nothing);
WorldRec.Number := World;
WorldRec.PlayerNo := StrToIntDef(Trim(GetTextAtEx(170, y-8, 0, SmallChars, False, False, 0, 2, clWhite, 6, False, tr_Digits)), -1);
WorldRec.Location := Trim(GetTextAtEx(236, y - 7, 0, SmallChars, False, False, 0, 2, clWhite, 16, False, tr_AllChars));
WorldRec.Activity := Trim(GetTextAtEx(344, y - 7, 0, SmallChars, False, False, 0, 2, clWhite, 24, False, tr_AllChars));
WorldRec.LootShare := FindColor(xx, yy, 2913076, 510, y-8, 530, y+8);
WorldRec.QuickChat := FindColor(xx, yy, 2913076, 557, y-8, 577, y+8);
WorldRec.PVP := FindColor(xx, yy, 2913076, 582, y-8, 602, y+8);
WorldRec.Members := (Trim(GetTextAtEx(631, y - 7, 0, SmallChars, False, False, 0, 2, clWhite, 8, False, tr_AllChars)) = 'Members');
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 FindTextTpaEx(16777215, 0, 57, 130, 162, 458, x, y, 'orld '+inttostr(W)+' ', SmallChars, nothing) then
begin
MMouse(x, y, 500, 4);
GetMousePos(x, y);
if FindColor(xx, yy, 4351095, x-20, y-2, x+20, y+2) then
begin
Mouse(x, y, 0, 0, true);//Final click
T := GetSystemTime;
while (WorldScreen) and (GetSystemTime - T < 10000) do
Wait(100);
Result := (not(WorldScreen));
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: integer;
wArray: TWorldArray;
begin
if Length(WorldArray) < 1 then
LoadWorldArrays;
H := High(WorldArray);
for i := 0 to H do
if (WorldArray[i].Members = Members) and (WorldArray[i].PvP = PvP) then
begin
SetArrayLength(wArray, Length(wArray)+1);
wArray[High(wArray)] := WorldArray[i];
end;
Result := wArray[random(High(wArray)+1)].Number;
end;