SRL Archive - SRL Archives

GetLeastCrowdedServer: Integer;


marpis

2009-09-30 13:59:45

Self-explanatory

thanks zeph for the link to serverlist :) or should i thank mixster? ^^

E: New version that updates itself if memberworld numbers change.
Thanks to mixster, zeph and narcle! :)


function LeastCrowdedServer(Members, PVP: Boolean):Integer;
var
I, N, Hi: Integer;
GoodWorlds, PlayerCounts: TIntegerArray;
Content, S: string;
begin
Content := GetPage('http://www.runescape.com/slu.ws?order=WMPLA'); // Get serverlist as a string
LoadWorldArrays; // Load SRL Serverlist that has info of servers (is it p2p or pvp etc)
Hi := High(WorldArray);
for I := 0 to Hi do //if the world[i] is p2p server and we are looking for f2p continue. same with pvp.
if (WorldArray[I].Members and (not Members)) or (WorldArray[I].PVP and (not PVP)) then
Continue
else
begin
SetLength(GoodWorlds, Length(GoodWorlds) + 1); // we found a server which met our criters, add to "GoodWorlds" array
SetLength(PlayerCounts, Length(PlayerCounts) + 1);
GoodWorlds[High(GoodWorlds)] := WorldArray[I].Number; // here we check the worlds number from the SRL WorldArray
end;

Hi := High(GoodWorlds);

for I := 0 to Hi do
begin
N := Pos('World '+IntToStr(GoodWorlds[I]), Content); // Look for text "World 14" for example, in the serverlist website
if (N = 0) then
begin // if not found, we set the playeramount incredibly high for that server so it doesn't get picked as the least crowded
PlayerCounts[I] := 1 shl 20; // = 1048576
Continue;
end;
S := Copy(Content, N + 11, 24); // copy the part from the rs serverlist site where is the playercount
PlayerCounts[I] := StrToIntDef(GetNumbers(S), 1 shl 20); // read playercount as an integer
if PlayerCounts[I] <= 0 then // if something went wrong, set playercount very high so it doesn't get picked as the least crowded
PlayerCounts[I] := 1 shl 20;
//WriteLn('Server '+IntToStr(GoodWorlds[I])+' has '+IntToStr(PlayerCounts[I])+' players.');
end;
InIntArrayEx(PlayerCounts, N, AMin(PlayerCounts)); // now we check in which index is the smallest number in PlayerCounts array
Result := GoodWorlds[N]; // and choose the world
end;

Rick

2009-10-01 02:55:22

Nice, I think this would be really useful.

YoHoJo

2009-10-01 04:44:39

Wana explainexactly what the code does please?
Also good job making this i cant believe there isnt one already. Very useful function, A LOT of scripts would work MUCH better on less crowded servers.

Rick

2009-10-01 05:06:06

http://www.runescape.com/slu.ws?order=WMPLA
is the server list for Runescape.

It checks each world against the input settings, and loads it into the GoodWorlds array.

It then goes through the GoodWorld array to check the amount of people in each World and stores it in PlayerCount.

Finally it checks the PlayerCount array for the lowest number of people and returns it as the result.

Is that what you were looking for?

YoHoJo

2009-10-01 05:09:44

Couldn't you just click "Wold Select" or whatever on the login screen, and sort by players from low to high, and then just click the first one on the list?

Rick

2009-10-01 05:23:06

The first world may not always be suitable for autoing. What if its PVP, and the user doesn't want that. Also, this can be used in SMART setup, before the script has started.

mormonman

2009-10-01 05:26:39

@YoHoJo - Would if you want to choose an unsigned world for SMART
@R!ch!e - There is already a function for that

I don't think this will be added to SRL because they discourage anything that associates it directly with the rs website(I think, don't take my word for it). Which is why we don't have GE Price parsing in the include.

Rick

2009-10-01 05:48:32

Doesn't SMART just load a random world? Not the least populated?

mormonman

2009-10-01 05:50:10

From: r!ch!e
Doesn't SMART just load a random world? Not the least populated?


Unsigned loads a specific world.

Quickmarch

2009-10-01 13:18:42

Why did you use shl if you're not using variables? Why not just replace it with 1048576 (The result of 1 shl 20)?

marpis

2009-10-02 12:03:29

From: Quickmarch
Why did you use shl if you're not using variables? Why not just replace it with 1048576 (The result of 1 shl 20)?


Successfully compiled (42 ms)
took: 5553 <- this was with 1048576
Successfully executed
Successfully compiled (42 ms)
took: 5491 <- this was with 1 shl 20

made it calculate 2 million times

EvilChicken!

2009-10-02 16:42:42

From: marpis
Successfully compiled (42 ms)
took: 5553 <- this was with 1048576
Successfully executed
Successfully compiled (42 ms)
took: 5491 <- this was with 1 shl 20

made it calculate 2 million times


Quickmarch is right, it's not realistic to call this function 2 million times.
Sure, right/left-shifting is faster, but it would be like using Value + Random(Value) instead of RandomRange(Value, Value+Randomness); just because the first one is nanoseconds faster.


Plus, I'm not sure about committing this function; the Devs have some sort of policy about not letting SCAR connect to external websites within the include. That sounds fully understandable to me.