Results 1 to 7 of 7

Thread: GetRandomWorld function for SMART

  1. #1
    Join Date
    Sep 2007
    Posts
    415
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default GetRandomWorld function for SMART

    i made this function to return the number of a random world, free or members, for use in SMART

    SCAR Code:
    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
    Quote Originally Posted by That guy that wrote forefeathers
    <munklez>haha im too lazy, girls annoy me
    <munklez> they always wanna like, do stuff
    <munklez> and i just wanna program
    <munklez> and they always take all my money

  2. #2
    Join Date
    Oct 2007
    Posts
    302
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Awesome, tyvm. A very nice function, i'm sure this could be added to srl <3 lol
    Previously known as boxcrop.


  3. #3
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    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:
    SCAR Code:
    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;

  4. #4
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    PriSoner actually made a function like this a long time ago, it owns:

    SCAR Code:
    {*******************************************************************************
    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;

  5. #5
    Join Date
    Jan 2008
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for the compliment Evil and thanks for pointing out my function.

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

    Go here if you wish to comment on it or improve upon it: RndWorld(wType)

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


    Quote Originally Posted by ZephyrsFury View Post
    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.
    For the Ultimate Monk Fisher: Ultra Monkfish n Bank Click Here


  6. #6
    Join Date
    Sep 2007
    Posts
    415
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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
    Quote Originally Posted by That guy that wrote forefeathers
    <munklez>haha im too lazy, girls annoy me
    <munklez> they always wanna like, do stuff
    <munklez> and i just wanna program
    <munklez> and they always take all my money

  7. #7
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Very nice work .
    Repped

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2008, 05:20 PM
  2. Replies: 2
    Last Post: 02-26-2008, 08:26 PM
  3. [FUNCTION] FindDoorColour: integer; By ZephyrsFury [FUNCTION]
    By ZephyrsFury in forum Research & Development Lounge
    Replies: 10
    Last Post: 07-27-2007, 08:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •