SRL Archive - SRL Archives

function RndWorld(wType: integer): integer;


PriSoner

2008-02-25 11:07:39

Just a simple function that may be usefull to some of you, do with it what you will..

function RndWorld(wType: integer): integer;

Returns a world number based on input:
1 Returns a random Valid World member/Non Member.
2 Returns a random Free Play World
3 Returns a random Members World.

Can be easily used with functions like SmartSetupEX(); to load a valid world.

Uses Worlds.ini so that any world changes will always be up to date.

Does not return any Special/Reserved World.

{*******************************************************************************
function RndWorld(wType: integer): integer;
By: PriSoner
Description: Returns a random world number. Uses worlds.ini to get a world count
and check if world is members or free.
Options: Enter 1 to return any valid random world.
2 to return any valid Free Play World
3 to return any valid Members World
*******************************************************************************}
function RandWorld(wType: integer): integer;
var winipath: String;
rndcount: integer;
begin
if (wType > 0) and (wType < 4) then
begin
winipath := AppPath + 'includes\SRL\SCSS\worlds.ini';
rndcount := StrToInt(ReadINI('Worlds', 'Count', winipath));
case wType of
1: repeat
result := Random(rndcount) + 1;
until (ReadINI('World' + IntToStr(result), 'Type', winipath) = 'Free') or
(ReadINI('World' + IntToStr(result), 'Type', winipath) = 'Members');
2: repeat
result := Random(rndcount) + 1;
until (ReadINI('World' + IntToStr(result), 'Type', winipath) = 'Free');
3: repeat
result := Random(rndcount) + 1;
until (ReadINI('World' + IntToStr(result), 'Type', winipath) = 'Members');
end;
writeln('Your Randomly Chosen World is: ' + IntToStr(result));
end else
begin
writeln('function RandWorld: Incorrect value! Valid Range is 1 to 3. Terminating Script!');
TerminateScript;
end;
end;

FrÕzÑ_§ÕµL

2008-02-25 13:50:04

Nice work, I'll just stick with my
Case Random(#ofWorlds)
repeat
until(Nworld <> OWorld)
sort of thing for now, as it works so yea.

I am so pissed that you cant change from F2P to P2P on SMART!

PriSoner

2008-02-25 14:11:58

It just makes it easy to maintain and impliment while keeping the program size and memory usage down. :D

I also notice with your big list, that it contains some of the Special/Test/Reserved Worlds like World 120 which at best would mean that the if a player accidentally gets it as a world their efforts and time would go unrewarded and at worst they may end up getting banned. :confused:

Bobarkinator

2008-02-25 16:57:55

I really appreciate you PriSoner. You have helped people on numerous occasions and contribute to the community quite often. Thanks for all you do.

PriSoner

2008-02-25 21:49:04

Thank you. It's always nice to feel appreciated. :D and your kind words are very appreciated! ;)

FrÕzÑ_§ÕµL

2008-02-25 22:08:53

What do you mean special/test/reserved?!

PriSoner

2008-02-25 22:27:07

If you look at the world list via the runescape client or on the Jagex Website you will notice that out of a possible 159 worlds only 146 are listed.

This means that the average joe would not be able to access the non-listed world without having to subvert the system a little (and it aint hard).

Some of these worlds are beta worlds used to test and deploy new updates, some of these worlds have full functionality and some don't count anything you do as permanent.

If you log into one of these worlds you will also notice that there are very few people about. Some would say this makes it perfect for scripters, however I am of the opinion that it makes it very obvious to jagex who to keep an eye on.

From Jagex's point of view, who would be in one of these worlds other than the invited or folk trying to subvert the system. After all the worlds are not available using the official client or via their website.

Worlds.ini only contains the worlds accessible via the client which made it perfect for my uses.. plus the fact that I didn't fancy sorting through all the worlds myself! ;)

FrÕzÑ_§ÕµL

2008-02-27 13:36:30

So if these test worlds are not displayed, then when I created my list it was entirely safe. I'm not just using SelectWorld(Random(150)) you know :P

PriSoner

2008-02-27 14:29:45

I know, I know.. Relax I'm not having a pop at you… :p

It was just that when you mentioned your function I trotted over to have a look at it.. it's a big list of members worlds and a big list of f2p worlds to randomly choose from based on a boolean.

The first thing I noticed was that in one of the lists you had World 120 which is a special world, I didn't check for any others at the time but after a cursory glance now the rest look like they are probably ok…

It may be that at the time you created your list of worlds, world 120 may have been ok, or you may have added it accidentally, I don't know, but what I do know is that it's definitely not ok now.

One of the handy additions in SRL12 was the worlds.ini file, I thought i'd make use of it as intended and created this easy small function.

Because I noticed your list had world 120 in it i just used it to highlight the usefulness of using a central database like this because any changes can be updated quickly throughout all scripts that reference the file..

No Offence Intended!

EvilChicken!

2008-04-09 10:52:16

You know what, I've used your function in several varieties (sp?) and just saw I've not rep'ed you for this. This is great work, and you truly deserve it. In my upcoming script (which I'll be releasing in not too long, [G.A.R.] I'm using your function in a creative way. I've edited it only to include members worlds:


{*******************************************************************************
function RndWorld: Integer;
By: PriSoner, slight edit by EvilChicken!
Description: Returns a random members world number. Uses worlds.ini to get a
world count and checks if world is members or free.
*******************************************************************************}
function RandWorld: Integer;
var
WiniPath: string;
RndCount: Integer;

begin
WiniPath := AppPath + 'includes\SRL\SCSS\worlds.ini';
RndCount := StrToInt(ReadINI('Worlds', 'Count', winipath));
repeat
Result := Random(Rndcount) + 1;
until ReadINI('World' + IntToStr(Result), 'Type', winipath) = 'Members';
Wait(300 + random(200));
end;

.. and I'm using this not only at startup, but also in my worldswitcher. (SelectWorld(RandWorld)). So, this function has helped me in a couple ways. It is great to have people like you here at SRl, PriSoner.

As I said, rep for you.

Edit: To fix the problem of using world that aren't listed, I switch worlds every startup before logging in. Then it can only pick worlds that are viewed.

drizzt

2008-04-09 16:39:19

hmm, i had heard it had been done before but didn't know where, this is probably a lot faster than mine since it doesn't get all of them..good work PriSoner

PriSoner

2008-04-10 08:18:15

From: EvilChicken!
You know what, I've used your function in several varieties (sp?) and just saw I've not rep'ed you for this. This is great work, and you truly deserve it. In my upcoming script (which I'll be releasing in not too long, [G.A.R.] I'm using your function in a creative way. I've edited it only to include members worlds:

.. and I'm using this not only at startup, but also in my worldswitcher. (SelectWorld(RandWorld)). So, this function has helped me in a couple ways. It is great to have people like you here at SRl, PriSoner.

As I said, rep for you.

Thank you very much.. :D It's always nice to feel appreciated and comments like yours really help make the effort all worth while.

From: EvilChicken!

Edit: To fix the problem of using world that aren't listed, I switch worlds every startup before logging in. Then it can only pick worlds that are viewed.

This function will only return listed worlds.. (well as long as worlds.ini is current) ;)

From: drizzt
hmm, i had heard it had been done before but didn't know where, this is probably a lot faster than mine since it doesn't get all of them..good work PriSoner
There's nothing wrong with yours, we all have different ways of doing things. I created this function, like you because I needed it and I didn't find anything else that did what I wanted. Mine uses less memory, is faster but randomly stabs at worlds until it finds a valid one and then uses that, yours builds a list of valid worlds first and then picks a random valid world first time.. Each method has it's advantages depending on the individual script. Of course I prefer mine though ;)

I added to your rep for your function though! :)