Results 1 to 16 of 16

Thread: How to use random solvers in OSR

  1. #1
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default How to use random solvers in OSR

    Well hello there! I wrote this guide to help people understand both how the solvers work for OSR as well as how to best implement them into your script.


    Random Detection

    To better understand how the solvers work, how do we detect the randoms?

    Talking Randoms

    As most of you probably know, a good majority of the random events simply require you to talk to the npc (ex: drunken dwarf). For this, the approach in 2007 and the same we took when rewriting the randoms was to detect your player name being said said in the main screen. So we have a handy function to scan what is said in the mainscreen to figure out if something is talking to you and where the figure is positioned. Later in this guide I will discuss the implications of this.

    Combat Randoms

    Another good chunk of the randoms are combat related (ex: evil chicken). We found that the best way to handle this was to simply run away (and then back) if we detected your character is in combat. You are probably thinking..what if we are using a combat script? Well then, as a scripter, you can set SRL_COMBATRANDOMS := False; and it will disable the combat random solvers. Otherwise your character will constantly be running away! More discussion on customizing the combat solver is discussed below.

    Skill Specific Randoms

    For randoms that are skill specific (ex: ent), we are still discussing the best way to handle them. For now, and possibly going forward, it will be the scripters responsibility to detect and solve these.

    Remaining Randoms

    The remaining randoms use a variety of techniques to detect where you are (missing game tabs, music, inventory makeup, etc.). These solvers will either solve your random or, if disable, log you out and switch to the next character (if there is one). Also worth noting, this is the area where random developers need the most help in getting accounts stuck in randoms and is the category with the most work remaining.


    Using and Implementing the Random Solvers

    Generally speaking, all of the randoms are solved using findnormalrandoms;. See below for more specifics.


    Talking Randoms

    As the detection works by scanning for the players name being spoken in the main screen, there are a couple of key things you need to do.

    1) Add a value to the .nick field of the player array like so:
    Simba Code:
    Procedure DeclarePlayers;
    Begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;

      Players[0].Name := '';          // ***Username***
      Players[0].Pass := '';          // ***PW***
      Players[0].WorldInfo  := [];    // ***Desired World, leave blank if random***
      Players[0].Nick := 'man88';          // ***Portion of display name, IMPORTANT FOR RANDOMS***
      Players[0].LampSkill := Skill_Slayer;
      Players[0].Active := True;
    End;

    This will set your nickname for the solver. You should generally just use 3-4 characters from your name (in the above snippet, assuming my name is "Ashaman88", I only put "man88". It must be consecutive characters and you should try and stay away from common 3 letter combos (ex: if your name has "and" in it, probably shouldn't use that, unless you have to). If you do not have anything in here, it WILL cause a runtime error when calling the random solvers. That is why it is important for the scripter to add a failsafe to shutdown the script if there is no value for that (in the future it may be handled by the include).

    2) You MUST call declareplayers BEFORE you call setupsrl. setupsrl handles setting the nickname and will also cause a runtime error if you do not do it in that order (this also may be made to be more flexible in the future). If you still get the runtime error, redownload the include!

    3) Another key thing to note is that it will only search for your nickname when you call findnormalrandoms. This is very important because the NPC's only say your name for about a second every 10seconds? or so. That means you need to call fnr as often as possible (Ex: if you are wc, in the loop you are waiting for the tree to fall calling fnr every 100ms or so). Another possibility is calling a findtalkwait function (more to be added on the actual function name and use) separately, which pauses your script for however long you tell it to and solely searches for your name.

    4) A final important thing to note is that other people near you may cause false positives if they say your name. This is why it is also very important for scripters to set all chats off (or at least public), when starting up the script. You can use the setchat function to do this.

    Combat Randoms

    As mentioned above, you can disable these randoms by setting SRL_COMBATRANDOMS := False; at the start of your script, but you should only do so if you are using a combat script (or don't want your character to run away when under attack).

    Another useful tool we added was to allow the scripter to determine which direction the character will run when it is under attack. This will prevent you from trying to run into an ocean and/or through an enclosed wall. This works by setting SRL_FindRandomRunDirection := ['W', 'N']; (whatever directions you want) at the start of your script. You can set it to just one direction, or all four! If there is more than one direction, the function will randomly select one of the directions to run in. Furthermore, if there are no directions set by the scripter, the function will assume all 4 directions are fair game.

    Again combat randoms are solved and detected by findnormalrandoms.

    Remaining Randoms

    Just call findnormalrandoms


    Conclusion

    As you can see, there is still a lot of work to do and improvements to be made on random solvers. Please see here for the current status of the solvers, and to also suggest new features, and lend accounts in randoms to developers. I will be adding more to this guide as developments occur as well!


    Thanks

    Also be sure to give a big thanks to each of the devs who have worked a lot on these solvers and the OSR include in general

    @Ashaman88; @DannyRS; @euphemism; @J J; @Justin; @Le Jingle; @Ollybest; @slushpuppy


    Please give feedback and suggestions
    Last edited by Ashaman88; 04-07-2013 at 05:14 PM.

  2. #2
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Fantastic guide Ashaman, Gives the user very detailed information on how we detect randoms. Can't wait for future updates on this

    Forum account issues? Please send me a PM

  3. #3
    Join Date
    May 2012
    Location
    John's Creek, Georgia, United States
    Posts
    392
    Mentioned
    0 Post(s)
    Quoted
    86 Post(s)

    Default

    It doesnt matter which characters you choose in your nick right?
    as long as they are consecutive letters

  4. #4
    Join Date
    Jun 2012
    Location
    Howell, Michigan
    Posts
    1,585
    Mentioned
    34 Post(s)
    Quoted
    553 Post(s)

    Default

    Love the guide, nice read and easy to do! I like how it shows everyone how its done(:

  5. #5
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by Physic View Post
    It doesnt matter which characters you choose in your nick right?
    as long as they are consecutive letters
    yep and generally something not common - like if your name has "and" in it, that is probably not a good pick. I'll add more info

  6. #6
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Very nice thread! :] There's some stuffs in here I didn't know until after reading

    I suppose with this, I'll abort (for now) the auto nick parser

    P.S. - [sidenote] I want a leo random

  7. #7
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    Very nice thread! :] There's some stuffs in here I didn't know until after reading

    I suppose with this, I'll abort (for now) the auto nick parser

    P.S. - [sidenote] I want a leo random
    Don't give up! I've been meaning it respond to that thread . Plus it's always good as a backup

  8. #8
    Join Date
    Oct 2011
    Posts
    422
    Mentioned
    15 Post(s)
    Quoted
    116 Post(s)

    Default

    Only if hobbit merges my pull request ;d

  9. #9
    Join Date
    Oct 2011
    Posts
    422
    Mentioned
    15 Post(s)
    Quoted
    116 Post(s)

    Default

    @Ashaman88;

    https://github.com/SRL/SRL-OSR/commi...982322a6fa4df5

    Template:
    Simba Code:
    {$DEFINE ANTIRANDOM_CUSTOMSETSOLVER}
    {$DEFINE SMART}
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}

    .....

    procedure hatetheserandoms(log : Boolean);
    begin
      if FindObjDTM(MouseX,MouseY,upStairsDTM) OR FindObjDTM(MouseX,MouseY,downStairsDTM) then
      begin
        writeln('Hate these randoms');
        Mouse(MouseX,MouseY,0,0,mouse_Left);
        sleep(300);
      end else MakeCompass('n');
      FCRWait(2000);
        if HPPercent(true) < 50 then
      begin
       writeln('Disabling script');
       while not Logout do sleep(100);
       TerminateScript;
       end;
     if log then
      begin
       sleep(12000);
         while not Logout do sleep(100);
        Sleep(5000 + Random(2000));
      end;
    end;
    function AntiRandom_CustomSetSolver(name : String; args : T2DPointArray) : Boolean;
    var
    box : TBox;
    begin
        case name of
        'Poison Gas':
        begin
          if (Length(args) > 0) AND FindObjDTM(MouseX,MouseY,upStairsDTM) then
            begin
                with MiddleTPA(args[0]) do
                begin
                   if Distance(x,y,MSCX,MSCY) < 20 then
                   begin
                   writeln('fcking randoms');
                     hatetheserandoms(false);
                     sleep(50000);
                   end;
              end;
            end;
            Result := True;
          end;
        'Combat Poison':
        begin
          hatetheserandoms(true);
          writeln('Poison detected');
          sleep(50000);
          Result := True;
        end;
        'Combat':
        begin
          writeln('Combat detected')
          hatetheserandoms(true);
          Result := True;
        end;
      end;
    end;
    begin
      {$IFDEF SMART}
        {$IFDEF SIMBAMAJOR980}
          Smart_Server := 72;
          Smart_Members := True;
          Smart_Signed := True;
          Smart_SuperDetail := False;
        {$ELSE}
         // SRL_SixHourFix := True;
          Smart_FixSpeed := True;
        {$ENDIF}
      {$ENDIF}

     
        DeclarePlayers;
      SetupSRL;
      FindNormalRandoms;
      SRL_CombatRandoms := False;
      repeat
      begin
        ...
            FindNormalRandomsCustom([SRL_ThievingRandoms,SRL_CombatRandomsEx]);
        ...
      end;
      until(false);

    end.
    Last edited by slushpuppy; 04-09-2013 at 03:41 PM.

  10. #10
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by slushpuppy View Post
    @Ashaman88;

    https://github.com/SRL/SRL-OSR/commi...982322a6fa4df5

    Template:
    Simba Code:
    {$DEFINE ANTIRANDOM_CUSTOMSETSOLVER}
    {$DEFINE SMART}
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}

    .....

    procedure hatetheserandoms(log : Boolean);
    begin
      if FindObjDTM(MouseX,MouseY,upStairsDTM) OR FindObjDTM(MouseX,MouseY,downStairsDTM) then
      begin
        writeln('Hate these randoms');
        Mouse(MouseX,MouseY,0,0,mouse_Left);
        sleep(300);
      end else MakeCompass('n');
      FCRWait(2000);
        if HPPercent(true) < 50 then
      begin
       writeln('Disabling script');
       while not Logout do sleep(100);
       TerminateScript;
       end;
     if log then
      begin
       sleep(12000);
         while not Logout do sleep(100);
        Sleep(5000 + Random(2000));
      end;
    end;
    function AntiRandom_CustomSetSolver(name : String; args : T2DPointArray) : Boolean;
    var
    box : TBox;
    begin
        case name of
        'Poison Gas':
        begin
          if (Length(args) > 0) AND FindObjDTM(MouseX,MouseY,upStairsDTM) then
            begin
                with MiddleTPA(args[0]) do
                begin
                   if Distance(x,y,MSCX,MSCY) < 20 then
                   begin
                   writeln('fcking randoms');
                     hatetheserandoms(false);
                     sleep(50000);
                   end;
              end;
            end;
            Result := True;
          end;
        'Combat Poison':
        begin
          hatetheserandoms(true);
          writeln('Poison detected');
          sleep(50000);
          Result := True;
        end;
        'Combat':
        begin
          writeln('Combat detected')
          hatetheserandoms(true);
          Result := True;
        end;
      end;
    end;
    begin
      {$IFDEF SMART}
        {$IFDEF SIMBAMAJOR980}
          Smart_Server := 72;
          Smart_Members := True;
          Smart_Signed := True;
          Smart_SuperDetail := False;
        {$ELSE}
         // SRL_SixHourFix := True;
          Smart_FixSpeed := True;
        {$ENDIF}
      {$ENDIF}

     
        DeclarePlayers;
      SetupSRL;
      FindNormalRandoms;
      SRL_CombatRandoms := False;
      repeat
      begin
        ...
            FindNormalRandomsCustoms([SRL_ThievingRandoms,SRL_CombatRandomsEx]);
        ...
      end;
      until(false);

    end.
    Sweet it finally went through! I'll add that section

  11. #11
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    so we dont need to call: SetScreenName(Players[CurrentPlayer].Nick); ?

  12. #12
    Join Date
    Apr 2013
    Posts
    395
    Mentioned
    1 Post(s)
    Quoted
    177 Post(s)

    Default

    Quote Originally Posted by hoodz View Post
    so we dont need to call: SetScreenName(Players[CurrentPlayer].Nick); ?
    It's in the last line of SetupSRL.

  13. #13
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    Quote Originally Posted by Haxz View Post
    It's in the last line of SetupSRL.
    okay thanks!

  14. #14
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    Lovely, how does this sound, split the none-teleportation randoms into two functions that a user can choose from(except sandwich lady and that guy miels/niels):
    A) solve the none-teleportation randoms, genie, the captain, dwarf, strange plant, Jekyll etc..
    B) Run away from them.

    So it would be like this
    Code:
    Const
    Flee := True; // If both are true script will terminate giving the error You cant have both solve and flee from random events on, choose one. 
    Solverandoms := False; 
      
    
    procedure players...; 
    begin....
      Players[0].Nick := 'man88';          // ***Portion of display name, IMPORTANT FOR RANDOMS***
      Players[0].LampSkill := Skill_Slayer;
      Players[0].FleeRandoms := Flee;
      Players[0].SolveRandoms := Solverandoms;
      Players[0].Active := True;
    End;
    its just a thought

  15. #15
    Join Date
    Apr 2013
    Location
    England
    Posts
    223
    Mentioned
    2 Post(s)
    Quoted
    106 Post(s)

    Default

    heyyy ... so in my script i tried to use the FindNonInventoryRandoms most of the time and then threw in a few FindNormalRandoms ... however, it came up with an error when a random popped up ...

    randomFail.png

    sorry if im being stupid or something ...

    got it again ... this is where the issue was ...

    randomsFail.jpg
    Last edited by EngageTheRage; 04-24-2013 at 04:45 PM.

  16. #16
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    I don't script OSR, I don't bot OSR, I don't even play OSR.

    Buuuuut, I definitely think it's awesome the amount of work you guys have all put forth towards the OSR include and what you've all done for the community! Good job!

Thread Information

Users Browsing this Thread

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

Posting Permissions

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