Jump to content
slacky

[2007] Get current world population

Recommended Posts

As I was reading this tread, i thought to my self, there must be a simple way to get the current world population, while "in game", as I'm familiar with similar tasks from both Python, and PHP, I quickly thought about regular expression, so I checked the scar-wiki, to see if they had a "PregMatchAll"-kindof function, the result was False. But that aint needed, so I went ahead and used "PregMatchEx", and "PregMatch"... I quickly got some good results!! :)

 

Now, what this two functions does is pretty simple..:

 

function RS07_GetCurrentWorld: Integer;

Returns current world while in game, requires MSSL-library.

 

function WorldPlayerCount(world: String): Integer;

Takes a string as input, EG: '305' - It then grabs the visible source from Runescape's world-select page.

Regex: Navigates the data until a world matches your world-string, then grabs the current population, then returns it.

 

Combine this two functions and you automaticly get the current world population.

 

Again, this is thought of as a solution to shadowrecons post, but might be useful elsewhere. And if his calculations are correct for RS07, isn't up to me to figure out! :P

Can also be used (or modified) to find leased populated world, if the bot your working on just need to world-hop to less crowded world, but other solutions might be prefered.

 

program WorldThing;
{$DEFINE RS07}
{$I MSSL\MSSL.scar}


{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|| function RS07_GetCurrentWorld: Integer; 
|| Description: While in game, you can get the world your playing in.
|| Contributors: slacky -> thanks to Janilabo for MSSL (and a few tips).
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
function RS07_GetCurrentWorld: Integer; 
begin
 Result := -1;
 if RS07_OpenGameTab(8) then
   Result := StrToInt(GetTextAtEx(695, 209, 2, RS07_MainFont, False, False, 0, 2, 3381759, 3, True, tr_AllChars)); 
end;


{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|| function WorldPlayerCount(world: String): Integer;
|| Description: Get current player population of a world, can be used to find 
|| best world if you need to world hop, also needed to calculate ORE-respawn time.
|| Contributors: slacky
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
function WorldPlayerCount(world: String): Integer;
var
 i, players: Integer;  
 Matches: TRegexMatchArray;
 Webdata, Match: String;
begin
 i := InitializeHTTPClient(True, True); 
 players := -1; 
 try     
   Webdata := GetHTTPPage(i, 'http://oldschool.runescape.com/slu');
   Match := PregMatch('/e\(('+world+'),(.*?),"oldschool(.*?)",(.*?),(.*?)\);/iM', Webdata); 
   if Match <> '' then
   begin 
     PregMatchEx('/"oldschool(\w+)",(.*?),(.*?)\);/', Match, Matches);  
     players := StrToInt(Matches[2].MatchedText);
   end;
 finally
   FreeHTTPClient(i);
 end; 

 Result := players;
end;


{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|| Test it out?? 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
var 
 world: String;
begin
 MSSL_Setup; 
 world := IntToStr(RS07_GetCurrentWorld); 
 if world<>'-1' Then 
 begin
   writeln('Population '+ IntToStr(WorldPlayerCount(world)) +' @ World '+ world);
 end;
end.

 

Notes:

- As i only touch pascal, once or twice each season the code might (and from what is see; does) contain some unneeded processing.

- The time it takes to get the current world populations will be 0.2-1.5 secounds depending on processing time, and your response time to that server.

- If anyof the functions above fails; the result will be -1

 

Also, I'm aware that i'm not freeing MSSL, I got to leave something out for you guys.

Edited by slacky
Link to comment
Share on other sites

Truly awesome job slacky! Seems like you are getting the scripting going here, sweet!

 

That is pretty damn good looking function aswell, I must say! Beautiful standards.

 

1 tip I'll hook you up with, that I gave to lazarbeam aswell.

 

This:

function RS07_GetCurrentWorld: Integer; 
begin
 if not(RS07_GameTabOpen(8)) then RS07_OpenGameTab(8);
 Result := StrToInt(GetTextAtEx(695, 209, 2, RS07_MainFont, False, False, 0, 2, 3381759, 3, True, tr_AllChars)); 
end;

 

Could be something like this:

 

function RS07_GetCurrentWorld: Integer; 
begin
 Result := -1;
 if RS07_OpenGameTab(8) then
   Result := StrToInt(GetTextAtEx(695, 209, 2, RS07_MainFont, False, False, 0, 2, 3381759, 3, True, tr_AllChars)); 
end;

 

Because RS07_OpenGameTabEx() uses RS07_GameTabOpen() check, where RS07_OpenGameTab() is based on RS07_OpenGameTabEx().

RS07_OpenGameTab() will check if gametab is already open and if it is, it will return true without trying to open it again. :P

 

Then you could have a failsafe if result is -1 (game tab couldn't be activated, this could happen with say... Lag for example).

 

Keep em coming!

 

-Jani

Link to comment
Share on other sites

Ello slacky, I added these awesome commands in latest MSSL, just committed it moment ago. Will be updated to Includes Manager in about 15 minutes.

 

Added in "World.scar", with some functions for world related things. ;)

I edited your functions slightly (just some small changes really), but yes, I of course added the main credits to you - thanks slacky!

 

World.scar (SVN file)

 

Changelog

 

So, we can now EASILY switch worlds at login screen using MSSL!

 

-Jani

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...