SA-MP Forums Archive
MySQL admin system. Need Help! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL admin system. Need Help! (/showthread.php?tid=357165)



MySQL admin system. Need Help! - FOTIS6 - 06.07.2012

I have created a mysql register/login Script.
I also use it for Admins. But I have problems with admins commands.

Код:
new Text3D:adminonduty;
COMMAND:onduty(playerid, params[])
{
	mysql_query("SELECT name FROM playerdata WHERE level > 2");
	mysql_store_result();
	if(mysql_affected_rows()>0)
	{
		new string[128];
		format(string, sizeof(string), "Administrator %s is now onduty!", PlayerName(playerid));
		SendClientMessage(playerid, red, string);
		adminonduty = Create3DTextLabel("Administrator", lightgreen, 30.0, 40.0, 50.0, 40.0, 0);
		Attach3DTextLabelToPlayer(adminonduty, playerid, 0.0, 0.0, 0.7);
		SetPlayerHealth(playerid, 999999);

	}
	else return SendClientMessage(playerid, red, "Error: You must be Administrator level 3 to use this command");
	mysql_free_result();
        return 1;
}
I want to use it for level 3. But all players can use it.
I hope you can help me.


Re: MySQL admin system. Need Help! - DBan - 06.07.2012

Why not make it easier for yourself?

Create an enum:
pawn Код:
enum playerdata
{
    adminlevel
}
new PlayerInfo[MAX_PLAYERS][playerdata];
Then set the level when the player connects (I created a stock in my script to do that)
pawn Код:
stock SetLevel(playerid)
{
    new query[200], level;
    format(query, sizeof(query), "SELECT adminlevel FROM `playerdata` WHERE user ='%s'", GetName(playerid));
    mysql_query(query);
    mysql_store_result();
    level = mysql_fetch_int(); // This gets the adminlevel and sets it into the variable
    mysql_free_result();
    PlayerInfo[playerid][adminlevel] = level; // Set adminlevel to the level that was stored inside the variable
    return 1;
}
pawn Код:
public OnPlayerConnect
{
    SetLevel(playerid);
    return 1;
}
Then whenever you check if the player is high enough level:
pawn Код:
if(PlayerInfo[playerid][adminlevel] > 2)
{
    // Add code here...
}



Re: MySQL admin system. Need Help! - FOTIS6 - 06.07.2012

Thanks for it but it didn't worked


Re: MySQL admin system. Need Help! - DBan - 06.07.2012

Quote:
Originally Posted by FOTIS6
Посмотреть сообщение
Thanks for it but it didn't worked
In what way did it not work? Are you getting errors, or?

EDIT:
Don't copy and paste. The MySQL query was from my script, you'll need to edit it as you will have different table names and columns.


Re: MySQL admin system. Need Help! - FOTIS6 - 06.07.2012

No errors. It didn't work in the server.
Chatlog: Error: You must be Administrator level 3 to use this command


Re: MySQL admin system. Need Help! - DBan - 06.07.2012

Edited my message ^^

You need to edit the mysql query according to your database.


Re: MySQL admin system. Need Help! - FOTIS6 - 06.07.2012

Код:
enum playerdata
{
    level
}
new PlayerInfo[MAX_PLAYERS][playerdata];

stock SetLevel(playerid)
{
    new query[200], level;
    format(query, sizeof(query), "SELECT level FROM playerdata WHERE user ='%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    level = mysql_fetch_int(); // This gets the adminlevel and sets it into the variable
    mysql_free_result();
    PlayerInfo[playerid][level] = level; // Set adminlevel to the level that was stored inside the variable
    return 1;
}
Didn't work
I edited it.


Re: MySQL admin system. Need Help! - DBan - 06.07.2012

Quote:
Originally Posted by FOTIS6
Посмотреть сообщение
Код:
enum playerdata
{
    level
}
new PlayerInfo[MAX_PLAYERS][playerdata];

stock SetLevel(playerid)
{
    new query[200], level;
    format(query, sizeof(query), "SELECT level FROM playerdata WHERE user ='%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    level = mysql_fetch_int(); // This gets the adminlevel and sets it into the variable
    mysql_free_result();
    PlayerInfo[playerid][level] = level; // Set adminlevel to the level that was stored inside the variable
    return 1;
}
Didn't work
I edited it.
Are you sure your account is set to the correct level? It works perfectly on my server.

pawn Код:
COMMAND:onduty(playerid, params[])
{
    if(PlayerInfo[playerid][adminlevel] > 2)
    {
        new string[128];
        format(string, sizeof(string), "Administrator %s is now onduty!", GetName(playerid));
        SendClientMessage(playerid, CRED, string);
        SetPlayerHealth(playerid, 999999);
    }
    else return SendClientMessage(playerid, CRED, "Error: You must be Administrator level 3 to use this command");
    return 1;
}
I removed the 3d text draws when I edited it, you can put it back in if you want.


Re: MySQL admin system. Need Help! - FOTIS6 - 06.07.2012

Yes. it is set to level 5


Re: MySQL admin system. Need Help! - DBan - 06.07.2012

Try the code I posted (edited my post)