stock crashing my server
#1

This is my stock:

pawn Код:
stock GiveCellNumber(playerid)
{
    new number;
    new string[128];
    new Infinity = 0;
    if(IsPlayerConnectedAndLoggedIn(playerid))
    {
        while(Infinity != 1)
        {
            number = random(899999) + 100000;
            format(string, sizeof(string), "XRPG/Numbers/%s.ini",number);
            if(!fexist(string)) // Check's if it's taken.
            {
                new File:hFile;
                hFile = fopen(string, io_append);
                fwrite(hFile, PlayerName[playerid]);
                PlayerInfo[playerid][pMyNumber] = number;
                fclose(hFile);
                return 1; // Stops the loop. (i think :X).
            }
        }
    }
    return 1;
}
It's supose to give you an unique cell phone number, but when ever i use it, my server crashes. (it turnes off).

Please help, thank you.
Reply
#2

pawn Код:
stock GiveCellNumber(playerid)
{
    new
        number,
        File:hFile,
        string[128];
    if (IsPlayerConnectedAndLoggedIn(playerid))
    {
        while (true)
        {
            number = random(899999) + 100000;
            format(string, sizeof(string), "XRPG/Numbers/%s.ini", number);
            if (!fexist(string))
            {
                hFile = fopen(string, io_readwrite);
                PlayerInfo[playerid][pMyNumber] = number;
                fwrite(hFile, PlayerName[playerid]);
                fclose(hFile);
                break;
            }
        }
    }
    return 1;
}
You were trying to append a string to a nonexistent file.
Reply
#3

Uhm, it's not working.

First i get this warning on the line with while (true):

warning 206: redundant test: constant expression is non-zero

And second, the filename isn't the number it's some strange letter instead.

Please help, thanks.
Reply
#4

pawn Код:
stock GiveCellNumber(playerid)
{
    new
        foundnumber,
        number,
        File:hFile,
        string[128];
    if (IsPlayerConnectedAndLoggedIn(playerid))
    {
        while (!foundnumber)
        {
            number = random(899999) + 100000;
            format(string, sizeof(string), "XRPG/Numbers/%s.ini", number);
            if (!fexist(string))
            {
                foundnumber = 1;
                hFile = fopen(string, io_readwrite);
                PlayerInfo[playerid][pMyNumber] = number;
                fwrite(hFile, PlayerName[playerid]);
                fclose(hFile);
            }
        }
    }
    return 1;
}
Reply
#5

I was formatting the string incorrectly.

pawn Код:
stock GiveCellNumber(playerid)
{
    new
        number,
        File:hFile,
        string[128];
    if (IsPlayerConnectedAndLoggedIn(playerid))
    {
        for ( ; ; )
        {
            number = random(899999) + 100000;
            format(string, sizeof(string), "XRPG/Numbers/%i.ini", number);
            if (!fexist(string))
            {
                hFile = fopen(string, io_readwrite);
                PlayerInfo[playerid][pMyNumber] = number;
                fwrite(hFile, PlayerName[playerid]);
                fclose(hFile);
                break;
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)