SRL Archive - SRL Archives

RandomSend


Tniffoc

2008-09-21 12:53:41

I think that this would shorten a lot of anti-ban procedures in scripts. It says a random thing from the array of strings in it's argument. Please post reviews/comments here! This would go in either Text.scar with TypeSend, or AutoTalk.scar which is empty!


{*******************************************************************************
procedure RandomSay;
By: King of Knives with revision by Tniffoc
Description: Says a random string from the array provided to it.
*******************************************************************************}
procedure RandomSay(toSay: array of string);
var
lengthOfArray: Integer;
begin
lengthOfArray:= Length(toSay);
if (lengthOfArray=0) then
begin
srl_Warn('RandomSay;','No strings were provided!');
Exit;
end;
if (not (toSay[Random(lengthOfArray)]='') then
TypeSend(toSay[Random(lengthOfArray)])
else
srl_Warn('RandomSay', 'The string provided in the array is empty!', -1);
end;


Nava2

2008-09-21 13:43:04

Where is the random part…

Tniffoc

2008-09-21 14:34:06

oh wow, I ctr-c'd before I added that… DUH!
Update

lordsaturn

2008-09-21 14:36:36

shortened to 13 lines:

procedure RandomSay(toSay: array of string);
var
i: Integer;
begin
i:= High(toSay);
if(Length(toSay) > 0)then
if(not (toSay[i] = ''))then
TypeSend(toSay[i])
else
Writeln('ERROR in RandomSay: The string provided in the array was empty!');
else
Writeln('ERROR in RandomSay: No Strings were defined!');
end;

Tniffoc

2008-09-21 14:41:28

From: lordsaturn
shortened to 13 lines:

procedure RandomSay(toSay: array of string);
var
i: Integer;
begin
i:= High(toSay);
if(Length(toSay) > 0)then
if(not (toSay[i] = ''))then
TypeSend(toSay[i]);
else
Writeln('ERROR in RandomSay: The string provided in the array was empty!');
else
Writeln('ERROR in RandomSay: No Strings were defined!');
end;


I did think about that method but it doesn't compile.

Identifier expected in script

TViYH

2008-09-21 15:24:30


procedure RandomSay(toSay: array of string);
var
i: Integer;
begin
i:= High(toSay);
if(Length(toSay) > 0)and(not (toSay[i] = '')) then
begin
TypeSend(toSay[i]);
end else
srl_Warn('RandomSay;', 'The string provided in the array is empty.', -1);
end;

JuKKa

2008-09-21 15:47:53


{.Include srl/srl.scar}

//Credits to JuKKa (hes awesome)
Procedure RandomSay(txt: TStringArray);
Var
I: Integer;
Begin
I := Random(High(txt) + 1);
If(Length(Txt[I]) > 0)Then
TypeSend(Txt[I])
Else
srl_Warn('RandomSay;', 'The string provided in the array is empty.', -1);
End;


Begin
repeat
RandomSay(['shit', 'face', 'cunt', 'ass']);
until false
End.

And credits…

Tniffoc

2008-09-21 16:07:38

Updated!

Thank you to Jukka & TVIYH

lordsaturn

2008-09-21 16:30:46

:p


procedure RandomSay(toSay: TStringArray);
var
s: string;
begin
if Length(toSay) = 0 then
begin
srl_Warn('RandomSay', 'The array provided is empty!', -1);
Exit;
end;
s := toSay[Random(Length(toSay))];
if (s = '') then
srl_Warn('RandomSay', 'The string provided in the array is empty!', -1)
else
TypeSend(s);
end;

Tniffoc

2008-09-21 16:35:31

From: lordsaturn
:p


procedure RandomSay(toSay: array of string);
var
s: string;
begin
if Length(toSay) = 0 then Exit;
s := toSay[Random(Length(toSay))];
if (s = '') then
srl_Warn('RandomSay', 'The string provided in the array is empty!', -1)
else
TypeSend(s);
end;


Sorry, but I don't like extra memory usage like that. I like my version more. Sry.

King of Knives

2008-09-21 17:53:42

I'll join in!


procedure RandomSay(toSay: array of string);
begin
if Length(toSay)=0 then Exit;
if not (toSay[Random(Length(toSay))]='') then TypeSend(toSay[Random(Length(toSay))])
else srl_Warn('RandomSay', 'The string provided in the array is empty!', -1);
end;
Dusting off my old SCAR-skills :p.

-Knives

Tniffoc

2008-09-21 19:17:17

From: King of Knives
I'll join in!


procedure RandomSay(toSay: array of string);
begin
if Length(toSay)=0 then Exit;
if not (toSay[Random(Length(toSay))]='') then TypeSend(toSay[Random(Length(toSay))])
else srl_Warn('RandomSay', 'The string provided in the array is empty!', -1);
end;
Dusting off my old SCAR-skills :p.

-Knives


Wow, you just owned us all… I just did a few minor edits so you weren't calling Length so much. I also fixed some standards.

lordsaturn

2008-09-21 21:39:53

From: tniffoc
Sorry, but I don't like extra variables like that. I like my version more. Sry.



There are the same number of variables… :p

Tniffoc

2008-09-21 22:27:43

From: lordsaturn
There are the same number of variables… :p

Rofl. Correct me if I'm wrong, but an integer takes up less space than a string, correct?

TViYH

2008-09-21 22:30:34

But when you say it takes up more space, that doesn't mean there are more variables.

Tniffoc

2008-09-21 23:03:23

From: TheVoiceInYourHead
But when you say it takes up more space, that doesn't mean there are more variables.


I know, I just blabbed it out incorrectly. Here, I'll edit my post. :)