SRL Archive - OSR Help

Shorter code?


DeSnob

2010-05-16 13:07:33

I feel something fishy about this proc in my fishing bot (no pun intended) I know it can be shortened but don't know any way to shorten it anymore! Can somebody look at this and just tell me what to do to make it smaller?
{Setting 1 = Stay offline   Setting 2 = Log back on Setting 3 = nothing}
procedure WaitR(reason: string; time, randomness, setting: integer; myantiban, randoms, mylogout, error: boolean);
var
waittime: integer;
begin
waittime := time + randomness;

if (error) then Writeln('INFO: **Error** ' + reason + ': ' + IntToStr(waittime)) else
Writeln('INFO: ' + reason + ': ' + IntToStr(waittime));
if (myantiban) then AntiBan;
if (randoms) then FindNormalRandoms;
if (mylogout) then
begin
if (LoggedIn) then
begin
if (LogOut) then Writeln('INFO: WaitR/ Logged out.');
end else
begin Writeln('INFO: **Error** Was already logged out!'); Exit; end;
end;

Wait(time+random(randomness));
case (setting) of
1: if (LoggedIn) then
begin
LogOut;
TerminateScript;
end else
begin
Writeln('INFO: WaitR/ Staying offline. Terminating.');
LogOut;
TerminateScript;
end;
2: begin LogInPlayer; Writeln('INFO: Logged back on.'); end;
3: exit;
end;
end;

Awkwardsaw

2010-05-16 13:13:03

you can remove the 3 in the setting case, :)

also, less lines doesnt make it faster.. standardized:

procedure WaitR(reason: string; time, randomness, setting: integer; myantiban, randoms, mylogout, error: boolean);
var
waittime: integer;
begin
waittime := time + randomness;
if (error) then
Writeln('INFO: **Error** ' + reason + ': ' + IntToStr(waittime))
else
Writeln('INFO: ' + reason + ': ' + IntToStr(waittime));
if (myantiban) then
AntiBan;
if (randoms) then
FindNormalRandoms;
if (mylogout) then
begin
if (LoggedIn) then
begin
if (LogOut) then
Writeln('INFO: WaitR/ Logged out.');
end else
begin
Writeln('INFO: **Error** Was already logged out!');
Exit;
end;
end;
Wait(time+random(randomness));
case (setting) of
1: if (LoggedIn) then
LogOut
else
begin
Writeln('INFO: WaitR/ Staying offline. Terminating.');
LogOut;
TerminateScript;
end;
2:
begin
LogInPlayer;
Writeln('INFO: Logged back on.');
end;
end;
end;

DeSnob

2010-05-16 13:20:41

From: Awkwardsaw
you can remove the 3 in the setting case, :)

also, less lines doesnt make it faster.. standardized:

procedure WaitR(reason: string; time, randomness, setting: integer; myantiban, randoms, mylogout, error: boolean);
var
waittime: integer;
begin
waittime := time + randomness;
if (error) then
Writeln('INFO: **Error** ' + reason + ': ' + IntToStr(waittime))
else
Writeln('INFO: ' + reason + ': ' + IntToStr(waittime));
if (myantiban) then
AntiBan;
if (randoms) then
FindNormalRandoms;
if (mylogout) then
begin
if (LoggedIn) then
begin
if (LogOut) then
Writeln('INFO: WaitR/ Logged out.');
end else
begin
Writeln('INFO: **Error** Was already logged out!');
Exit;
end;
end;
Wait(time+random(randomness));
case (setting) of
1: if (LoggedIn) then
LogOut
else
begin
Writeln('INFO: WaitR/ Staying offline. Terminating.');
LogOut;
TerminateScript;
end;
2:
begin
LogInPlayer;
Writeln('INFO: Logged back on.');
end;
end;
end;


It's not that i want to make it faster, i want to make it "neater"

nielsie95

2010-05-16 13:25:03

It doesn't get much shorter than:


procedure WaitR(reason: string; time, randomness, setting: integer; myantiban, randoms, mylogout, error: boolean);
begin
if error then
reason := reason + '**Error** ';
Writeln('INFO: ' + reason + ': ' + IntToStr(time + randomness));

if myantiban then
AntiBan;
if randoms then
FindNormalRandoms;
if mylogout then
if (not LoggedIn) then
begin
Writeln('INFO: **Error** Was already logged out!');
Exit;
end
else if LogOut then
Writeln('INFO: WaitR/ Logged out.');

Wait(time+random(randomness));
case setting of
1: //Stay offline
begin
if (not LoggedIn) then
Writeln('INFO: WaitR/ Staying offline. Terminating.');
LogOut;
TerminateScript;
end;
2: //Log back on
begin
LogInPlayer;
Writeln('INFO: Logged back on.');
end;
3: Exit; //nothing
end;
end;

DeSnob

2010-05-16 14:52:59

ty :D even better!