Posts: 105
Threads: 10
Joined: Jul 2014
Reputation:
0
Hi,
I am trying to create a phone system. I was looking for a way to create phone numbers that is assigned to each player when they do /buyphone, however i failed to understand that 2 people cannot have the same number. I need help on creating numbers that have not already been used. I am using the random function right now with mysql. Help will be really appreciated.
Posts: 584
Threads: 51
Joined: Jan 2014
Reputation:
0
Just make the phone number a unique key and it can't be duped
Posts: 105
Threads: 10
Joined: Jul 2014
Reputation:
0
Mind elaborating a little more?
Posts: 10,066
Threads: 38
Joined: Sep 2007
Reputation:
0
You could use UUID_SHORT() which is guaranteed to be unique, but probably too long for your purpose. You could also use the Unix timestamp, which is 10 characters long and relatively unique; two players being assigned a number in the same second seems unlikely.
Posts: 801
Threads: 29
Joined: May 2012
Reputation:
0
If you're using MYSQL right now, I suppose you have the saving system done, now that you've finished that, you need to loop through all the created numbers from the database(loaded) and then check that the random number generated isn't equal to any of the already settled numbers in the database.
Posts: 105
Threads: 10
Joined: Jul 2014
Reputation:
0
Well i do have the saving system done. So pheonix what you technically mean is that after the player has done /buyphone it loops through the database and looks if the number has already been assigned?
@Vince
Ive never really used Unix timestamps, mind showing me an example?
Posts: 344
Threads: 12
Joined: Sep 2010
Reputation:
0
@Unix timestamps:
new seconds = gettime();
That's it.
Posts: 105
Threads: 10
Joined: Jul 2014
Reputation:
0
Got confused a little bit, i was asking for an example regarding my problem