SA-MP Forums Archive
Phone Numbers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Phone Numbers (/showthread.php?tid=531930)



Phone Numbers - MikeEd - 15.08.2014

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.


Re: Phone Numbers - sammp - 15.08.2014

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


Re: Phone Numbers - MikeEd - 15.08.2014

Mind elaborating a little more?


Re: Phone Numbers - Vince - 15.08.2014

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.


Re: Phone Numbers - ThePhenix - 15.08.2014

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.


Re: Phone Numbers - MikeEd - 15.08.2014

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?


Re: Phone Numbers - MicroD - 15.08.2014

@Unix timestamps:

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


Re: Phone Numbers - MikeEd - 15.08.2014

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


Re: Phone Numbers - MicroD - 15.08.2014

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


Re: Phone Numbers - ThePhenix - 15.08.2014

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.