Admin levels using mysql
#1

Hello guys , just a question
How can i create admin levels with mysql account system?
mysql system is up just wanna know how to make admin levels
Just give me the right functions and i'll try it on my own
Thanks.
Reply
#2

why so many ppl using MySQL IT SUCKS us something else...for me i never likes mysql...
Reply
#3

mysql sucks?
Mysql is faster and alot better...
and btw u think mysql sucks because you never gave yourself a chance to learn it.
anyways i appreciate you opinion .
Reply
#4

Which MySQL plugin are you using?
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=56564
R6 Ones
Reply
#6

Show me everything you have so far
Reply
#7

mine is based on this
https://sampforum.blast.hk/showthread.php?tid=159785
changed some things so it fits my game mode.
Reply
#8

pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20),admin INT(4), IP VARCHAR(16) )");
    //Fields:
Firstly there, the admin integer is added to the table if it don't exist.

Create a global variable (not inside any public function or stock):
pawn Код:
new PlayaAdmin[MAX_PLAYERS];
So now, in this:

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);
    //We only select the variables that we want to use.
    //We don't need things like the password string or the user string.
    mysql_query(query); //Queries the result
    mysql_store_result(); //Store a result because it's a SELECT statement.
    while(mysql_fetch_row_format(query,"|"))
    {
        //We use while so that it does a single query, not multiple
        //Especially when we have more variables. If there is more
        //Variables, you should just split the line with sscanf. To
        //Make it easier.
        mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
        mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
        //If you are wondering why I'm using savingstring instead
        //Of a variable like using MoneyGiven right away, it's because
        //mysql_fetch_field_row requires a string.
    }
    mysql_free_result(); //We must always free a stored result
    SendClientMessage(playerid, -1, "You have been logged in!"); //Sends the client a message.
    Logged[playerid] = 1; //Sets our logged in variable to one
    return 1;
}
pawn Код:
mysql_fetch_field_row(savingstring, "admin"); PlayaAdmin[playerid] = strval(savingstring);
Put this in underneath:
pawn Код:
MoneyGiven[playerid] = strval(savestring);
Now on any admin command, you can do this (here is an example):

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/kick", cmdtext, true, 10) == 0)
    {
        new otherplayer;
        if(PlayaAdmin[playerid] >= 1 || IsPlayerAdmin(playerid))
        {
            if(sscanf(cmdtext,"u",otherplayer)) return SendClientMessage(playerid,0xFFFFFF00,"Usage: /kick [ID]");
            Kick(otherplayer);
        }
        else SendClientMessage(playerid,0xFFFFFF00,"SERVER: Unknown command.");
        return 1;
    }
    return 0;
}
Reply
#9

It's actually easy.

pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16) )");
You need to add another row into that code, so it'll be like:

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) )");
Add up a variable on top of your script:

pawn Код:
new IsAdmin[MAX_PLAYERS];
Then you'll need to call and store admin row on login function of the script you've added:

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;
}
And it's ready! You can easily check if player's admin, on your admin commands with that code:

pawn Код:
if(IsAdmin[playerid] < 1) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You are not an admin, or your admin level is not enough!");
If you want to make command for higher admin level, you should change the number on if function:

pawn Код:
if(IsAdmin[playerid] < 1) // Change "1" number to the admin level you want
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.
Reply
#10

Quote:
Originally Posted by [A]ndrei
Посмотреть сообщение
why so many ppl using MySQL IT SUCKS us something else...for me i never likes mysql...
You sucks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)