Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 66

Thread: Breakhandler

  1. #26
    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
    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.
    I think MSI's and this one could be combined. I really like how this one doesn't require a temporary time like MSI's. This uses just one global variable and take advantage of GetSystemTime.

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

    Default

    What temporary time?
    Simba Code:
    procedure MSI_HandleBreaking;
    var
      t, _avg: Integer;
    begin
      if (not LoggedIn) then
        Exit;

      if not MSI_SetupVars[SETUP_HUMAN_BREAK] then
        if MSI_Players[CurrentPlayer].BreakTime = 0 then
          if MSI_SetupVars[SETUP_BREAK_TIME] = 0 then
            Exit;

      if (BankScreen) then
        CloseBank;

      MSI_AddHeader('MSI_HandleBreaking');

      if (HowManyPlayers = 1) or (PlayersActive = 1) then
      begin
        MSI_Debug('Taking a short break');

        if MSI_SetupVars[SETUP_HUMAN_BREAK] then
          case Random(10) of

            0, 2: Logout;

            1: while LoggedIn do
                 MSI_FindRandoms(False);

            3..6: begin
                    t := (GetSystemTime + RandomRange(60000, 60000 * 3));
                    while (t > GetSystemTime) and LoggedIn do
                      MSI_FindRandoms(False);
                    if LoggedIn then
                      if InRange(Random(10), 1, 5) then
                        Logout
                      else
                        ExitToLobby;
                  end;

            7..9: ExitToLobby;
          end
        else
          if InRange(Random(10), 2, 9) then
            ExitToLobby;

        _avg := Round(SETUP_BREAK_TIME * RANDOM_TIME_PERCENT);
        t := (GetSystemTime + ((MSI_SetupVars[SETUP_BREAK_TIME] * 60000) + RandomRange(-_avg * 60000, _avg * 60000)));
        while GetSystemTime < t do
        begin
          Status('MSI_SetupVars[SETUP_BREAK_TIME] remaining: '+MsToTime(t - GetSystemTime, Time_Formal)+';');
          Wait(RandomRange(2000, 25000));
          if LoggedIn then
            MSI_FindRandoms(True);
        end;

        MSI_Debug('Break over, continuing to play');

        if (LobbyScreen) then
          MouseBox(80, 450, 560, 470, 1);
      end else
      begin
        MSI_Debug('Switching players');
        NextPlayer(True);
      end;

      WaitFunc(@LoggedIn, 100, 15000);

      stats_IncVariable('Total Logins', 1);
      MSI_CloseHeader('MSI_HandleBreaking: ' + BoolToStr(LoggedIn));
    end;
    That's pretty much what I've always used, just with all the MSI stuff removed (obviously) :P

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

    Default

    Quote Originally Posted by Narcle View Post
    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.
    That's actually what I' m adding right now. I had an idea, but I need some feedback. Should I have the time left for each break displayed on the SMART canvas or in the debug box? I can do it either way, I just need some opinions. I'm also testing my multiplayer implementation right now, I will post it if it works.

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

    Default

    Quote Originally Posted by Echo_ View Post
    That's actually what I' m adding right now. I had an idea, but I need some feedback. Should I have the time left for each break displayed on the SMART canvas or in the debug box? I can do it either way, I just need some opinions. I'm also testing my multiplayer implementation right now, I will post it if it works.
    debug box. Displaying on the canvas makes some people lag too much. Also, not everyone uses SMART all the time

  5. #30
    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
    What temporary time?
    It's in the mainloop. MarkTime() is called each time it switches players, and TimeFromMark is checked after each load.

    Yeah, could probably use MSI's with some modifications.

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

    Default

    I got the breakhandler to work with 2 players now It now reads how many players are active, and if there are 2 players active, the script will break then log into players[1]. After players[0]' s break has finished, it will then log out of players[1] and log back into players[0]. I also added a total breaks variable for progress reports. I'm still working on adding a continuous breaking timer for the debug box and multiplayer support for up to 5 players Here's the code if you want to look it over or test it.

    global vars:
    Simba Code:
    var
      BreakRounds, TotalBreaks: Integer

    Break handler:
    Simba Code:
    {*******************************************************************************
    procedure BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer);
    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 = 2) 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) + (x));
          IncEx(TotalBreaks, 1);
          Writeln('Logging in to ' + Capitalize(Players[1].Nick) + '.');
          NextPlayer(True);
          Exit;
          while (CurrentPlayer = 1) do Wait((x) + (z));
          Writeln('Switching back to ' + Capitalize(Players[0].Nick) + '.');
          SwitchToPlayer(0, True);
          end;
      end;
    end;

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

    Default

    Couldn't you just do if HowManyPlayers >= 2 then?
    There used to be something meaningful here.

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

    Default

    I was planning on doing one for each amount of players, not just 1, 2, and 5.

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

    Default

    Quote Originally Posted by Echo_ View Post
    I was planning on doing one for each amount of players, not just 1, 2, and 5.
    No, just make one where HowManyPlayers is greater then 1 or greater then or equals to 2, and do NextPlayer.

    That way its dynamic to any amount of players.
    There used to be something meaningful here.

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

    Default

    So something kind of like this then?
    Simba Code:
    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) + (x));
          IncEx(TotalBreaks, 1);
          Writeln('Logging in to ' + Capitalize(Players[CurrentPlayer + 1].Nick) + '.');
          NextPlayer(True);
          Exit;
          while (LoggedIn) do Wait((x) + (z));
          Writeln('Switching back to ' + Capitalize(Players[CurrentPlayer - 1].Nick) + '.');
          SwitchToPlayer(CurrentPlayer - 1, True);
          end;
      end;

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

    Default

    Quote Originally Posted by Echo_ View Post
    So something kind of like this then?
    Simba Code:
    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) + (x));
          IncEx(TotalBreaks, 1);
          Writeln('Logging in to ' + Capitalize(Players[CurrentPlayer + 1].Nick) + '.');
          NextPlayer(True);
          Exit;
          while (LoggedIn) do Wait((x) + (z));
          Writeln('Switching back to ' + Capitalize(Players[CurrentPlayer - 1].Nick) + '.');
          SwitchToPlayer(CurrentPlayer - 1, True);
          end;
      end;
    Whats with the "SwitchToPlayer"? Why don't you just use NextPlayer?
    There used to be something meaningful here.

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

    Default

    It eventually has to switch back to the first player in a loop.

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

    Default

    NextPlayer should take care of that.
    There used to be something meaningful here.

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

    Default

    Thanks Frement, you saved me a lot of unneeded work I updated my OP, all I have left to add is the debug box timer.

  15. #40
    Join Date
    Apr 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I still have to add a debug box timer.

  16. #41
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Sir R. M8gic1an View Post
    @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
    Simba Code:
    const
      BREAK_EVERY = 0;
      BREAK_RAND = 1;
      BREAK_PREV = 2;
      BREAK_NEXT = 3;

    type
      TBreakProc = procedure;

    var
      BreakHandler: array[BREAK_EVERY..BREAK_NEXT] of extended;
      BreakProc: TBreakProc;

    procedure ResetBreak;
    begin
      BreakHandler[BREAK_NEXT] := GetSystemTime + (BreakHandler[BREAK_EVERY] + Random(BreakHandler[BREAK_RAND]));
    end;

    procedure FBreak;
    begin
      BreakHandler[BREAK_PREV] := GetSystemTime;
      if (BreakProc <> nil) then
        BreakProc();
      ResetBreak;
    end;

    procedure Break;
    begin
      if (GetSystemTime > BreakHandler[BREAK_NEXT]) then
        FBreak;
    end;

    function TimeToBreak: extended;
    begin
      Result := BreakHandler[BREAK_NEXT];
    end;

    function TimeFromBreak: extended;
    begin
      Result := BreakHandler[BREAK_PREV];
    end;

    procedure SetupBreaks(Break: TBreakProc; BreakEvery, Randomness: extended);
    begin
      BreakProc := @Break;
      BreakHandler[BREAK_EVERY] := BreakEvery;
      BreakHandler[BREAK_RAND] := Randomness;
    end;

    1. Include BreakHandler above.
    2. SetupBreaks(@YourBreakProc, BreakEveryMS, RandomNess);
    3. ResetBreaks; (Do this every time you switch players);
    4. Add Break; to a location in your main loop where the player can break!
    5. Add FBreak; to locations you want to force a break even if the timer hasn't expired!
    Last edited by Dgby714; 04-29-2011 at 11:13 PM.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  17. #42
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Bump.

    This seems good to implement.

    Do you mind me using/changing it in one of my scripts?
    "Logic never changes, just the syntax" - Kyle Undefined?

    Remember, The Edit Button Is There For A Reason!!!

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

    Default

    Quote Originally Posted by Yago View Post
    Bump.

    This seems good to implement.

    Do you mind me using/changing it in one of my scripts?
    Go for it, just give me some credits

  19. #44
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    I've used it in all of my scripts, very stable, very reliable.

    I did, however modify a few things here and there in relevance to my script, but there was one small fix I had for you.

    Where you have this:
    Simba Code:
    Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
    It actually writes how much initial break time it will spend, not counting the random +/- minutes it has added to the break time. For example, if you had an initial break time set for 10 minutes with a 5 minute randomness, it'll say, every time, that the break will last for 10 minutes.

    So I declared this within the function:
    Simba Code:
    RealBTime: integer;
    And changed this:
    Simba Code:
    Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
    To this:
    Simba Code:
    RealBTime := ((x+z)/60000);
              Writeln('Taking a break for about ' + IntToStr(RealBTime) + ' minutes.');

    Works like a charm.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  20. #45
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Echo_ View Post
    Go for it, just give me some credits
    First sorry for the grammer. Im on an ipod.
    This should be implemented or at least used more imo. It took me some time (a few days(like my free time)) to make my own break system and it has many flaws.

    I let u know what i think after testing it.
    "Logic never changes, just the syntax" - Kyle Undefined?

    Remember, The Edit Button Is There For A Reason!!!

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

    Default

    What system are you guys using? The one Dgby posted or the one Echo_ posted?

  22. #47
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Echo_'s. I don't see why we should use anything differently.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  23. #48
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    What system are you guys using? The one Dgby posted or the one Echo_ posted?
    Updated mine =)

    Found a bug in my randomness and added a few things.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

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

    Default

    Quote Originally Posted by Dgby714 View Post
    Updated mine =)

    Found a bug in my randomness and added a few things.
    I didn't look at yours too much, but is it meant to be used in combination with Echo_'s?

  25. #50
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    I didn't look at yours too much, but is it meant to be used in combination with Echo_'s?
    No, mine is completely different.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

Page 2 of 3 FirstFirst 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
  •