Auto Increament (Player ID)
#4

My suggestion is make a server-wide account counter. Then just increase it by one every successful registration.

Create the variable
pawn Код:
new
    PlayerAccounts;
Now load that variable every time you initiate the server. I'm not familiar with yini, but in dini, it went something like this:
pawn Код:
stock LoadAccountCounter()
{
    #define ACC_CTR_FILE "accounts.cfg"
    if(!fexist(ACC_CTR_FILE)) return 1;
    new
        File: i_FileHandle = fopen("accounts.cfg", io_read), sz_FileStr[16];
    fread(i_FileHandle, sz_FileStr);
    sscanf(sz_FileStr, "p<,>i", PlayerAccounts); // You can add multiple variables to this, see below
    return fclose(i_FileHandle);
}
Save the variable whenever you feel like it:
pawn Код:
stock SaveAccountCounter()
{
    new
        sz_FileStr[16], File: i_FileHandle = fopen(ACC_CTR_FILE, io_write);
    format(sz_FileStr, sizeof(sz_FileStr), "%d", PlayerAccounts);  // Add multiple variables separated with a comma
    fwrite(i_FileHandle, sz_FileStr);
    #undef ACC_CTR_FILE
    return fclose(i_FileHandle);
}
Now to increase the counter's variable by one every time a user successfully registers:
pawn Код:
case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register","You haven't entered anything. Please enter a password to Proceed.","Register","Quit");
                PlayerInfo[playerid][Password] = udb_hash(inputtext);
                SavePlayer(playerid);
                PlayerAccounts++; // ++ increases the counter
               
            }
        }
It's been awhile since I've touched non-MySQL systems so it might not be the best format. It should work though.
Reply


Messages In This Thread
Auto Increament (Player ID) - by JonathanW - 18.11.2014, 06:48
Re: Auto Increament (Player ID) - by Dairyll - 18.11.2014, 06:57
Re: Auto Increament (Player ID) - by JonathanW - 18.11.2014, 07:07
Re: Auto Increament (Player ID) - by Dairyll - 18.11.2014, 08:08
Re: Auto Increament (Player ID) - by JonathanW - 18.11.2014, 09:01
Re: Auto Increament (Player ID) - by Dairyll - 18.11.2014, 14:42
Re: Auto Increament (Player ID) - by JonathanW - 18.11.2014, 14:47

Forum Jump:


Users browsing this thread: 2 Guest(s)