/makeadmin, small problem.
#1

Hi. I got the following error:

pawn Код:
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
pawn Код:
CMD:makeadmin(playerid, params[])
{
    new id, level, file[256];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "ud", id, level))
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /makeadmin [playerid] [level 1-4]");
        else
        {
            if(level > 4) return SendClientMessage(playerid, COLOR_RED, "There are only 4 admin levels available!");
            else
            {
                if(level >= 1)
                if(fexist(file))
                dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel] = 1);
                SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to admin level 1!");
            }
            else
            {
                if(level >= 2)
                if(fexist(file))
                dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel] = 2);
                SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to admin level 2!");
            }
            else
            {
                if(level >= 3)
                if(fexist(file))
                dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel] = 3);
                SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to admin level 3!");
            }
            else
            {
                if(level >= 4)
                if(fexist(file))
                dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel] = 4);
                SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to developer / scripter!");
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "You must be an admin to promote someone!");
            }
        }
    }
    return 1;
}
pawn Код:
}
else
{
The last 4 else's are the error lines.

And, can someone give me the ZCMD codes? like: >= and < that sort of codes. I can't find it somehow.
Reply
#2

You can't have multiple else conditions, you need to use else if.

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new id, level, file[256];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "ud", id, level))
            return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /makeadmin [playerid] [level 1-4]");
        else
        {
            if(level > 4)
                return SendClientMessage(playerid, COLOR_RED, "There are only 4 admin levels available!");
            else if(level >= 1)
            {
                if(fexist(file))
                    dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel] = 1), SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to admin level 1!");
            }
            else if(level >= 2)
            {
                if(fexist(file))
                    dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel] = 2), SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to admin level 2!");
            }
            else if(level >= 3)
            {
                if(fexist(file))
                    dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel] = 3), SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to admin level 3!");
            }
            else if(level >= 4)
            {
                if(fexist(file))
                    dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel] = 4), SendClientMessage(playerid, COLOR_YELLOW, "You have been promoted to developer / scripter!");
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "You must be an admin to promote someone!");
            }
        }
    }
    return 1;
}
Reply
#3

Fixed. My bad.

But I still need those codes though.
Reply
#4

What do you mean with those codes?
Reply
#5

pawn Код:
CMD:makeadmin(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return 1;

    new id, level, file[128];
    if(sscanf(params, "ri", id, level)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /makeadmin [playerid] [level 1-4]");


    //You need to format file here with the file path for their user data.
    format(file, sizeof(file), "Filepath/here");

    if(fexist(file))
    {
        format(file, sizeof(file), "You have been promoted to admin level %i!", level);
        SendClientMessage(playerid, COLOR_YELLOW, file);

        PlayerInfo[playerid][pAdminLevel] = level;
        dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel]);
    }
    else SendClientMessage(playerid, 0xCC0000AA, "This user isn't registered!");
    return 1;
}
You don't need any elseifs at all really.
Reply
#6

Antonio. It works, but when I am about to make myself admin, it says I am not registered.
Reply
#7

I hope you get the name of the player and change the format for the location
pawn Код:
format(file, sizeof(file), "Users/%s.ini"); // Or whatever your path is!
Reply
#8

Did you modify the filepath to your file path? For example;
pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(file, sizeof(file), "MyServerName/Accounts/%s.ini", name);
Reply
#9

I did. It's called Account. My register system saves my account, but when I make myself admin I get the message that I am not registered.
Reply
#10

Use this....

Код:
CMD:makeadmin(playerid, params[])
{
   	if(!IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playerid, COLOR_GREY, "You are not allowed to use command.");
	if(IsPlayerAdmin(playerid))
	{
	    new playerb, admin, string[128];
	    if(sscanf(params, "ui", playerb, admin)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /no1canknowdis [playerid] [level]");
		if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
	    if(PlayerInfo[playerb][pAdmin] != admin)
	    {
	        new log[256];
		    if(PlayerInfo[playerb][pAdmin] < admin)
			{
		    	format(string, sizeof(string), "AdmWarn: %s has {33AA33}promoted {AA3333}%s to level {33AA33}%d {AA3333}admin.", RPN(playerid), RPN(playerb), admin);
            	format(log, sizeof(log), "AdmWarn: %s (%s) has promoted %s (%s) to level %d admin.", RPN(playerid), RPIP(playerid), RPN(playerb), RPIP(playerb), admin);
			}
			else if(PlayerInfo[playerb][pAdmin] > admin)
			{
	  	    	format(string, sizeof(string), "AdmWarn: %s has {FF9900}demoted {AA3333}%s to level {FF9900}%d {AA3333}admin.", RPN(playerid), RPN(playerb), admin);
	  	    	format(log, sizeof(log), "AdmWarn: %s (%s) has demoted %s (%s) to level %d admin.", RPN(playerid), RPIP(playerid), RPN(playerb), RPIP(playerb), admin);
			}
			Log("logs/makeadmin.log", log);
			PlayerInfo[playerb][pAdmin] = admin;
			PlayerInfo[playerb][pSafeAdmin] = 1;
			SendAdminMessage(COLOR_DARKRED, 1, string);
			if(!PlayerInfo[playerb][pAdmin])
			{
			    PlayerInfo[playerb][pSafeAdmin] = 0;
			    PlayerInfo[playerid][pGangMod] = 0;
			    PlayerInfo[playerid][pFacMod] = 0;
			    PlayerInfo[playerid][pBanAppealer] = 0;
			    SendClientMessage(playerb, COLOR_DARKRED, string);
			}
			new file[32];
			format(file, sizeof(file), "users/%s.ini", RPNU(playerb));
			format(file, sizeof(file), "users/%s.ini", dini_Get(file, "AdminName"));
			if(dini_Exists(file))
			{
				dini_IntSet(file, "Admin", PlayerInfo[playerb][pAdmin]);
			}
			format(file, sizeof(file), "users/%s.ini", RPNU(playerb));
			if(dini_Int(file, "AdminAccount") == 1)
			{
			    format(file, sizeof(file), "users/%s.ini", dini_Get(file, "OldName"));
			    dini_IntSet(file, "Admin", PlayerInfo[playerb][pAdmin]);
			}
		}
		else SendClientMessage(playerid, COLOR_GREY, "Player already has this admin level.");
	}
	else
	{
	    SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)