PDA

View Full Version : GetRandomWorld function for SMART



drizzt
04-08-2008, 12:13 AM
i made this function to return the number of a random world, free or members, for use in SMART

Function GetRandomWorld(Free: Boolean): integer;
var
World: String;
gws, cw, hmw: Integer;
wlist: array of integer;
begin
If Free then World := 'Free'
else World := 'Members';
hmw := StrToInt(ReadINI('Worlds','Count',AppPath + 'Includes\SRL\SCSS\Worlds.ini'))
for gws := 1 to hmw do
begin
if ReadINI('World' + inttostr(gws),'Type',AppPath + 'Includes\SRL\SCSS\Worlds.ini') = World then
begin
cw := Length(Wlist);
SetArrayLength(Wlist,cw + 1);
Wlist[cw] := gws;
end;
end;
Writeln(inttostr(length(Wlist)));
Result := wlist[1 + random(length(hmw))];
end;

also, due to some worlds missing from SRL rev #15, i'll be keeping an updated worlds.ini down here as worlds.txt because .ini files are invalid for uploading, so just resave this as worlds.ini in Includes\SRL\SCSS\Worlds.ini

Zezi
04-08-2008, 01:19 AM
Awesome, tyvm. A very nice function, i'm sure this could be added to srl <3 lol

ZephyrsFury
04-08-2008, 08:18 AM
For me it takes a while for SCAR to access Worlds.ini so if you had an int array of worlds it would be easier to just select one from there.

ie:

function GetRandomWorld(WorldType: (Free, Members, Both)): Integer;
var
FreeWorlds, MemberWorlds, TheWorlds: TIntegerArray;
begin
FreeWorlds := [1, 3, 4, 5, 7, 8, 10, 11, 13, 14, 15, 16, 17, 19, 20, 21, 25, 29, 30, 32,
33, 34, 35, 37, 38, 40, 41, 43, 47, 50, 51, 52, 55, 57, 61, 62,
63, 67, 68, 72, 74, 75, 80, 81, 85, 86, 87, 90, 93, 94, 95, 96,
101, 102, 105, 106, 107, 108, 109, 113, 117, 118, 119, 123, 125,
126, 127, 128, 133, 134, 136, 141, 142, 149, 152, 153, 154, 155];
MemberWorlds := [2, 6, 9, 12, 18, 22, 23, 24, 26, 27, 28, 31, 36, 39, 42, 44, 45,
46, 48, 49, 53, 54, 56, 58, 59, 64, 65, 66, 69, 70, 71, 76, 77,
78, 79, 82, 83, 84, 88, 89, 91, 92, 97, 98, 99, 100, 103, 104,
110, 111, 112, 114, 115, 116, 121, 124, 129, 130, 131, 132,
137, 138, 143, 144, 145, 151, 157, 158, 159];
case WorldType of
Free: TheWorlds := FreeWorlds;
Members: TheWorlds := MemberWorlds;
Both: TheWorlds := CombineIntArray(FreeWorlds, MemberWorlds);
end;
Result := TheWorlds[Random(Length(TheWorlds))];
end;

EvilChicken!
04-08-2008, 12:54 PM
PriSoner actually made a function like this a long time ago, it owns:


{************************************************* ******************************
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;

PriSoner
04-08-2008, 01:55 PM
Thanks for the compliment Evil and thanks for pointing out my function. :D

I was actually gonna mention it but you beat me to it.

Go here (http://www.villavu.com/forum/showthread.php?t=26536?t=28952) if you wish to comment on it or improve upon it: RndWorld(wType) (http://www.villavu.com/forum/showthread.php?t=26536?t=28952)

My function differs in that it you can specify what kind of world you want it to return. F2P, Members or Any.



For me it takes a while for SCAR to access Worlds.ini so if you had an int array of worlds it would be easier to just select one from there.

The advantage of using worlds.ini is that it creates an easy central database to maintain for all functions.

drizzt
04-08-2008, 09:55 PM
thanks guys, and i couldn't find when i wanted to use it so i made it, and figured others could use it.

about going to "any" world..i wouldn't think anyone would use it, because if your player is a member, then you would use members world, because..even if it is at a free place, then its less likely to be packed at on a members server. that was my logic for that

Naum
04-09-2008, 02:40 PM
Very nice work :).
Repped