Phone Numbers
#1

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.
Reply
#2

Just make the phone number a unique key and it can't be duped
Reply
#3

Mind elaborating a little more?
Reply
#4

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.
Reply
#5

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.
Reply
#6

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?
Reply
#7

@Unix timestamps:

new seconds = gettime();
That's it.
Reply
#8

Got confused a little bit, i was asking for an example regarding my problem
Reply
#9

Код:
new phonenumber = gettime() + random(1000);
I think that's "random" enough? That will give you (semi)unique phone number.
Reply
#10

Quote:
Originally Posted by MicroD
Посмотреть сообщение
Код:
new phonenumber = gettime() + random(1000);
I think that's "random" enough? That will give you (semi)unique phone number.
That's atually a pretty nice idea.

Use MicroD idea, it's a very nice one.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)