ID:171913
 
I want to have it so that when people select a name, the game checks from a list (world list maybe?) to see if the name has been taken and if it has then tell the person that and have them reselect a name and if they get one add it to the list. i tried some different codes but they ended up not working.. any help?
Have you tried looping through the mobs in the world?

// In mob/Login()

InputName:
var/newName = input(src,"Choose a unique name.","Choose Name",key)as text
for(var/mob/M) if(M != src && M.name == newName) goto InputName
name = newName


Edit: I forgot to mention soemthing that you may be doing wrong.

You may be directly setting src.name, and then picking up the new mob in the loop. That way, it will always say there is a mob with that name.
In response to Yota
thank you but.. that doesnt cover the offline players.
Siefer wrote:
I want to have it so that when people select a name, the game checks from a list (world list maybe?) to see if the name has been taken and if it has then tell the person that and have them reselect a name and if they get one add it to the list. i tried some different codes but they ended up not working.. any help?

Just make a simple list.

var/list/playernames = list()
mob/Login()
while(!cname&&!playernames.Find(cname)))
cname = input("Pick a name","Name") as text
src.name = cname


If your game uses saving, just remove the playername when you delete your character.

~~> Dragon Lord
In response to Siefer
Siefer wrote:
thank you but.. that doesnt cover the offline players.

OK, try this then. It will skip all mobs that have a key, and no client. Thoes are most likley to be mobs that used to have players. So you can name yourself after an offline player, but not an NPC. The problem however, is if an offliner comes back on, they, and the new guy can have the same name.

InputName:
var/newName = input(src,"Choose a unique name.","Choose Name",key)as text
for(var/mob/M) if(M != src && (M.key && !M.client) && M.name == newName) goto InputName
name = newName


This below will do the same as the above, but will allow you to name yourself after the NPCs too.
InputName:
var/newName = input(src,"Choose a unique name.","Choose Name",key)as text
for(var/mob/M) if(M != src && !M.client && M.name == newName) goto InputName
name = newName