19.10.2013, 08:07
Just use recursion
It will keep calling itself until you have a car number that's unique.
pawn Код:
stock RandomCarNumbers()
{
new string[64], query[128];
format(string,sizeof(string),"{000000}%c%c%c-%i%i%i",(65+random(26)),(65+random(26)),(65+random(26)),1+random(9),random(10),random(10));
MySQLCheck();
format(query, sizeof(query), "SELECT * FROM 'cars' WHERE numeriai = %s", string);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() > 0)
return
RandomCarNumbers();
else
{
mysql_free_result();
return string;
}
}