ID:161442
 
Well here's what I have so far...
mob/var
Names=list()
Legals=list("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
mob/verb
Create()
Step1
var/Name=input("Please enter your name. 4-16 characters","Name",usr.key)as text
if(!Name)
goto Step1
if(length(Name)<4)
usr<<"Your name must be between 4-16 characters!"
goto Step1
if(length(Name)>16)
usr<<"Your name must be between 4-16 characters!"
goto Step1
else
var/N=lowertext(Name)
if(N in Names)
usr<<"This name already exists, please find a new one!"
goto Step1
else
var/Firstletter=copytext(N,1,2)
if(Firstletter in Legals)
Firstletter=uppertext(Firstletter)
var/Afterletters=copytext(N,2,0)
Afterletters=lowertext(Afterletters)
Name="[Firstletter][Afterletters]"
usr<<"[Name]"
Names+=N
else
usr<<"Your name cannot contain any illegal characters outside of A-Z!"
goto Step1

But what I am wondering is a few questions.

1) Is this an efficient way to do this or no.

2) How do you check all the letters after the first one for illegal characters???

Godzooks wrote:
1) Is this an efficient way to do this or no.

Yes.

2) How do you check all the letters after the first one for illegal characters???

See below.

var/list/names = list("Admin", "Administrator")
mob/verb/Create()
var/name

while(!name) //a loop is made that cannot be exited unless we have a proper name (or if the player logs out)
name = input(usr, "Please input a name.", "Create") as null|text
if(name == null) return //the player aborted by clicking "Cancel"

//first, we check the length of the name.
var/length = length(name)
if(length < 4 || length > 16)
name = null
alert(usr, "Your name can be no more than 16 characters, and may be no less than 4.", "Create - Error")
continue

//next, we check if it contains letters. If it contains numbers or symbols it will be rejected.\
see http://www.asciitable.com for a the list (you'll want to look at "Dec")

var/i
for(i = 1 to length)
var/char = text2ascii(name, i)
if(char < 65 || char > 122) break
if(char > 91 && char < 96) break
if(i)
name = null
alert(usr, "Your name may only contain letters. (A-z)", "Create - Error")
continue

//finally, we check if the name was already chosen or has been reserved
if(name in names)
name = null
alert(usr, "The specified name already exists or has been flagged as 'reserved'.", "Create - Error")
continue

if(!client) return //player has logged out; this is unnessesary if the mob is deleted upon logout

... //continue with the rest of the steps

names += name //at the end of all execution, when the Create verb has ended and the player is created properly,\
we make sure the name can't be used in the future


//the following makes sure the list of names is saved over reboots, assuming this was your intent
world
New()
.=..()
if(fexists("names.sav"))
var/savefile/F = new("names.sav")
F >> names
Del()
var/savefile/F = new("names.sav")
F << names
return ..()


-- Data
In response to Android Data
That didn't work, but I know what you are saying. Convert each letter over to ascii, then check each ones numerical value to see if it is allowed, and do that for each letter.
In response to Android Data
just trying but...

mob/verb/change_name(t as name)
usr.name == t
In response to Eternity Productions
Eternity Productions wrote:
just trying but...

> mob/verb/change_name(t as name)
> usr.name == t


Read about what the " == " operator does and then replace it with " = "