Check if phone number exist - 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: Check if phone number exist (
/showthread.php?tid=633525)
Check if phone number exist -
iDark - 02.05.2017
Hello,
Is this idea good to check if a phone number exist already?
Код:
new randphone = 0, number = 0, ok = 0, query[64];
format(query, sizeof(query), "SELECT Phone FROM players WHERE Phone > 0");
new Cache: numbers = mysql_query(SQL, query);
do
{
ok = 1;
randphone = 10000 + random(89999);
if(cache_get_row_count() > 0)
{
for(new i, j = cache_get_row_count(); i != j; i++)
{
number = cache_get_field_content_int(i, "Phone");
if(number == randphone)
{
ok = 0;
}
}
}
}
while(ok == 0);
cache_delete(numbers);
I don't want to check database everytime, so I made it with cache. I don't know if this code is good... And I want to ask if there is a function better than this one... I don't know if is a good idea to make a loop in another one and I don't want to make an infinite loop than can result in a server freeze.
Re: Check if phone number exist -
Toroi - 02.05.2017
Why don't you let the players choose their phone number? It'd be a lot easier to check if it already exists or not and they'll remember it as they were the ones who picked it.
Just sayin'
Re: Check if phone number exist -
Vince - 02.05.2017
Does it
need to be completely random, though? Because you could just use the player's unique SQL id in the number. Like the first two digits are random(100) and the last four digits are the player's unique id, padded with zeros if it's less than 1000 (%04d). This method may make it slightly obvious what's going one because the first players will have xx0001, xx0002, xx0003, etc. But it should appear more random once registered player count reaches above 100.
Re: Check if phone number exist -
iDark - 03.05.2017
Quote:
Originally Posted by Troydere
Why don't you let the players choose their phone number? It'd be a lot easier to check if it already exists or not and they'll remember it as they were the ones who picked it.
Just sayin'
|
It's more realistic to give them random phone numbers.
Quote:
Originally Posted by Vince
Does it need to be completely random, though? Because you could just use the player's unique SQL id in the number. Like the first two digits are random(100) and the last four digits are the player's unique id, padded with zeros if it's less than 1000 (%04d). This method may make it slightly obvious what's going one because the first players will have xx0001, xx0002, xx0003, etc. But it should appear more random once registered player count reaches above 100.
|
Yeah, I want it random. I have already 10k players registered so I think this will not work fine...