if statement problem
#1

Hello everyone, so I have made an /fedit command and I have been trying to figure out how to allow both admin and faction leaders to access the same command but instead it puts both if statements together.

here is the code

pawn Код:
CMD:fedit(playerid,params[]) //This is the family edit command
{
    if(pInfo[playerid][USER_ADMIN] < 5)
    {
        SendClientMessage(playerid, -1, "You must be an admin or a faction leader to use this command!");
        return 1;
    }
    if(pInfo[playerid][USER_FACTION] < 1 && pInfo[playerid][USER_FACTIONRANK] < 10)
    {
        SendClientMessage(playerid, -1, "You must be an admin or a faction leader to use this command!");
        return 1;
    }
    if(pInfo[playerid][USER_FACTION] > 0 && pInfo[playerid][USER_FACTIONRANK] == 10)
    {
        ShowPlayerDialog(playerid, factionedit, DIALOG_STYLE_LIST, "Faction Edit Panel","Faction Name\nFaction Ranks\nFaction MOTD", "Select", "Close");
        return 1;
    }
    if(pInfo[playerid][USER_ADMIN] == 5)
    {
        ShowPlayerDialog(playerid, factionedit, DIALOG_STYLE_LIST, "Faction Edit Panel","Faction Name\nFaction Ranks\nFaction MOTD", "Select", "Close");
        return 1;
    }
    return 1;
}
the problem is if I am an admin and I am not a faction leader it gives me the message instead of the dialog.
Reply
#2

This should do the job well.

PHP код:
if(pInfo[playerid][USER_ADMIN] < || (pInfo[playerid][USER_FACTION] < && pInfo[playerid][USER_FACTIONRANK] < 10)) 
Reply
#3

pawn Код:
if(pInfo[playerid][USER_ADMIN] < 5 && pInfo[playerid][USER_FACTION] < 1 && pInfo[playerid][USER_FACTIONRANK] < 10) return SendClientMessage(playerid, -1, "You must be an admin or a faction leader to use this command!");
Reply
#4

I am trying to make them separate, like if you are an admin you can access it without being a faction leader or a part of the faction, and if you are the faction leader you don't have to be a part of the faction.
Reply
#5

Can you also provide the necessary numbers of USER_FACTION and USER_FACTIONRANK as I am not aware of?
Reply
#6

They are being created by a command I don't have them premade I use a command called /createfaction to set the ID and the name of the faction, here is the code.

pawn Код:
CMD:createfaction(playerid, params[])//Command only to be used to create families
{
    new pname[MAX_PLAYER_NAME], string[200], Query[500], facname[50], factionid;
    GetPlayerName(playerid, pname, 24);
   
    if(sscanf(params, "ds[50]", factionid, facname))
    {
        SendClientMessage(playerid, -1, "[USAGE]: /createfaction (faction id) (factionname)");
        return 1;
    }
    if(strlen(facname) > 50)
    {
        SendClientMessage(playerid, -1, "The maximum length for a faction name is 50.");
        return 1;
    }
    if(pInfo[playerid][USER_ADMIN] < 5)
    {
        SendClientMessage(playerid, -1, "You do not have permissions to use this command.");
        return 1;
    }
    if(strlen(facname) <= 50)
    {
        fInfo[FID] = factionid;
        fInfo[FNAME] = facname;
        format(Query, sizeof(Query), "INSERT INTO factioninfo (fid, fname) VALUES (%d, '%s')", fInfo[FID], fInfo[FNAME]);
        db_query(FDatabase, Query);
        format(string, sizeof(string), "[DEBUG]You have created faction named %s and set it's ID to %d.", fInfo[FNAME], fInfo[FID]);
        SendClientMessage(playerid, -1, string);
        return 1;
    }
    return 1;
}
Reply
#7

No, that's not what I meant.

You said "faction leader" so is that supposed to mean USER_FACTIONRANK should be equal to 10?
Also how do you check if the player is not "part of the faction"?
Reply
#8

The leadership rank is 10 and I store them both directly from the user data and then store the leaders name inside the factioninfo like this

pawn Код:
CMD:makeleader(playerid, params[]) //This command is only to be used to make someone a leader of a certain family
{
    new ID, pname[MAX_PLAYER_NAME], idname[MAX_PLAYER_NAME], factionid, Query[256], FQuery[256];
    GetPlayerName(playerid, pname, 24);
    GetPlayerName(ID, idname, 24);
   
    if(sscanf(params, "ud", ID, factionid))
    {
        SendClientMessage(playerid, -1, "[USAGE]/makeleader (playerid) (factionid).");
        return 1;
    }
    if(pInfo[playerid][USER_ADMIN] < 5)
    {
        SendClientMessage(playerid, -1, "You do not have permissions to use this command.");
        return 1;
    }
    if(pInfo[playerid][USER_ADMIN] == 5)
    {
        pInfo[ID][USER_FACTION] = factionid;
        pInfo[ID][USER_FACTIONRANK] = 10;
        fInfo[FACTIONLEADER] = idname;
        fInfo[FMEMBERS] += 1;
        format(Query, sizeof(Query), "UPDATE users SET faction = %d, factionrank = %d WHERE username = '%s'", pInfo[ID][USER_FACTION], pInfo[ID][USER_FACTIONRANK], DB_Escape(pInfo[ID][USER_NAME]));
        db_query(Database, Query);
        format(FQuery, sizeof(FQuery), "UPDATE factioninfo SET factionleader = '%s', fmembers = %d", fInfo[FACTIONLEADER], fInfo[FMEMBERS]);
        db_query(FDatabase, FQuery);
        return 1;
    }
    return 1;
}
Reply
#9

Like you currently have it, you can only have 1 faction stored to fInfo array. The correct way to copy strings is not by using '=', strcat is a good way to do it.

It'd be suggested to save the faction leader as an integer to both.

Anyway, the way you wrote it is a bit confusing so from what I understood you want something like being able to use the command if you are either admin or the faction leader (assuming level 5 is the max).
pawn Код:
if (pInfo[playerid][USER_ADMIN] != 5 && pInfo[playerid][USER_FACTIONRANK] != 10) return error..
Reply
#10

Yes thank you that was I was looking for.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)