View Full Version : GetLeastCrowdedServer: Integer;


marpis
09-30-2009, 05:59 PM
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;

r!ch!e
10-01-2009, 06:55 AM
Nice, I think this would be really useful.

YoHoJo
10-01-2009, 08:44 AM
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.

r!ch!e
10-01-2009, 09:06 AM
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
10-01-2009, 09:09 AM
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?

r!ch!e
10-01-2009, 09:23 AM
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
10-01-2009, 09:26 AM
@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.

r!ch!e
10-01-2009, 09:48 AM
Doesn't SMART just load a random world? Not the least populated?

mormonman
10-01-2009, 09:50 AM
Doesn't SMART just load a random world? Not the least populated?

Unsigned loads a specific world.

Quickmarch
10-01-2009, 05:18 PM
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
10-02-2009, 04:03 PM
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!
10-02-2009, 08:42 PM
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.