SA-MP Forums Archive
Problem with phone system - 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: Problem with phone system (/showthread.php?tid=279833)



Problem with phone system - ViPGuy - 29.08.2011

Hey guys,
so i have this problem that it generates the number fine. but it doesent save it .. heres the code:

pawn Код:
forward NumberExists(numb);
public NumberExists(numb)
{
    new value;
    new string[256];
    CheckMySQL();
    format(string, sizeof(string), "SELECT * FROM numbers WHERE number = '%d'",numb);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows())value = 0;
    else value = 1;
    return value;
}
forward MakePNumber(playerid,p);
public MakePNumber(playerid,p)
{
    new number2 = Random(56000000,78000000);
    if(NumberExists(number2) == 1)
    {
        MakePNumber(playerid,p);
        print("Number already exists");
    }
    else if(NumberExists(number2) == 2)
    {
        new s[255];
        UserStats[playerid][number] = number2;
        UserStats[playerid][phone] = p;
        CheckMySQL();
        format(s, sizeof(s), "INSERT INTO numbers (number) VALUES ('%d')",number2);
        mysql_query(s);
        SavePlayer(playerid);
        print("New number!");
    }
    return 1;
}
Thx for help


Re: Problem with phone system - Pinguinn - 29.08.2011

You mean it doesn't save into table `numbers`?
Or you mean it doesn't save for the players?


Re: Problem with phone system - ViPGuy - 29.08.2011

both


Re: Problem with phone system - Pinguinn - 29.08.2011

The 2nd problem is because you are only saving a number
Try this
pawn Код:
new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof name);
    format(s, sizeof(s), "INSERT INTO numbers (username, number) VALUES ('%s', '%d')", name, number2);
    mysql_query(s);
For the first problem, do you connect to MySQL?


Re: Problem with phone system - ViPGuy - 29.08.2011

Yep, i have the connection other things save

but, the table numbers is meant like, when it creates a number it checkes from the numbers table that does the generated number already exists if not its gonna save it as players phone number and its gonna insert the number to the table if the number already exists in the database it generates another number


Re: Problem with phone system - Pinguinn - 29.08.2011

Do you get printed 'New number!'?


Re: Problem with phone system - ViPGuy - 29.08.2011

No .. thats the prob


Re: Problem with phone system - Pinguinn - 29.08.2011

Try this

pawn Код:
forward NumberExists(numb);
public NumberExists(numb)
{
    new value;
    new string[256];
    CheckMySQL();
    format(string, sizeof(string), "SELECT * FROM numbers WHERE number = '%d'",numb);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows() == 0)
    {
        value = 0;
    }
    else value = 1;
    return value;
}
forward MakePNumber(playerid,p);
public MakePNumber(playerid,p)
{
    new number2 = Random(56000000,78000000);
    if(NumberExists(number2) == 1)
    {
        MakePNumber(playerid,p);
        print("Number already exists");
    }
    else
    {
        new s[255];
        UserStats[playerid][number] = number2;
        UserStats[playerid][phone] = p;
        CheckMySQL();
        format(s, sizeof(s), "INSERT INTO numbers (number) VALUES ('%d')",number2);
        mysql_query(s);
        SavePlayer(playerid);
        print("New number!");
    }
    return 1;
}



Re: Problem with phone system - ViPGuy - 29.08.2011

Thx,

lol my mistake

i got it


Re: Problem with phone system - Pinguinn - 29.08.2011

No problem