SA-MP Forums Archive
samp / mysql - 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: samp / mysql (/showthread.php?tid=652550)



samp / mysql phonenumber - Zeus666 - 14.04.2018

How can I generate a random 6 digits number without digit 0 as the first digit as a phone number?

ex: 244132, 131131, 121412

I want them to be saved in MYSQL when someone types /buyphone (i can do this)

help me just with the generator number, the rest of script I can do it alone, I don't know how to do it via pawn

And I don't know how to check it in MYSQL if already exists that number, to give another random number.


Re: samp / mysql - TitoRayne - 14.04.2018

this may help
Код:
 mysql_format(connectionID, queryBuffer, sizeof(queryBuffer), "UPDATE users SET phone = %i WHERE uid = %i", PlayerInfo[playerid][pPhone], PlayerInfo[playerid][pID]);
mysql_tquery(connectionID, queryBuffer);



Re: samp / mysql - JesterlJoker - 14.04.2018

PHP код:
createphone(){
       new 
number[6];
       for(new 
i=0j=6i<ji++){
              
random(9+1); // this will give you a number from 1 to 9 it can be used like this
              
number[i] = random(9+1); // This might work or might not, haven't tested it yet
       
}
       return 
number;

It's a theory, don't know if it works

do what TitoRayne showed and it will save on MySQL


Re: samp / mysql - TitoRayne - 14.04.2018

Are you cool now bruv?


Re: samp / mysql - Zeus666 - 21.04.2018

No, I don't know how to do the stock (question edited)


Re: samp / mysql - Phreak - 21.04.2018

Код:
new phonenumber[6];
phonenumber[0] = rand(8)+1; // sets the first number from 1 to 9
for(new i=i; i<sizeof(phonenumber);i++)
{
    phonenumber[i]=rand(9); // sets the rest of the numbers from 0 to 9
}
And I'm not sure about the mysql part as I'm not that good with mysql myself but you can try:
PHP код:
new query[256]
// select all the phone numbers that match the phone number you want
mysql_format(yourDatabasequerysizeof query"SELECT * FROM `yourTable` WHERE `phonenumber` = '%i' LIMIT1"thePhoneNumberYouGotFromTheCommand )
mysql_query(yourDatabasequerycallbackFunctionparameterTypeparameter );
forward yourCallbackFunction(parameter);
public 
yourCallbackFunction(parameter)
{
   if(
cache_num_rows() > 0// if the phone number is found in the database
   
{
       
// do something
   
}

And of course you have to replace the name of yourDatabase, yourTable, phonenumber and everything else to match yours.


Re: samp / mysql - Zeus666 - 21.04.2018

Hi, I did this way

PHP код:
CMD:number(playeridparams[])
{
    if(
pInfo[playerid][Telefon] == 0)
    {
        new 
string[220], number randomEx(1000,99999999);
        
pInfo[playerid][Telefon] = number;
        
format(stringsizeof(string), "Your phonenumber is: %i",pInfo[playerid][Telefon]);
        
SendClientMessage(playerid,-1,string);
        
SaveStats(playerid);
    }
    else {
        
SendClientMessage(playerid,-1,""chat" You already have an phone number !");
    }
    return 
1;

Thanks anyway


Re: samp / mysql - Dayrion - 21.04.2018

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
Hi, I did this way

PHP код:
CMD:number(playeridparams[])
{
    if(
pInfo[playerid][Telefon] == 0)
    {
        new 
string[220], number randomEx(1000,99999999);
        
pInfo[playerid][Telefon] = number;
        
format(stringsizeof(string), "Your phonenumber is: %i",pInfo[playerid][Telefon]);
        
SendClientMessage(playerid,-1,string);
        
SaveStats(playerid);
    }
    else {
        
SendClientMessage(playerid,-1,""chat" You already have an phone number !");
    }
    return 
1;

Thanks anyway
You should do : "randomEx(111111,999999);" It will give you a random number without a zero and in range of 6 digits.


Re: samp / mysql - Zeus666 - 21.04.2018

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
You should do : "randomEx(111111,999999);" It will give you a random number without a zero and in range of 6 digits.
Well, changed my mind a little bit there. :d