SRL Archive - SRL Archives

function SetNickname


muna580

2006-07-07 02:16:12

[PHP]{*******************************************************************************
function SetNick(Name: String): String;
by: Muna580 and Cheesehunk
Description: Takes a username as a parameter and turns it into a 3 or 4 character long nickname.
*******************************************************************************}
function SetNickname(Name: String): String;
var
NameLength, RandomIndexStart, RandomIndexEnd : integer;
var
Nick:string;
begin
repeat
NameLength:= Length(Name);
repeat
RandomIndexStart:= Random(NameLength) + 1;
RandomIndexEnd:= Random(NameLength);
until(RandomIndexEnd > RandomIndexStart);
Nick:= Copy(Name,RandomIndexStart,RandomIndexEnd);
until (Length(Nick) = 3) or (Length(Nick) = 4);
Result:= Nick;
end;[/PHP]

Parameters:
Name:String - The username that you want to convert into a nickname.

Returns:
The nickname of the username given in the parameter.

Example:

Muna580 is una5
Kaitnieks is aitn
Surajd is ura
WhiteShadow is iteS
Wizzup is zup
Cheesehunk is hees
Bego is ego
1337_macro is 133
realrune is rune

XxKanexX

2006-07-07 03:54:21


function SetNick(Name: String): String;
var i: Integer;
begin
repeat
i:= Random(Length(Name));
until(i - 4 <= Length(Name));
Result:= Copy(Name, i, i + (3 + Random(2)));
end;
Shorter and works the same. ;)

Jagex_Fagex

2006-07-07 04:44:11

lol.. kane always come up with smaller scripts.. but do just the same.. or better job XD. anyway.. this could be quite helpful.. i sometimes have trouble in which to set as my nick.. thanks :)

XxKanexX

2006-07-07 05:18:05

Well i come here when i'm bored, so i re-write things. I just only hope the original writers don't mind ;\

WT-Fakawi

2006-07-07 06:06:58

You should not autoset a nickname, but manually! Imagine what will happen if this function picks your nick as "lol" or "lvl".

Set Nick Manual!

Jagex_Fagex

2006-07-07 06:40:16

but fawk.. we could pick it manually.. just get it to print out the nick first and we put it in ourselves if it is good… however. we could also use read line to ask us if it is good. if we say yes. it auto sets it. if we say no. it gets another one?

Starblaster100

2006-07-07 13:05:08

There is also the problem of the script picking you nick name as :

'r b'

from the 2 words

'Star Blaster100'

This causes nick name finding to never work :(

muna580

2006-07-07 16:32:31

From: Starblaster100
There is also the problem of the script picking you nick name as :

'r b'

from the 2 words

'Star Blaster100'

This causes nick name finding to never work :(


Your right, the only problem with the nick maker is that it messes up with names that have spaces in them. And antoher problem that WT-Fakawi said.

They are always solutions to problems like these. We can just use the SetNickname and before the script starts, its going to ask the user to verify it.

WT-Fakawi

2006-07-07 17:31:21

in fact, I believe somewhere in the depths of this forum is a thread devoted to PlayerNames.
I will dig it up for you…


EDIT:
Cant find it, but it all boils down to this:

I give my Player names that have the three letter occurence twice, like: "Echlochlask", where chl is used twice (Players.Nick:='chl'), "Ioplioplala" (Players.Nick:=opl) or "frambouramsi" (Players.Nick:='ram')This makes it easier for FindTalk to find the name…

Starblaster100

2006-07-07 18:16:38

Here is something i made long ago for SRL Users to create a nickname out of the Username, i use it in all my scripts.

[php]
function FindBiggestString(What : string): string;
var
TheString : array[1..3]of string;
iNumber, cNumber : integer;
begin
For cNumber := 1 to 3 do
begin
If(CNumber > 1) then
Delete(What, 1, 1);
for iNumber := 1 to 30 do
begin
TheString[cNumber] := TheString[cNumber] + Copy(What, 1, 1);
Delete(What, 1, 1);
If(pos(' ', What) = 1)then
break;
end;
end;
if(Length(TheString[1]) > Length(TheString[2]))and
(Length(TheString[1]) > Length(TheString[3]))then
Result := TheString[1];
if(Length(TheString[2]) > Length(TheString[1]))and
(Length(TheString[2]) > Length(TheString[3]))then
Result := TheString[2];
if(Length(TheString[3]) > Length(TheString[1]))and
(Length(TheString[3]) > Length(TheString[2]))then
Result := TheString[3];
end;

function CreateNick(What : string): string;
begin
Result := What;
If(Length(Result) > 4) then
begin
repeat
Delete(Result, 1, 1);
Delete(Result, Length(Result), Length(Result));
until (Length(Result)<=4)
if (pos(' ', Result) = 1) or (pos(' ', Result) = Length(Result))then
delete(Result, pos(' ', Result), 1);
end;
end;

NickNameBMP := CreateBitmapMaskFromText(CreateNick(FindBiggestString(Players[CurrentPlayer].Name)), UpChars);
[/php]

Its very useful. Finds the biggest string out of 3 words and creates a nickname based on the biggest word. This eliminates the spaces problem