ID:162458
 
I am trying to make a verb where you can change a players name (if not appropriate seeing as how a filter couldn't get all the bad bad stuff) but I don't know how exactly to do it with copytext. Could anyone point me in the direction of a demo or a library to show how to check for illegal characters or oversized names? Thanks
do you mean, you want to change a guys name automatically, and make sure his name isnt 100 characters long?
In response to Superbike32
No no no

I mean like, if I myself think someones name is offensive, I change it for them to something appropriate. But I'm not gonna be the only one with this verb so I want to make sure people don't change it to something 2000 characters long.
In response to Godzooks
then whats with the copytext part?
In response to Superbike32
well, heres the code to change it, will less than a length of 15 characters long.

mob
verb
Change_Name(var/mob/M in world, Name as text)
if(length(Name) <= 15)
Name = M.name
else
usr << "Please choose a shorter name."


just change the 15 in the following line, and as of right now they can have 0-15 letters/numbers/characters in length long in their name

but if u changed this to 30, they can 0-30 letters/numbers/characters in length long in their name

its this line ull need to change.

if(length(Name) <= 15)


now, if you want it so it has to be at least 1 character in length in their name, and less than 15 or w/e, heres the code.

mob
verb
Change_Name(var/mob/M in world, Name as text)
if(length(Name) >= 1)
..()
else
usr << "Please choose a longer name."
return
if(length(Name) <= 15)
M.name = Name
usr << "Your name has been changed to [M.name]."
else
usr << "Please choose a shorter name."
return


and if you want to change the least amount it has to be, change this line of code.

if(length(Name) >= 1)

and now, if you want me to post how to make it so nobody online can have the same code if its changed, i will show u that one soon, if u ask.
In response to Superbike32
If you could please, that would be nice :D

But the copytext is for like, removing illegal characters.

So someone cant have any of these in their name:

< , . / ? - _ + + etc...
In response to Godzooks
OK, well, i will make a list of things not able to be used, and if they are found, not allow it to be entered in.

give me a minute plz, thanks.
In response to Superbike32
Well you could either do that, or you could show me the format and I could enter all the characters I dont want in in?

OH YEAH, and one more thing, sorry I didn't mention this earlier, do you know how to take the first letter from the beginning of the name and capitalize it so that 'the' doesn't show up before it
In response to Godzooks
well, right now im not gonna do the thing with illegal characters as nobody has a foolproof system right now, and im working on a good way to capitalize the first letter, as right now, nobody has one that always does it correctly.
This seems to be all i could get that worked 100% correctly.

mob
verb
Change_Name(var/mob/M in world, Name as text)
if(length(Name) >= 1)
..()
else
usr << "Please choose a longer name."
return
if(length(Name) <= 15)
..()
else
usr << "Please choose a shorter name."
return
M.name = Name
usr << "Your name has been changed to [M.name]."
In response to Superbike32
GodZooks, i can now check characters and capitalization of things.

I just need to know a few things.

About capitalization of letters, you can make it so it doesnt accept the name till they capitalize the first letter, because of the fact that sometimes they will want to change their name if it is going to have to be capitalized, or that it is automatically capitalized for them.

Another thing, is that, do you want all other letters to then be un-capitalized, if so, will it do it automatically, as some people will want other capitals in their name, even if its not in a whole other word.

My code is so good, that it will be able to detect new words, would you want both words to start capitalized, and every other letter thats not the first Uncapitalized?

Do you want to limit how many words long your name can be, besides just how many letters long your name cant be?

and etc....
In response to Superbike32
this text will format it in a way that each word, whether it be one letter long or not, starts with a cpital, and the rest have no capital letters, i will add it with the other in a minute, but heres the code in case you want to implement it yourself.

mob
verb/Format_Text(T as text)
if(!T)
return
var
start = 1
end = length(T)
Formatted = ""
Previous = ""
while(start<=end)
var/letter = copytext(T,start,start+1)
if(letter == " ")
if(Formatted == "")
goto Skip
usr << "#[start] - [letter] - [uppertext(letter)==letter?"Capitalized":"Not capitalized"]"
if(Formatted == "")
Formatted += uppertext(letter)
Previous = letter
else
if(Previous == " ")
if(letter == " ")
goto Skip
Formatted += uppertext(letter)
else
Formatted += lowertext(letter)
Previous = letter
Skip
start++
usr << "Formatted = [Formatted]"
In response to Superbike32
..() is in no way appropriate for what you have there. Get rid of it.
mob/verb/Change_Name(mob/M, t as text)
src << M.rename(t)

#define MIN_LENGTH 2
#define MAX_LENGTH 20
var/list/illegal_strings=list("+",">","spit")

mob/proc/rename(new_name)
if(length(new_name) < MIN_LENGTH) return "Name too short."
if(length(new_name) > MAX_LENGTH) return "Name too long."
for(var/string in illegal_strings)
if(findtext(char,new_name)) return "[string] not allowed."
name=uppertext(copytext(new_name,1,2))+copytext(new_name,2)
return "Name changed to [name]."


copytext() could also be used just to cut the name off at the max. To see it happen just add a third argument to my last call to copytext(), make it four and names will be limited to three characters. =)
In response to Superbike32
That's nasty, ugly spaghetti-code and doesn't even do what he wants. If you want to filter out any unwanted characters from a text string, the process is simple:

//text is the text to filter
//prohibited is a string
proc/filtertext(var/text, var/prohibited)
var/len = length(text)
//go through the text string
for(var/v = 1, v <= len, v++)
//fetch each letter
var/char = copytext(text, v, v+1)
//check that letter against the prohibited letters
if(!findtext(prohibited, char))
//if it passes, add it to the return value
. += char
In response to Garthor
Jw, instead of making an 'illegal characters' list, wouldn't it be alot easier to make a legal characters list? For example, the legal characters list would contain a-z, A-Z, 0-9. Wouldn't that work out alot better?
In response to Garthor
Garthor im a newbie coder and i want to be good as you so could you please explain the code strings you just wrote please i think that this is a great chance for me to learn real coding please if its not to much to ask just explain your codes
In response to Biond_coder
There are six lines of code there. I explained pretty much all of them. What else do I need to explain that you can't figure out by just opening the reference?