29.06.2012, 11:23
It's actually easy.
You need to add another row into that code, so it'll be like:
Add up a variable on top of your script:
Then you'll need to call and store admin row on login function of the script you've added:
And it's ready! You can easily check if player's admin, on your admin commands with that code:
If you want to make command for higher admin level, you should change the number on if function:
And to edit admin levels of your players, you must get into your database and edit "admin" row on your "playerdata" table.
Hope it helped to you. PM me anything that you want to ask.
Edit: Whoah. Another guy just posted before me.
pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16) )");
pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16), admin VARCHAR(2) )");
pawn Код:
new IsAdmin[MAX_PLAYERS];
pawn Код:
stock MySQL_Login(playerid)
{
new query[300], pname[24], savingstring[20];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '%s'", pname);
mysql_query(query); //Queries the result
mysql_store_result(); //Store a result because it's a SELECT statement.
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
mysql_fetch_field_row(savingstring, "admin"); IsAdmin[playerid] = strval(savingstring);
}
mysql_free_result();
SendClientMessage(playerid, -1, "You have been logged in!");
Logged[playerid] = 1;
return 1;
}
pawn Код:
if(IsAdmin[playerid] < 1) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You are not an admin, or your admin level is not enough!");
pawn Код:
if(IsAdmin[playerid] < 1) // Change "1" number to the admin level you want
Hope it helped to you. PM me anything that you want to ask.
Edit: Whoah. Another guy just posted before me.