PDA

View Full Version : Breakhandler



Echo_
02-09-2011, 12:33 PM
NOW WITH MULTIPLAYER SUPPORT :)

I had this idea for writing an SRL break handler, so here is what I came up with.
{************************************************* ******************************
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.

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.

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

Zyt3x
02-09-2011, 04:34 PM
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 :)

HyperSecret
02-09-2011, 05:30 PM
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.

Echo_
02-09-2011, 06:06 PM
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 :)


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.

doom0791
02-09-2011, 06:27 PM
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?

Echo_
02-09-2011, 06:38 PM
"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 :p

Coh3n
02-09-2011, 07:44 PM
I'm assuming you've tested it, so it does in fact break after every 20 minutes, for example?

Frement
02-09-2011, 08:35 PM
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!

Coh3n
02-10-2011, 01:09 AM
I'd like to add this. I think you should have it +/- the random numbers rather than just +.

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.

Echo_
02-10-2011, 04:08 AM
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.

NCDS
02-10-2011, 04:26 AM
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:

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. :)

Echo_
02-10-2011, 02:23 PM
Ok :( What is the aim of SRL 5 btw?

Sir R. M8gic1an
02-10-2011, 02:41 PM
@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,

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

NCDS
02-10-2011, 08:48 PM
@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. :p


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.

Coh3n
02-10-2011, 08:59 PM
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.

Echo_
02-11-2011, 04:18 AM
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 :D

Boreas
02-11-2011, 05:52 AM
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.

Coh3n
02-11-2011, 07:25 AM
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 :D
I'm going to test it right now actually, and see how it goes. :)


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? :o

Boreas
02-11-2011, 04:53 PM
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? :o

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.

Coh3n
02-11-2011, 07:17 PM
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.

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

Echo_
02-12-2011, 12:40 AM
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.

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

Coh3n
02-12-2011, 12:46 AM
Awesome. I'd like to add this to SRL, but there's a few things I'd like to see first.

Writeln how much time is left in the break. This should help you a little. ;)
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;



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

Sir R. M8gic1an
02-12-2011, 12:56 AM
Awesome. I'd like to add this to SRL, but there's a few things I'd like to see first.

Writeln how much time is left in the break. This should help you a little. ;)

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

Narcle
02-12-2011, 05:47 AM
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.

NCDS
02-12-2011, 05:51 AM
Awesome. I'd like to add this to SRL, but there's a few things I'd like to see first.

Writeln how much time is left in the break. This should help you a little. ;)
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;



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.

Coh3n
02-12-2011, 08:58 AM
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.

NCDS
02-12-2011, 02:41 PM
What temporary time?

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

Echo_
02-12-2011, 08:04 PM
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.

NCDS
02-12-2011, 08:09 PM
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 ;)

Coh3n
02-13-2011, 06:27 AM
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.

Echo_
02-13-2011, 10:01 PM
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 :D Here's the code if you want to look it over or test it.

global vars:
var
BreakRounds, TotalBreaks: Integer

Break handler:
{************************************************* ******************************
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;

Frement
02-13-2011, 10:14 PM
Couldn't you just do if HowManyPlayers >= 2 then?

Echo_
02-13-2011, 10:17 PM
I was planning on doing one for each amount of players, not just 1, 2, and 5.

Frement
02-13-2011, 10:22 PM
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.

Echo_
02-13-2011, 10:38 PM
So something kind of like this then?
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;

Frement
02-13-2011, 10:40 PM
So something kind of like this then?
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?

Echo_
02-13-2011, 10:41 PM
It eventually has to switch back to the first player in a loop.

Frement
02-13-2011, 10:49 PM
NextPlayer should take care of that.

Echo_
02-14-2011, 12:19 AM
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.

jannypan
04-13-2011, 08:48 AM
I still have to add a debug box timer.

Dgby714
04-13-2011, 09:25 AM
@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,

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


Include BreakHandler above.
SetupBreaks(@YourBreakProc, BreakEveryMS, RandomNess);
ResetBreaks; (Do this every time you switch players);
Add Break; to a location in your main loop where the player can break!
Add FBreak; to locations you want to force a break even if the timer hasn't expired!

Yago
04-28-2011, 10:41 PM
Bump.

This seems good to implement.

Do you mind me using/changing it in one of my scripts?

Echo_
04-29-2011, 12:30 AM
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 ;)

Flight
04-29-2011, 12:44 AM
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:
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:
RealBTime: integer;
And changed this:
Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
To this:
RealBTime := ((x+z)/60000);
Writeln('Taking a break for about ' + IntToStr(RealBTime) + ' minutes.');

Works like a charm. :)

Yago
04-29-2011, 03:41 AM
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.

Coh3n
04-29-2011, 03:58 AM
What system are you guys using? The one Dgby posted or the one Echo_ posted?

Flight
04-29-2011, 08:06 AM
Echo_'s. I don't see why we should use anything differently.

Dgby714
04-29-2011, 11:14 PM
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.

Coh3n
05-02-2011, 02:54 AM
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?

Dgby714
05-02-2011, 05:07 AM
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.

Coh3n
05-02-2011, 06:00 AM
No, mine is completely different.
I feel like having it in one procedure would be simpler, no?

Dgby714
05-02-2011, 06:25 AM
I feel like having it in one procedure would be simpler, no?
I just seen what Sir R. M8gic1an posted and made something along those lines I havn't even looked at Echo_s.

Flight
05-02-2011, 11:41 AM
Echo_'s is just one function, and you call it within you're script's loop. I hope that answers your question.

theheretic
05-02-2011, 12:19 PM
This is perfect, going to use this in my scripts :D

Yago
05-02-2011, 08:49 PM
Hey Echo instead of howmanyplayers what do you think about players active?

Echo_
05-03-2011, 12:21 AM
Hey Echo instead of howmanyplayers what do you think about players active?

I think that would work too, but I believe in the "if it's not broken, don't fix it" policy ;)

Coh3n
05-03-2011, 12:35 AM
I think that would work too, but I believe in the "if it's not broken, don't fix it" policy ;)
Yes, but in this situation PlayersActive makes more sense.

Yago
05-03-2011, 01:36 AM
I think that would work too, but I believe in the "if it's not broken, don't fix it" policy ;)

Then it would be broken because if there aren't any active players the thing might fail.

Coh3n
12-13-2011, 05:48 AM
So, just found this thread. If no one disagrees I think I'll add this (along with the Global variables) to SRL's antiban.simba.

Sound okay?

E: I'd still like to see "Time left in break: " added.

Sir R. M8gic1an
12-13-2011, 01:24 PM
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; // notice this?
while (LoggedIn) do Wait((x) + (z));
Writeln('Switching back to ' + Capitalize(Players[CurrentPlayer - 1].Nick) + '.');
SwitchToPlayer(CurrentPlayer - 1, True);
end;
end;


Actually this never switches back to the original player... all this function really does is put a timer on your NextPlayer call / break if theres only one player left. You'd need yet another if statement at the top if you actually wanted to switch back to the player who was on break..

As for Dbgy's system it doesn't currently have the whole login logout stuff so...

-RM

Dgby714
12-13-2011, 01:48 PM
Actually this never switches back to the original player... all this function really does is put a timer on your NextPlayer call / break if theres only one player left. You'd need yet another if statement at the top if you actually wanted to switch back to the player who was on break..

As for Dbgy's system it doesn't currently have the whole login logout stuff so...

-RM

Mine lets people do what they wand in the procedure they pass to SetupBreaks. Mine doesn't actually handle the breaks.

Coh3n
12-13-2011, 06:54 PM
I actually think I'm going to make an "SRL Snippets" section for code just like this. This stuff I think should be done in scripts, not the include (I know, I changed my mind). We want the include to aid the scripter, not do everything for them, if that makes sense.

E: Moved to SRL Snippets.

Jeames27
11-27-2018, 06:15 PM
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.

KeepBotting
11-28-2018, 01:14 AM
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.

There is a break system in SRL, see https://srl.github.io/SRL/antiban.html

the bank
11-28-2018, 01:43 AM
There is a break system in SRL, see https://srl.github.io/SRL/antiban.html

Duplicate of this post https://villavu.com/forum/showthread.php?t=62216&p=777429#post777429

Probably just a bot. Or somebody really not trying very hard for junior.

Bess52
03-01-2019, 01:39 AM
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!