PDA

View Full Version : Problem with my command


K9IsGodly
14/05/2014, 04:56 PM
CMD:giverank(playerid, params[])
{
if(PlayerFacInfo[playerid][Fac] >= 15)
{
new targetid, level;
if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, -1, "/giverank [playerid/partofname] [level]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not currently online!");
if(!(-1 < level < 20 )) return SendClientMessage(playerid, -1, "The max level is 16!");
new faclevel[20], astr[128], sendername[MAX_PLAYER_NAME];
if(PlayerInfo[playerid][pAdmin] == 99999 || PlayerFacInfo[playerid][Fac] == 15)
{
switch(level)
{
case 0:
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have been demoted by Admin %s", sendername);
SendClientMessage(targetid, -1, astr);
GetPlayerName(targetid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have demoted %s of their Admin rank.", sendername);
SendClientMessage(playerid, -1, astr);
PlayerFacInfo[targetid][Fac] = level;
return 1;
}
case 1: faclevel = "Cadet In Training";
case 2: faclevel = "Cadet";
case 3: faclevel = "Officer";
case 4: faclevel = "Corporal";
case 5: faclevel = "Sergeant";
case 6: faclevel = "Sergeant Grade Two";
case 7: faclevel = "Lieutenant";
case 8: faclevel = "Inspector";
case 9: faclevel = "Captain";
case 10: faclevel = "Major";
case 11: faclevel = "Major Grade Two";
case 12: faclevel = "Commander";
case 13: faclevel = "Commissioner";
case 14: faclevel = "Chief Inspector";
case 15: faclevel = "Deputy Chief";
case 16: faclevel = "Chief";
default: return SendClientMessage(playerid, -1, "You have entered an invalid level. (0 - 16)");
}
GetPlayerName(playerid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have been made into a %s by Admin %s!", faclevel, sendername);
SendClientMessage(targetid, -1, astr);
GetPlayerName(targetid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have made %s into a %s!", sendername, faclevel);
SendClientMessage(playerid, -1, astr);
PlayerFacInfo[targetid][Fac] = level;
PlayerFacInfo[targetid][FacType] = 1;
}
}
else
{
SendClientMessage(playerid, -1, "You do not meet the level requirement for using this command!");
}
return 1;
}



CMD:makepolicechief(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 6)
{
new targetid;
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "/makepolicechief [playerid/partofname]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not currently online!");
PlayerFacInfo[targetid][Fac] = 16;
PlayerFacInfo[targetid][FacType] = 1;
SendClientMessage(targetid, COLOR_BLUE, "You have been made into the police chief, congratulations!");
}
else
{
SendClientMessage(playerid, -1, "You do not meet the admin requirements to use this command!");
}
return 1;
}


That is my code for a faction system I'm just now creating. One of my issues is that when I am a level 99999 admin I can't /giverank, but when I /makepolicechief myself I am able to use the /giverank command. I want it so level 99999 admins and or deputy chiefs/chiefs can use the command (Deputy chief being level 15 and chief being level 16). Whenever I use the command as a level 99999 admin it just tells me I don't meet the level requirement. Can anyone tell what's wrong or should I show some other code?

Lynn
14/05/2014, 05:24 PM
CMD:giverank(playerid, params[])
{
if(IsPlayerConnected(playerid))
{
new targetid, level;
if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, -1, "/giverank [playerid/partofname] [level]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not currently online!");
if(!(-1 < level < 20 )) return SendClientMessage(playerid, -1, "The max level is 16!");
new faclevel[20], astr[128], sendername[MAX_PLAYER_NAME];
if(PlayerInfo[playerid][pAdmin] == 99999 || PlayerFacInfo[playerid][Fac] == 15)
{
switch(level)
{
case 0:
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have been demoted by Admin %s", sendername);
SendClientMessage(targetid, -1, astr);
GetPlayerName(targetid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have demoted %s of their Admin rank.", sendername);
SendClientMessage(playerid, -1, astr);
PlayerFacInfo[targetid][Fac] = level;
return 1;
}
case 1: faclevel = "Cadet In Training";
case 2: faclevel = "Cadet";
case 3: faclevel = "Officer";
case 4: faclevel = "Corporal";
case 5: faclevel = "Sergeant";
case 6: faclevel = "Sergeant Grade Two";
case 7: faclevel = "Lieutenant";
case 8: faclevel = "Inspector";
case 9: faclevel = "Captain";
case 10: faclevel = "Major";
case 11: faclevel = "Major Grade Two";
case 12: faclevel = "Commander";
case 13: faclevel = "Commissioner";
case 14: faclevel = "Chief Inspector";
case 15: faclevel = "Deputy Chief";
case 16: faclevel = "Chief";
default: return SendClientMessage(playerid, -1, "You have entered an invalid level. (0 - 16)");
}
GetPlayerName(playerid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have been made into a %s by Admin %s!", faclevel, sendername);
SendClientMessage(targetid, -1, astr);
GetPlayerName(targetid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have made %s into a %s!", sendername, faclevel);
SendClientMessage(playerid, -1, astr);
PlayerFacInfo[targetid][Fac] = level;
PlayerFacInfo[targetid][FacType] = 1;
}
}
else
{
SendClientMessage(playerid, -1, "You do not meet the level requirement for using this command!");
}
return 1;
}

K9IsGodly
14/05/2014, 05:33 PM
CMD:giverank(playerid, params[])
{
if(IsPlayerConnected(playerid))
{
new targetid, level;
if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, -1, "/giverank [playerid/partofname] [level]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not currently online!");
if(!(-1 < level < 20 )) return SendClientMessage(playerid, -1, "The max level is 16!");
new faclevel[20], astr[128], sendername[MAX_PLAYER_NAME];
if(PlayerInfo[playerid][pAdmin] == 99999 || PlayerFacInfo[playerid][Fac] == 15)
{
switch(level)
{
case 0:
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have been demoted by Admin %s", sendername);
SendClientMessage(targetid, -1, astr);
GetPlayerName(targetid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have demoted %s of their Admin rank.", sendername);
SendClientMessage(playerid, -1, astr);
PlayerFacInfo[targetid][Fac] = level;
return 1;
}
case 1: faclevel = "Cadet In Training";
case 2: faclevel = "Cadet";
case 3: faclevel = "Officer";
case 4: faclevel = "Corporal";
case 5: faclevel = "Sergeant";
case 6: faclevel = "Sergeant Grade Two";
case 7: faclevel = "Lieutenant";
case 8: faclevel = "Inspector";
case 9: faclevel = "Captain";
case 10: faclevel = "Major";
case 11: faclevel = "Major Grade Two";
case 12: faclevel = "Commander";
case 13: faclevel = "Commissioner";
case 14: faclevel = "Chief Inspector";
case 15: faclevel = "Deputy Chief";
case 16: faclevel = "Chief";
default: return SendClientMessage(playerid, -1, "You have entered an invalid level. (0 - 16)");
}
GetPlayerName(playerid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have been made into a %s by Admin %s!", faclevel, sendername);
SendClientMessage(targetid, -1, astr);
GetPlayerName(targetid, sendername, sizeof(sendername));
format(astr, sizeof(astr), "You have made %s into a %s!", sendername, faclevel);
SendClientMessage(playerid, -1, astr);
PlayerFacInfo[targetid][Fac] = level;
PlayerFacInfo[targetid][FacType] = 1;
}
}
else
{
SendClientMessage(playerid, -1, "You do not meet the level requirement for using this command!");
}
return 1;
}

Thanks, much appreciated. What was wrong with my original code? I couldn't find what you changed and I would like to know what you did in order to prevent issues in the future.

Lynn
14/05/2014, 05:39 PM
You had
if(PlayerFacInfo[playerid][Fac] >= 15)
Inside the code twice, once at the top, and once farther down.
The one at the top, didn't specify or if the player is a Admin 99999, So I just changed that to if the Player is connected, then proceed, and pause to see if the player is either a Admin or Faction 15.