ID:169525
 
Well, I took on the task of working on a game someone had given up on, and I began to find out why the person gave up on it. It's made using Deadrons Character Handling, and although it saves/loads characters just fine, there's nothing to stop players from making a character with the same name as somebody elses character. I need a way to fix that.

I tried myself to figure out how to make a code which would create a list, write new chars into it when they're made, and then read that file for existing chars when new ones are being created, but my effort was in vain. Yet it sounded so easy to me. Heh. Anyway, I thought about scrapping the game, but I've already done a decent amount of work, and would really like to see it go further. I'm still kinda new to the DM language, so please go easy on me. I sure hope someone can help though.

Oh, and if creating a list isn't the best way to go about it, could someone inform me of the proper way? A list just seemed like the best idea at the time.
Detnom wrote:
Well, I took on the task of working on a game someone had given up on, and I began to find out why the person gave up on it. It's made using Deadrons Character Handling, and although it saves/loads characters just fine, there's nothing to stop players from making a character with the same name as somebody elses character. I need a way to fix that.

I tried myself to figure out how to make a code which would create a list, write new chars into it when they're made, and then read that file for existing chars when new ones are being created, but my effort was in vain. Yet it sounded so easy to me. Heh. Anyway, I thought about scrapping the game, but I've already done a decent amount of work, and would really like to see it go further. I'm still kinda new to the DM language, so please go easy on me. I sure hope someone can help though.

Oh, and if creating a list isn't the best way to go about it, could someone inform me of the proper way? A list just seemed like the best idea at the time.

Hmmm I dont see why some person couldn't have the same name as another. Happens enough times in the real world.

To it with list you would need to store it into a seprate savefile. Lets call it pcnames.sav. Now lets take it in sections. The first section to do is the adding the name to the savefile. So when someone creates a new character lets add there name. listofnames.Add(usr.name) should do the trick. Now we save are listofnames to are savefile.

var/savefile/F = new/savefile("pcnames.sav")
F << listofnames


Now for the second section loading the list. At the main login start just load the list to the listofnames.

var/savefile/F = new/savefile("pcnames.sav")
var/list/listofnames = new/list()
F >> listofnames


Then at the create a character part. Just compair the name they entered with the names in the list.

for(var/n in listofnames)
if(n==usr.name)
// Go back too your character start.


Last but not least. When you delete a character you want that name out of the list. You will use the same code above except. You would add a listofnames.Remove(n). So the name in the list is removed. Then you would save the listofnames too the savefile again.

Hope all that info helps.
In response to Green Lime
Thank you for the reply.

One of the reasons I'm worried about people making the same name as someone else is, for instance, someone making a character with the same name as my core GM character. Or any of my other GM's for that matter, y'know? I think it would be more trouble to go around and put blocks in the code to stop people from making only the names me and my gms have, I'd be forced to add names as my team grows. I figure it would just be easier to compile all the characters into a list as they're made, and stop people from making the characters that are already made.

Now, in my StartUp.dm file, the characters name is defined by ckey_name instead of usr.name, so I replaced that accordingly. So here's now some of that code put in mine.. Although it doesn't appear to be working this way. What could be wrong?
            var/savefile/F = new/savefile("pcnames.sav")
var/list/listofnames = new/list()
F >> listofnames

for(var/n in listofnames)
if(n == ckey_name)
alert("There is already someone named that, try another.")
src.CreateCharacter()
return
else
listofnames.Add(ckey_name)
F << listofnames
Do I perhaps have to define the list, or something? I'm not getting any DM errors upon compiling, but it's not doing anything upon creation as far as stopping multiples still.