PDA

View Full Version : /makeadmin, small problem.


zClaw
31/05/2013, 02:52 PM
Hi. I got the following error:

error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero

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;
}


}
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.

GiamPy.
31/05/2013, 02:55 PM
You can't have multiple else conditions, you need to use else if.

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;
}

zClaw
31/05/2013, 02:57 PM
Fixed. My bad.

But I still need those codes though.

GiamPy.
31/05/2013, 02:59 PM
What do you mean with those codes?

[ABK]Antonio
31/05/2013, 03:05 PM
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.

zClaw
31/05/2013, 03:45 PM
Antonio. It works, but when I am about to make myself admin, it says I am not registered.

Konstantinos
31/05/2013, 03:47 PM
I hope you get the name of the player and change the format for the location

format(file, sizeof(file), "Users/%s.ini"); // Or whatever your path is!

[ABK]Antonio
31/05/2013, 03:48 PM
Did you modify the filepath to your file path? For example;

new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(file, sizeof(file), "MyServerName/Accounts/%s.ini", name);

zClaw
31/05/2013, 07:28 PM
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.

RalphHaro
31/05/2013, 07:57 PM
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;
}

zClaw
31/05/2013, 07:59 PM
You just copied this.. None of my saved function comes back in this code.