Set admin.
#1

Well I coded a set admin command into my script but what I'll like is for it to detect whether the player is being promoted or demoted to a lower level. So I tried doing this, it compiles fine, but In-Game the text doesn't show it's just blank lines.

Here's my current code.

pawn Код:
CMD:setadmin(playerid, params[])
{
    if(IsAdmin(playerid, 4))
    {
        new target, level, Promoted[128], Demoted[128];
        if(sscanf(params, "ri", target, level))
        if(level > 5) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] You can not set a Administrator Level higher than level 5.");
        if( level > PlayerInfo[target][Administrator] ) { SendAdminMessage(COLOR_RED, Promoted ); }
        else if( level < PlayerInfo[target][Administrator] ) { SendAdminMessage(COLOR_RED, Demoted ); }
        PlayerInfo[target][Administrator] = level;

        new PlayerName[MAX_PLAYER_NAME], TargetName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        GetPlayerName(target, TargetName, sizeof(TargetName));

        format(Promoted, sizeof(Promoted), "%s %s has promoted %s to a Level %d Administrator.", GetAdminRank(playerid), PlayerName, TargetName, level);
        Logs("Logs/Promotions.txt", Promoted);

        format(Demoted, sizeof(Demoted), "%s %s has demoted %s to a Level %d Administrator.", GetAdminRank(playerid), PlayerName, TargetName, level);
        Logs("Logs/Demotions.txt", Demoted);
    }
    else return SendClientMessage(playerid, COLOR_RED, "[CONSOLE] You are not allowed to use this command.");
    return 1;
}
Also, slight problem with my admin chat command. It works fine but there's a slight problem.

If use the command, for example:

I'll do /achat testing - It will show [Owner] Nicholas: testing
Now if I do /achat (without typing a text) - It will show [Owner] Nicholas:

pawn Код:
CMD:achat(playerid, params[])
{
    new PlayerName[128], String[128];
    if(PlayerInfo[playerid][Administrator] < 1)
    if(isnull(params)) { SendClientMessage(playerid, COLOR_RED, "[ADMIN] /achat [Chat]"); }
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    format(String, sizeof(String),"%s %s: %s", GetAdminRank(playerid), PlayerName, params);
    SendAdminMessage(COLOR_RED, String);
    return 1;
}
Reply
#2

Both I have tried before, and haven't fix it.
Reply
#3

You started out pretty good, what you did wrong, is that you SendClientMessage before you format the "Promoted" "Demoted" strings, that's why it gives blank lines. This should work:

pawn Код:
CMD:setadmin(playerid, params[])
{
    if(IsAdmin(playerid, 4))
    {
        new target, level, String[128];
        if(sscanf(params, "ri", target, level))
        if(level > 5) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] You can not set a Administrator Level higher than level 5.");
        new PlayerName[MAX_PLAYER_NAME], TargetName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        GetPlayerName(target, TargetName, sizeof(TargetName));
        if( level > PlayerInfo[target][Administrator] )
                format(String, sizeof(String), "%s %s has promoted %s to a Level %d Administrator.", GetAdminRank(playerid), PlayerName, TargetName, level);
        else if( level < PlayerInfo[target][Administrator] )
                format(String, sizeof(String), "%s %s has demoted %s to a Level %d Administrator.", GetAdminRank(playerid), PlayerName, TargetName, level);
        PlayerInfo[target][Administrator] = level;
        SendClientMessage(target, -1, String);
    }
    else return SendClientMessage(playerid, COLOR_RED, "[CONSOLE] You are not allowed to use this command.");
    return 1;
}
You don't need two strings. Just one is enough and you format it according to promote or demote function.

About your second problem, ain't that big deal. You just have to put a return after checking if the param is null. Here:
pawn Код:
CMD:achat(playerid, params[])
{
    new PlayerName[128], String[128];
    if(PlayerInfo[playerid][Administrator] < 1)
    if(isnull(params)) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] /achat [Chat]");
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    format(String, sizeof(String),"%s %s: %s", GetAdminRank(playerid), PlayerName, params);
    SendAdminMessage(COLOR_RED, String);
    return 1;
}
Now, what you did wrong, is that you didn't return the command and it continued till the end, therefor sending an empty message. Now, after it checks if the param is null, if it's true, it'll return sending the admin a message, that he needs to insert a parameter. Returning the command, will not continue what's after the return. So, no other message will be sent.
Reply
#4

Okay thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)