help me with /admin command!
#1

Hello i created a /(a)dmin command. But when i compile i get some errors ¤_¤
This is the code:
pawn Код:
CMD:admin(playerid, params[])
{
        if(IsPlayerConnected(playerid))
        {
            new sendername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[96];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: (/a)dmin [admin chat]");
                return 1;
            }
            new atext[60];
            if(Player[playerid][AdminLevel] == 1)
            {
                atext = "Junior Moderator";
            }
            if(Player[playerid][AdminLevel] == 2)
            {
                atext = "Moderator";
            }
            if(Player[playerid][AdminLevel] == 3)
            {
                atext = "Lead Moderator";
            }
            if(Player[playerid][AdminLevel] == 4)
            {
                atext = "Junior Administrator";
            }
            if(Player[playerid][AdminLevel] == 5)
            {
                atext = "Administrator";
            }
            if(Player[playerid][AdminLevel] == 6)
            {
                atext = "Lead Administrator";
            }
            if(Player[playerid][AdminLevel] == 7)
            {
                atext = "Owner";
            }
            format(string, sizeof(string), "[%s] %s (%d):"COL_WHITE " %s", atext, RemoveUnderScore(playerid), playerid, result);
            if(Player[playerid][AdminLevel] >= 1)
            {
                SendAdminMessage(COLOR_NICEGREEN, string);
            }
        }
        return 1;
}
This is the errors i get:
pawn Код:
error 017: undefined symbol "cmdtext"
error 017: undefined symbol "idx"
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
Reply
#2

You are using ZCMD (CMIIW), There is already "params" parameter, which contain input from the command after space symbol (e.g. /admin <params>). You don't need to use strrest code placed on the command.
So just do this:
pawn Код:
CMD:admin(playerid, params[])
{
    if(!IsPlayerConnected(playerid)) return 0; // Player is not connected.
    if(Player[playerid][AdminLevel] >= 1) // Better check first if it's an admin
    {
        new sendername[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sendername, sizeof(sendername)); // I'm not sure what are you going to use this at, But it might be replaced on function "RemoveUnderScore(playerid)" instead?
        if(!strlen(params))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: (/a)dmin [admin chat]");
            return 1;
        }
        new atext[20]; // This only need 20 because the longest string, "Junior Administrator" length is 20
        switch(Player[playerid][AdminLevel])
        {
            case 1: atext = "Junior Moderator";
            case 2: atext = "Moderator";
            case 3: atext = "Lead Moderator";
            case 4: atext = "Junior Administrator";
            case 5: atext = "Administrator";
            case 6: atext = "Lead Administrator";
            case 7: atext = "Owner";
        }
        format(string, sizeof(string), "[%s] %s (%d):"COL_WHITE" %s", atext, RemoveUnderScore(playerid) /* Isn't this supposed to be "sendername"? */, playerid, params);
        SendAdminMessage(COLOR_NICEGREEN, string);
    }
    else SendClientMessage(playerid, COLOR_WHITE, "You are not an admin!"); // or "return 0;" here
    return 1;
}
I've also corrected some code, so only admin can send it, and optimized the variable usage. Although it's not tested yet, but i'm sure it will work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)