Auto Increament (Player ID) -
JonathanW - 18.11.2014
Hey. Well, I'm scripting a Character System, in 'Yini'. I know, MySQL does that stuff better, but I'll give it a try. Okay well, the way I'm gonna let it work is... Make an enumerator for the Master Account(in a folder), and use an ID to link it with the characters, present in 'Accounts' folder.
Well, I can't figure out, first of all, how to get the ID to increase automatically, on every Registeration. Like, it assigns ID 0, to the first person who registered, ID 1 to the second and so on...
Please help.
Sincerely,
JonathanW
Re: Auto Increament (Player ID) -
Dairyll - 18.11.2014
Do you already have a registration system? If so, can you post a sample of it?
Re: Auto Increament (Player ID) -
JonathanW - 18.11.2014
Well, here it is.
pawn Код:
// Master Account Information
enum pInfo
{
pID,
Password,
Admin,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
// Character Information
enum cInfo
{
mID,
}
new Character[MAX_CHARACTERS][cInfo];
// Under OnDialogResponse
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);
}
}
I'm wondering, how to Link the Master Account with the Character. In MySQL, you simple can do:
mysql_function_query(connectionHandle, "SELECT `username` FROM `playerCharacters` WHERE `masteraccountID` = 1291", true, "loadAccounts", "d", playerid);
Re: Auto Increament (Player ID) -
Dairyll - 18.11.2014
My suggestion is make a server-wide account counter. Then just increase it by one every successful registration.
Create the variable
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.
Re: Auto Increament (Player ID) -
JonathanW - 18.11.2014
I see your logic. Now, my second confusion...is, How to 'Link' the M.Account to the Character in the characters.
OT: Rep for ya, Dairyll.
Re: Auto Increament (Player ID) -
Dairyll - 18.11.2014
Link the mID to pID? Sorry, I just woke up so my brain's not functioning very well right now, haha.
Re: Auto Increament (Player ID) -
JonathanW - 18.11.2014
Quote:
Originally Posted by Dairyll
Link the mID to pID? Sorry, I just woke up so my brain's not functioning very well right now, haha.
|
I understand XD.
Anyone else?