Unique Cell phone number help -
Jakwob - 25.05.2015
Can someone help me? I wanted to make a cell phone system but I don't know how to give a players a unique cell phone number like 079-6336-2793 the 079 part needs to always be the same? If some one could help I will rep the ones who help. Thanks in advance.
Re: Unique Cell phone number help -
dominik523 - 25.05.2015
Use random() to get a some number and give it to the player. Save the number into a file or a database. The next time when someone gets a random value for their phone number, go through the database/file and check if the number exists. If it does, generate a new number.
Re: Unique Cell phone number help -
Vince - 25.05.2015
Saving system? If you use MySQL, create a new table to link a phone number to a player and set the number to be the primary key and auto increment. That way it's guaranteed to be unique.
You could also append the current Unix timestamp (returned by gettime()), although that may make the number too long. It also won't be unique if two or more players are assigned a number at the same second.
A third way, that also relies on SQL's auto increment, is to append the players' unique identifier, along with some random numbers.
Re: Unique Cell phone number help -
dominik523 - 25.05.2015
Quote:
Originally Posted by Vince
Saving system? If you use MySQL, create a new table to link a phone number to a player and set the number to be the primary key and auto increment. That way it's guaranteed to be unique.
You could also append the current Unix timestamp (returned by gettime()), although that may make the number too long. It also won't be unique if two or more players are assigned a number at the same second.
|
Yeah, I didn't think of just saving the number with player's stats. That's even better idea.
With auto increment, it will start from 1 (or maybe 0) right? That seems like a too short number IMO. I would still try with random and see how it turns out.
Re: Unique Cell phone number help -
Jakwob - 25.05.2015
I'm using y_ini as I struggle with sql I have try many of times but prefer ini
Re: Unique Cell phone number help -
Jakwob - 25.05.2015
Could I do it the same way you would when giving a player a level but start at a high number and automatically give them the number upon account creation and only allow them to use it once they have a cell phone
Sorry for the double post.
Re: Unique Cell phone number help -
Crayder - 25.05.2015
Start with a 'key' number, save it as the key in a file. Then when someone wants a number, load the key add a random number between 1 or 10. save the new number as their number and the new key.
PS. This has been my method for a while.