For an accounts system, I suggest you use dini for your scriptfiles.
Creating a PlayerInfo array.
pawn Код:
enum pInfo
{
logged,
admin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
You should look up about enums if you don't understand.
_________________________________________________
[size=15px]For the regster command:[/size]
pawn Код:
if(strcmp("/register", cmdtext, true, 9) == 0)
{
new pname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "accounts/%s.acc", pname); //format "string" as where you save the account too
//this isn't nessessary but it makes life easyer.
Check if they're already logged:
pawn Код:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");
dini_Exists tells you weather or not their account (file with their name) already exists.
pawn Код:
if(dini_Exists(string) == 1) return SendClientMessage(playerid, red, "Your account is registered, please /login"); // account already exists
if(strlen(cmdtext[10]) == 0) return SendClientMessage(playerid, red, "Usage: /register [password]");
if(strlen(cmdtext[12]) == 0) return SendClientMessage(playerid, red, "Your password is not long enough"); // their pass must be more then 2 chars
dini_Create creates their account (a file). dini_Set sets a String into their account (file). dini_IntSet sets an Integer into their account (file).
pawn Код:
dini_Create(string); // create their account
dini_Set(string, "password", cmdtext[10]); // put their pass in it
dini_IntSet(string, "admin", 0); // create an admin level variable
And finally tell them to login.
pawn Код:
format(string, sizeof(string), "Welcome %s, you may now /login", pname);
SendClientMessage(playerid, yellow, string);
return 1;
}
_________________________________________________
[size=15px]For the login command:[/size]
pawn Код:
if(strcmp("/login", cmdtext, true, 6) == 0)
{
new pname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "accounts//%s.acc", pname);
Check if they're already logged:
pawn Код:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");
dini_Get gets a string from a file.
pawn Код:
if(dini_Exists(string) == 0) return SendClientMessage(playerid, red, "You do not have an account, please /register"); // their account (file with their name) does not exist
if(strlen(cmdtext[7]) == 0) return SendClientMessage(playerid, red, "Usage: /login [password]");
if(strcmp(dini_Get(string, "password"), cmdtext[7], true) != 0) return SendClientMessage(playerid, red, "Passwords did not match"); // pass they entered and pass in the file
Set them to logged:
pawn Код:
PlayerInfo[playerid][logged] = 1;
dini_Int gets an integer from a file. Set their admin level:
pawn Код:
PlayerInfo[playerid][admin] = dini_Int(string, "admin");
And finish the command:
_________________________________________________
[size=15px]Simple /kick command:[/size]
pawn Код:
if(strcmp("/kick", cmdtext, true, 5) == 0)
{
new pname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "accounts//%s.acc", pname);
Check their level is correct:
pawn Код:
if(dini_Int(string, "admin") != 1) return SendClientMessage(playerid, red, "You are not a level 1 admin!"); // they where not level 1
// include more checks to see if they're connected and all that
Kick(strval(cmdtext[5])); // kick them
//tell everyone they're kicked
return 1;
}
_________________________________________________
[size=15px]FYI:[/size]
Gets the value of a string.
pawn Код:
new string[128];
0123456789
string = "hello 11aa".
string[6] (6 = char in which to start) would be "11aa". The value of it would be 11.
Make sure to set their admin level to 0 when they login!