Page 1 of 3 123 LastLast
Results 1 to 25 of 66

Thread: Breakhandler

  1. #1
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default Breakhandler

    NOW WITH MULTIPLAYER SUPPORT

    I had this idea for writing an SRL break handler, so here is what I came up with.
    Simba Code:
    {*******************************************************************************
    function BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer): Boolean;
    By: Echo_
    Description: Takes brakes according to the minute values entered
    *******************************************************************************}

    function BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer): Boolean;
    var
      w, x, y, z: Integer;
    begin
      if not LoggedIn then Exit;

      w := (BreakIn * 60000);
      x := (BreakFor * 60000);
      y := RandomRange(-randBreakIn * 60000, randBreakIn * 60000);
      z := RandomRange(-randBreakFor * 60000, randBreakFor * 60000);

      if (HowManyPlayers = 1) then
      begin
        if (GetTimeRunning < ((w) + (y) + BreakRounds)) then Exit
        else
          if (GetTimeRunning > ((w) + (y) + BreakRounds)) then
          begin
            Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
            Logout;
            Wait((x) + (z));
            Writeln('Logging in.');
            LoginPlayer;
            Result := LoggedIn;
            FindNormalRandoms;
            IncEx(BreakRounds, (w) + (x));
            IncEx(TotalBreaks, 1);
            Writeln('The next break will occur in about ' + IntToStr(BreakIn) + ' minutes.');
          end;
      end;

      if (HowManyPlayers > 1) then
      begin
        if (GetTimeRunning < ((w) + (y) + BreakRounds)) then Exit
        else
          if (GetTimeRunning > ((w) + (y) + BreakRounds)) then
          begin
          Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
          Logout;
          IncEx(BreakRounds, (w));
          IncEx(TotalBreaks, 1);
          NextPlayer(True);
          Exit;
          while (LoggedIn) do Wait((x) + (z));
          NextPlayer(True);
        end;
      end;
    end;

    It's pretty self explanatory.
    BreakIn - The amount of time the procedure will wait before taking a break
    BreakFor - The amount of time the procedure will take a break for
    randBreakIn - Randomness added to the value of BreakIn
    randBreakFor - Randomness added to the value of BreakFor

    You have to declare a global variable in your script named "BreakRounds" so that the procedure will know when to break next after already taking a break.
    Simba Code:
    var
      BreakRounds, TotalBreaks: Integer;

    As you can see, the parameter values are converted to run on minutes rather than milliseconds. So lets say I want my script to take a break after botting for about an hour. I want the break to be a half hour long. I want to have a random amount of time added to those values in the 10 minutes range. Here is what I would add to the beginning of my main loop.

    Simba Code:
    BreakHandler(60, 30, 10, 10);

    Thoughts? Suggestions? I still have to add a debug box timer.

    Credits: Coh3n - tweaked the timers to be more randomized
    Last edited by Echo_; 02-14-2011 at 12:20 AM.

  2. #2
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Perhaps change the parameter variable names to something a bit more understand-able. Like BI could be BreakIn, BF -> BreakFor, rBI -> randBreakIn, rBF -> randBreakFor

    Other than that, nice

  3. #3
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Haha, why isn't there a function in SRL for this? Everyone used it in their script somehow (usually)...or some variation of it to do something.

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


  4. #4
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Perhaps change the parameter variable names to something a bit more understand-able. Like BI could be BreakIn, BF -> BreakFor, rBI -> randBreakIn, rBF -> randBreakFor

    Other than that, nice
    Thanks for the suggestion, I changed variable names

    Quote Originally Posted by HyperSecret View Post
    Haha, why isn't there a function in SRL for this? Everyone used it in their script somehow (usually)...or some variation of it to do something.
    That' s why I decided to write this function, because it is commonly used and not currently included in SRL.
    Last edited by Echo_; 02-09-2011 at 06:13 PM.

  5. #5
    Join Date
    Jul 2008
    Location
    California
    Posts
    255
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Haha great function! I am surprised that this wasn't already in SRL

    I don't understand the importance of the variable w, though. Mind explaining?
    Unfortunately, no active scripts atm.

  6. #6
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    "GetSystemTime" is the amount of time since your computer was booted. By subtracting that from the amount of time you want to BreakIn, you get the amount of time in between the point you turned on your computer and the point that the script started (negative of course, but that' s why I also multiplied it by -1). This provides an accurate number for you to add to your BreakIn integer so that the if statement works correctly. I hope that makes sense

  7. #7
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    I'm assuming you've tested it, so it does in fact break after every 20 minutes, for example?

  8. #8
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Everyone knows how to make this, I'm not saying your work is unneeded, I mean that probably thats the reason it has not been added to SRL yet. I mean this should be added, and I would use this.

    Great work!
    There used to be something meaningful here.

  9. #9
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    I'd like to add this. I think you should have it +/- the random numbers rather than just +.
    Simba Code:
    Number + (RandomRange(-500, 500))
    Also, could someone please explain the logic here because I think I'm missing something. From what I see, without randomness, the two parts in the if statement (the inequality? I think), would always be the same, or very close, no matter the breakIn parameter.

  10. #10
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    I decided to remove that bit and use "GetTimeRunning" instead, thanks for the comment Coh3n. I am testing the function now, it should work with the updated code on the original topic.

  11. #11
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    I don't see this being added as it doesn't really follow the aim of SRL 5. At the very most a function like:
    Simba Code:
    function TakeBreak(Time: Integer): Boolean;
    var
      Ran: Integer;
    begin
      if InRange(Random(10), 1, 5) then
        Logout
      else
        while LoggedIn do
        begin
          FindNormalRandoms;
          Wait(RandomRange(2000, 10000));
        end;
      Time := Time * 60000;
      Ran := Round(Time * 0.30);
      Wait(Time + RandomRange(-Ran, Ran));
      LoginPlayer;
      Result := WaitFunc(@LoggedIn, 200, 3000);
    end;
    may be added, though there should be a param for the Time out option most likely. However, the simplicity of it makes me doubt it.

    Glad your trying to contribute towards the include though.

  12. #12
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    Ok What is the aim of SRL 5 btw?

  13. #13
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    @1st Post: That's a really cool idea but it needs to be turned inside out
    @NCDS: That's good but it needs to be multiplayer or more manageable.

    Take break is a great function.

    But it is not a break handler.

    I'll let u guys work that out

    Besides, BreakHandler is not a procedure.

    BreakHandler is a feature,
    Simba Code:
    Procedure TakeBreak();
    Function TimeToBreak();
    Function TimeFromBreak();

    Procedure SetUpBreaks(t1, t2, t3, t4);
    Procedure SetPlayerBreak(x,y,z,t);

    Some people say I'm a bad teamworker. I'm actually a great team worker. I teach you to be good teamworkers by being a good teamworker myself, and that's what I study. Or one of the things I study. So.... Yeh this is actually good team work init?

    Those function headers I posted are my suggestions for what could and needs and would be well in a break handler.

    There's more, but I haven't really looked into it
    Last edited by Sir R. M8gic1an; 02-10-2011 at 02:47 PM.

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  14. #14
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Sir R. M8gic1an View Post
    @NCDS: That's good but it needs to be multiplayer or more manageable.
    Was just quickly thrown together to show what might have a better chance of being included in SRL 5 (from my point of view), not really meant to be used, though it could be.

    Quote Originally Posted by Echo_ View Post
    Ok What is the aim of SRL 5 btw?
    From my understanding, the simple functions that anyone could write are to be limited/removed for the most part.

  15. #15
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    From my understanding, the simple functions that anyone could write are to be limited/removed for the most part.
    I wouldn't really call a break handler simple that anyone could write. I think it would be a nice feature for people to use in SRL. Just me though.

  16. #16
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    I updated my original post, the code there is now 100% functional and bug free. There are now no excuses for scripts not to have a break handler, it is a great antiban tool. If this doesn't get added to SRL and you decide to use it in any of your scripts, please give me credit for writing it. Thanks to all of the above posters, you guys helped me revise the procedure. Now I'm going to try to implement my idea into Magician's headers

  17. #17
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Request for when 24 hours reports become common again: army (including army of 1) break handling system

    1) Army file with a time card for each player.
    2) LogInEx LogOutEx that updates in and out in file for player.
    3) Global var for total time you expect to run all scripts out of 24 hrs
    4) Var for the max time each player can be logged in per 24 hrs
    5) Var for the max time each player can be logged without break (with another var for +/-)
    6) Var for time you expect to run current script out of 24 hours

    7) Function that is called after every bank/whatever which looks at those variables, and decides whether to stay loggedin, or switch user (switch again if next player also has had too much time), or just wait if all players have had too much time.


    For example, someone has a machine they intend to run scripts on 24 out of 24 hours. They are only running one script, for 24 out of 24 hours. They have 7 players, that should play for a max of 4 hours a day each, of stretches of 15 mins max. So that means 3 hours and 25 mins each (including switch time), per 24 hours. 6 hours into the 24 hours, each player will have done about 3hr25min/4 = 51 mins (made up of pieces <15mins). Let's say 4 players go false all at once (not likely, but it's to just make these example numbers easy). There are 18 hours left for 3 players, meaning 6 hours each, so they would finish the day with 6hr51m each (assuming no resets). However the breakhandler/switcher will stop this, by saying each of the 3 remaining players have 3hr9min left (13 stretches of <15mins), which is 9hrs27 min out of 18 hrs, so it needs to wait 8hr33mins. There will be 13*3 more logins, so between each login, wait 8hr33min/39 = 13.5 mins. This sounds like a lot of calculations, but it takes a few ms and is done after every load. Then if some/all of the 4 players are reset back to true at the 17 hour mark for example, the function re-evaluates and finds that it doesn't need to wait between logins. If max player time per day is longer, or if intended script runtime is shorter, there will be less waiting. Less players means more waiting, works with 1 player also. Also if it could give more time to the players that were reset to even them out that would be awesome, but not terribly important as chances are over time each players bench time will average out.

  18. #18
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Echo_ View Post
    I updated my original post, the code there is now 100% functional and bug free. There are now no excuses for scripts not to have a break handler, it is a great antiban tool. If this doesn't get added to SRL and you decide to use it in any of your scripts, please give me credit for writing it. Thanks to all of the above posters, you guys helped me revise the procedure. Now I'm going to try to implement my idea into Magician's headers
    I'm going to test it right now actually, and see how it goes.

    Quote Originally Posted by Boreas View Post
    Request for when 24 hours reports become common again: army (including army of 1) break handling system

    1) Army file with a time card for each player.
    2) LogInEx LogOutEx that updates in and out in file for player.
    3) Global var for total time you expect to run all scripts out of 24 hrs
    4) Var for the max time each player can be logged in per 24 hrs
    5) Var for the max time each player can be logged without break (with another var for +/-)
    6) Var for time you expect to run current script out of 24 hours

    7) Function that is called after every bank/whatever which looks at those variables, and decides whether to stay loggedin, or switch user (switch again if next player also has had too much time), or just wait if all players have had too much time.


    For example, someone has a machine they intend to run scripts on 24 out of 24 hours. They are only running one script, for 24 out of 24 hours. They have 7 players, that should play for a max of 4 hours a day each, of stretches of 15 mins max. So that means 3 hours and 25 mins each (including switch time), per 24 hours. 6 hours into the 24 hours, each player will have done about 3hr25min/4 = 51 mins (made up of pieces <15mins). Let's say 4 players go false all at once (not likely, but it's to just make these example numbers easy). There are 18 hours left for 3 players, meaning 6 hours each, so they would finish the day with 6hr51m each (assuming no resets). However the breakhandler/switcher will stop this, by saying each of the 3 remaining players have 3hr9min left (13 stretches of <15mins), which is 9hrs27 min out of 18 hrs, so it needs to wait 8hr33mins. There will be 13*3 more logins, so between each login, wait 8hr33min/39 = 13.5 mins. This sounds like a lot of calculations, but it takes a few ms and is done after every load. Then if some/all of the 4 players are reset back to true at the 17 hour mark for example, the function re-evaluates and finds that it doesn't need to wait between logins. If max player time per day is longer, or if intended script runtime is shorter, there will be less waiting. Less players means more waiting, works with 1 player also. Also if it could give more time to the players that were reset to even them out that would be awesome, but not terribly important as chances are over time each players bench time will average out.
    So basically, a system that ensures that all players will only run the specified amount of time?

  19. #19
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    I'm going to test it right now actually, and see how it goes.


    So basically, a system that ensures that all players will only run the specified amount of time?
    Exactly. Switching + waiting in one function that is called every load. And spread out too, not just switch players and set false when they hit their limit and then last 6 hours of the run it's just waiting as all players are false.

  20. #20
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Boreas View Post
    Exactly. Switching + waiting in one function that is called every load. And spread out too, not just switch players and set false when they hit their limit and then last 6 hours of the run it's just waiting as all players are false.
    Sounds like a neat feature.

    As to this function, I tested it out last night and it worked quite well. I made a couple small adjustments.
    Simba Code:
    {*******************************************************************************
    procedure BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer);
    By: Echo_
    Description: Takes brakes according to the minute values entered
    *******************************************************************************}

    var
      BreakRounds: Integer;
    function BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer): Boolean;
    var
      w, x, y, z: Integer;
    begin
      if not LoggedIn then
        Exit;

      Wait(2000 + Random(500));
      w := (BreakIn * 60000);
      x := (BreakFor * 60000);
      y := RandomRange(-randBreakIn * 60000, randBreakIn * 60000);
      z := RandomRange(-randBreakFor * 60000, randBreakFor * 60000);

      if (GetTimeRunning > ((w) + (y) + BreakRounds)) then
      begin
        Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
        Logout;
        Wait(x + z);
        Writeln('Logging in.');
        LoginPlayer;
        Result := LoggedIn;
        FindNormalRandoms;
        IncEx(BreakRounds, (w) + (x));
        Writeln('The next break will occur in about ' + IntToStr(BreakIn) + ' minutes.');
      end;
    end;
    I'd also like to suggest maybe using a loop, then showing how much time is left in the break after every few minutes.

  21. #21
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Sounds like a neat feature.

    As to this function, I tested it out last night and it worked quite well. I made a couple small adjustments.
    Simba Code:
    {*******************************************************************************
    procedure BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer);
    By: Echo_
    Description: Takes brakes according to the minute values entered
    *******************************************************************************}

    var
      BreakRounds: Integer;
    function BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer): Boolean;
    var
      w, x, y, z: Integer;
    begin
      if not LoggedIn then
        Exit;

      Wait(2000 + Random(500));
      w := (BreakIn * 60000);
      x := (BreakFor * 60000);
      y := RandomRange(-randBreakIn * 60000, randBreakIn * 60000);
      z := RandomRange(-randBreakFor * 60000, randBreakFor * 60000);

      if (GetTimeRunning > ((w) + (y) + BreakRounds)) then
      begin
        Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
        Logout;
        Wait(x + z);
        Writeln('Logging in.');
        LoginPlayer;
        Result := LoggedIn;
        FindNormalRandoms;
        IncEx(BreakRounds, (w) + (x));
        Writeln('The next break will occur in about ' + IntToStr(BreakIn) + ' minutes.');
      end;
    end;
    I'd also like to suggest maybe using a loop, then showing how much time is left in the break after every few minutes.
    Wow, I like how this snippet can choose a random integer bigger or smaller rather than just bigger. It adds more of a human-ness to the function, which is what the main point is with antiban I will update the original post.

    I think I will give Boreas' idea a go as well, I think it would be a really nice feature for SRL 5.

  22. #22
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Awesome. I'd like to add this to SRL, but there's a few things I'd like to see first.
    1. Writeln how much time is left in the break. This should help you a little.
      Simba Code:
      procedure TakeBreak();
      var
        t: Integer;
      begin
        Writeln('Breaking');
        Logout();

        t := (GetSystemTime + ((BREAK_FOR * 60000) + RandomRange(-5 * 60000, 5 * 60000)));
        Writeln('Breaking for ' + MsToTime(t - GetSystemTime, TIME_BARE));

        while (GetSystemTime < t) do
        begin
          if (Random(100) < 30) then
            Writeln('Time left: ' + MsToTime(t - GetSystemTime, TIME_BARE));

          Wait(RandomRange(10000, 20000));
        end;

        Inc(Players[CurrentPlayer].Integers[P_BREAKS]);
        Writeln('Continuing');
        LoginPlayer();
        R_FindRandoms();
      end;

    2. Multiplayer support, meaning instead of breaking after the amount of time, if more than one player is active, it will simply switch players instead.

  23. #23
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Awesome. I'd like to add this to SRL, but there's a few things I'd like to see first.
    1. Writeln how much time is left in the break. This should help you a little.
    2. Multiplayer support, meaning instead of breaking after the amount of time, if more than one player is active, it will simply switch players instead.
    Great suggestions

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  24. #24
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I threw this idea out there awhile ago, one that Coh3n just mentioned.

    Instead of breaking for all players, each player gets a "breaktime" and a "sleeptime" variable added. This way you can individually have a player "sleeping" while it runs the other players still. Then it just rotates which player is sleeping or on break etc. This way the script run time isn't wasted and its still running a player at any given time.
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  25. #25
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Awesome. I'd like to add this to SRL, but there's a few things I'd like to see first.
    1. Writeln how much time is left in the break. This should help you a little.
      Simba Code:
      procedure TakeBreak();
      var
        t: Integer;
      begin
        Writeln('Breaking');
        Logout();

        t := (GetSystemTime + ((BREAK_FOR * 60000) + RandomRange(-5 * 60000, 5 * 60000)));
        Writeln('Breaking for ' + MsToTime(t - GetSystemTime, TIME_BARE));

        while (GetSystemTime < t) do
        begin
          if (Random(100) < 30) then
            Writeln('Time left: ' + MsToTime(t - GetSystemTime, TIME_BARE));

          Wait(RandomRange(10000, 20000));
        end;

        Inc(Players[CurrentPlayer].Integers[P_BREAKS]);
        Writeln('Continuing');
        LoginPlayer();
        R_FindRandoms();
      end;

    2. Multiplayer support, meaning instead of breaking after the amount of time, if more than one player is active, it will simply switch players instead.
    Why not just use MSI's then? I've already added human like logging out (time out, wait then logout, etc.) as well as a percentage +/- for randomness quite some time ago. Would be pretty simple to make it work without MSI's types.

Page 1 of 3 123 LastLast

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
  •