MySQL issues with /makeadmin command
#1

So I have this command, which is ment to set someone's admin level. ( offline or online ) However, it doesn't work. It keeps telling me "That account does not exist." when I try to give someone an admin level in game.. I think it has something to do with the fact that everything is targetid. But if I change it to target, it will tell me "error 035: argument type mismatch (argument 1)" Anyone can help me with the solution?

Код:
CMD:makeadmin(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 4)
	{
		SCM(playerid,COLOR_ERROR,"ERROR: You do not have the required access to execute this command.");
		SCM(playerid,COLOR_INFO,"INFO: You need admin level 4 or above to use this command.");
	}
	else
	{
		new target[24], targetid = GetPlayerID(target), value, str[128], query[128];
        if(sscanf(params, "s[24]i", target, value))
            return SCM(playerid, COLOR_INFO, "INFO: /admin [full name(case sensitive)] [0-4]");

		if(value < 0 || value > MAX_ADMIN_LEVEL)
			return SCM(playerid, COLOR_ERROR, "ERROR: You can only use a value between 0 and 4.");

        if( targetid == playerid )
		    return SCM(playerid, COLOR_ERROR, "ERROR: You can not use this command on yourself.");

        if(IsPlayerConnected(targetid))
        {
            PlayerInfo[targetid][pAdmin] = value;

            mysql_format(ourConnection, query, sizeof(query),"UPDATE `accounts` SET `admin` = %i WHERE `acc_name` = %e",PlayerInfo[targetid][pAdmin], PlayerInfo[targetid][pAccName]);
    		mysql_tquery(ourConnection, query);

            format(str,sizeof(str),"SERVER: You have set {FFFFFF}%s(%i){ADD8E6} their admin level to {FFFFFF}%i{ADD8E6}.",ReturnName(targetid), targetid, value);
            SCM(playerid, COLOR_LIGHTBLUE, str);

            format(str,sizeof(str),"SERVER: Your admin level was set to {FFFFFF}%i{ADD8E6} by {FFFFFF}%s(%i){ADD8E6}.",value, ReturnName(playerid), playerid);
            SCM(targetid, COLOR_LIGHTBLUE,str);
        }
        else
        {
        	new rows, fields;
        	mysql_format(ourConnection, query, sizeof(query), "SELECT * FROM accounts WHERE acc_name = '%e'",ReturnName(targetid));
			mysql_tquery(ourConnection, query);
			cache_get_data(rows, fields, ourConnection);

    		if(!rows)
    			return SendClientMessage(playerid, COLOR_ERROR, "ERROR: That account does not exist.");

    		PlayerInfo[targetid][pAdmin] = value;
            PlayerInfo[playerid][pAdminRankMsg] = true; // sends the player a message when they login informing them that their admin rank was adjusted.

           	mysql_format(ourConnection, query, sizeof(query),"UPDATE `accounts` SET `admin` = %i WHERE `acc_name` = %e",PlayerInfo[targetid][pAdmin], ReturnName(targetid));
    		mysql_tquery(ourConnection, query);

    		format(str, sizeof(str), "SERVER: You have set {FFFFFF}%s{ADD8E6} their admin level to {FFFFFF}%i{A7A7A7}.",target, value);
            SCM(playerid, COLOR_LIGHTBLUE, str);
        }
    }
    return 1;
}
Reply
#2

PHP код:
new target[24], targetid GetPlayerID(target
'target' does not yet have a value, so you're basically saying:
targetid = GetPlayerID("");

Also, using a player ID when the player is offline is useless.. what do you think targetid would be if the player was offline?
Reply
#3

Quote:
Originally Posted by Threshold
Посмотреть сообщение
PHP код:
new target[24], targetid GetPlayerID(target
'target' does not yet have a value, so you're basically saying:
targetid = GetPlayerID("");

Also, using a player ID when the player is offline is useless.. what do you think targetid would be if the player was offline?
if I don't use targetid, and instead target, I get these errors when compiling.

Код:
./inc/admin.inc(68) : error 033: array must be indexed (variable "target")
./inc/admin.inc(75) : error 033: array must be indexed (variable "target")
./inc/admin.inc(78) : error 033: array must be indexed (variable "target")
Here's the current code: ( I have marked the lines that report errors )

Код:
CMD:makeadmin(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 4)
	{
		SCM(playerid,COLOR_ERROR,"ERROR: You do not have the required access to execute this command.");
		SCM(playerid,COLOR_INFO,"INFO: You need admin level 4 or above to use this command.");
	}
	else
	{
		new target[24], value, str[128], query[128];
        if(sscanf(params, "s[24]i", target, value))
        {
    		format(str, sizeof(str), "INFO: /admin [full name(case sensitive)] [0-%i]",MAX_ADMIN_LEVEL);
        	SCM(playerid, COLOR_INFO, str);
        }
		if(value < 0 || value > MAX_ADMIN_LEVEL)
		{
			format(str, sizeof(str), "ERROR: You can only use a value between 0 and %i.",MAX_ADMIN_LEVEL);	
			SCM(playerid, COLOR_ERROR, str);
    	}
    	
		new targetid = GetPlayerID(target);

        if( targetid == playerid )
		    return SCM(playerid, COLOR_ERROR, "ERROR: You can not use this command on yourself.");

        if(IsPlayerConnected(targetid))
        {
            PlayerInfo[targetid][pAdmin] = value;

            mysql_format(ourConnection, query, sizeof(query),"UPDATE `accounts` SET `admin` = %i WHERE `acc_name` = %e",PlayerInfo[targetid][pAdmin], PlayerInfo[targetid][pAccName]);
    		mysql_tquery(ourConnection, query);

            format(str,sizeof(str),"SERVER: You have set {FFFFFF}%s(%i){ADD8E6} their admin level to {FFFFFF}%i{ADD8E6}.",ReturnName(targetid), targetid, value);
            SCM(playerid, COLOR_LIGHTBLUE, str);

            format(str,sizeof(str),"SERVER: Your admin level was set to {FFFFFF}%i{ADD8E6} by {FFFFFF}%s(%i){ADD8E6}.",value, ReturnName(playerid), playerid);
            SCM(targetid, COLOR_LIGHTBLUE,str);
        }
        else
        {
        	new rows, fields;
        	mysql_format(ourConnection, query, sizeof(query), "SELECT * FROM accounts WHERE acc_name = '%e'",PlayerInfo[target][pAccName]);
			mysql_tquery(ourConnection, query);
			cache_get_data(rows, fields, ourConnection);

    		if(!rows)
    			return SendClientMessage(playerid, COLOR_ERROR, "ERROR: That account does not exist.");

    		PlayerInfo[target][pAdmin] = value;
            PlayerInfo[playerid][pAdminRankMsg] = true; // sends the player a message when they login informing them that their admin rank was adjusted.

           	mysql_format(ourConnection, query, sizeof(query),"UPDATE `accounts` SET `admin` = %i WHERE `acc_name` = %e",PlayerInfo[target][pAdmin], PlayerInfo[target][pAccName]);
    		mysql_tquery(ourConnection, query);

    		format(str, sizeof(str), "SERVER: You have set {FFFFFF}%s{ADD8E6} their admin level to {FFFFFF}%i{A7A7A7}.",target, value);
            SCM(playerid, COLOR_LIGHTBLUE, str);
        }
    }
    return 1;
}
Anyone, please help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)