Admin Rank displays incorrectly
#1

pawn Код:
YCMD:setadmin(playerid, params[], help)
{
    if( pInfo[playerid][Adminlevel] >= 4 )
    {
        new
            TargetID,
            tLevel,
            tReason[50],
            AdmRank[128];

        if( !sscanf(params, "uiS(No reason specified)[50]", TargetID, tLevel, tReason) )
        {
            if( tLevel > 6 )                    return SendClientMessage( playerid, -1, "[SYSTEM]: Maximum Level: 6." );
            if( pInfo[TargetID][Adminlevel] == tLevel )                    return SendClientMessage( playerid, -1, "[SYSTEM]: This player is already this level." );
            if( strlen( tReason ) > 50 )        return SendClientMessage( playerid, -1, "[SYSTEM]: Please use between 0-50 characters." );
            if( !IsPlayerConnected(TargetID)) return SendClientMessage( playerid, -1, "[SYSTEM]: Invalid ID. Please try again." );
            new
                MyString[128],
                TargetString[128];
            if(pInfo[TargetID][Adminlevel] == 0) { AdmRank = "Regular Player"; }
            else if(pInfo[TargetID][Adminlevel] == 1) { AdmRank = "Moderator"; }
            else if(pInfo[TargetID][Adminlevel] == 2) { AdmRank = "Professional Moderator"; }
            else if(pInfo[TargetID][Adminlevel] == 3) { AdmRank = "Administrator"; }
            else if(pInfo[TargetID][Adminlevel] == 4) { AdmRank = "Head Administrator"; }
            else if(pInfo[TargetID][Adminlevel] >= 5) { AdmRank = "Owner"; }
            if( pInfo[TargetID][Adminlevel] < tLevel )
            {
                format( MyString, sizeof MyString, "[SYSTEM]: You promoted %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(TargetID), TargetID, AdmRank, tLevel, tReason );
                format( TargetString, sizeof TargetString, "[SYSTEM]: You have been promoted by %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(playerid), playerid, AdmRank, tLevel, tReason );
                SendClientMessage( TargetID, -1, TargetString );
            }
            else
            {
                format( MyString, sizeof MyString, "[SYSTEM]: You demoted %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(TargetID), TargetID, AdmRank, tLevel, tReason );
                format( TargetString, sizeof TargetString, "[SYSTEM]: You have been demoted by %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(playerid), playerid, AdmRank, tLevel, tReason );
                SendClientMessage( TargetID, -1, TargetString );
            }
            SendClientMessage( playerid, -1, MyString );
            pInfo[TargetID][Adminlevel] = tLevel;
        }
        else
            return SendClientMessage( playerid, -1, "[SYSTEM]: /setadmin <TargetID> <Level> <(OPTIONAL)Reason>" );
    }
    else
        return SendClientMessage( playerid, -1, "[SYSTEM]: You have to be a moderator to use this command!" );
    return 1;
}
Whenever I promote or demoted a player, the "AdmRank" string is suppose to show the level name at which coincides the level number, but instead it's incorrectly displayed.

i.e.

Owner - level 5 and 6
Head Admin - level 4
Admin - level 3
Pro Mod - level 2
Mod - level 1

but it displays incorrectly..

Owner - level 5 and 6
Owner - level 4
Head admin - level 3
Admin - level 2
Pro Mod - level 1
Mod - level 0
Reply
#2

Why don't you use switch() statement?

pawn Код:
YCMD:setadmin(playerid, params[], help)
{
    if( pInfo[playerid][Adminlevel] >= 4 )
    {
        new
            TargetID,
            tLevel,
            tReason[50],
            AdmRank[128];

        if( !sscanf(params, "uiS(No reason specified)[50]", TargetID, tLevel, tReason) )
        {
            if( tLevel > 6 )                    return SendClientMessage( playerid, -1, "[SYSTEM]: Maximum Level: 6." );
            if( pInfo[TargetID][Adminlevel] == tLevel )                    return SendClientMessage( playerid, -1, "[SYSTEM]: This player is already this level." );
            if( strlen( tReason ) > 50 )        return SendClientMessage( playerid, -1, "[SYSTEM]: Please use between 0-50 characters." );
            if( !IsPlayerConnected(TargetID)) return SendClientMessage( playerid, -1, "[SYSTEM]: Invalid ID. Please try again." );
            new
                MyString[128],
                TargetString[128];
            switch(pInfo[TargetID][Adminlevel])
            {
                case 0: AdmRank = "Regular Player";
                case 1: AdmRank = "Moderator";
                case 2: AdmRank = "Professional Moderator";
                case 3: AdmRank = "Administrator";
                case 4: AdmRank = "Head Administrator";
                case 5,6: AdmRank = "Owner";
            }
            if( pInfo[TargetID][Adminlevel] < tLevel )
            {
                format( MyString, sizeof MyString, "[SYSTEM]: You promoted %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(TargetID), TargetID, AdmRank, tLevel, tReason );
                format( TargetString, sizeof TargetString, "[SYSTEM]: You have been promoted by %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(playerid), playerid, AdmRank, tLevel, tReason );
                SendClientMessage( TargetID, -1, TargetString );
            }
            else
            {
                format( MyString, sizeof MyString, "[SYSTEM]: You demoted %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(TargetID), TargetID, AdmRank, tLevel, tReason );
                format( TargetString, sizeof TargetString, "[SYSTEM]: You have been demoted by %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(playerid), playerid, AdmRank, tLevel, tReason );
                SendClientMessage( TargetID, -1, TargetString );
            }
            SendClientMessage( playerid, -1, MyString );
            pInfo[TargetID][Adminlevel] = tLevel;
        }
        else
            return SendClientMessage( playerid, -1, "[SYSTEM]: /setadmin <TargetID> <Level> <(OPTIONAL)Reason>" );
    }
    else
        return SendClientMessage( playerid, -1, "[SYSTEM]: You have to be a moderator to use this command!" );
    return 1;
}
Reply
#3

Stock:

pawn Код:
stock AdminRank(playerid)
{
    new name[23];
    if(pInfo[playerid][Adminlevel] == 0) format(name, sizeof(name), "Regular Player");
    else if(pInfo[playerid][Adminlevel] == 1) format(name, sizeof(name), "Moderator");
    else if(pInfo[playerid][Adminlevel] == 2) format(name, sizeof(name), "Professional Moderator");
    else if(pInfo[playerid][Adminlevel] == 3) format(name, sizeof(name), "Administrator");
    else if(pInfo[playerid][Adminlevel] == 4) format(name, sizeof(name), "Head Administrator");
    else if(pInfo[playerid][Adminlevel] > 4) format(name, sizeof(name), "Owner");
    return name;
}
Command:

pawn Код:
YCMD:setadmin(playerid, params[], help)
{
    if( pInfo[playerid][Adminlevel] >= 4 )
    {
        new
            TargetID,
            tLevel,
            tReason[50],

        if( !sscanf(params, "uiS(No reason specified)[50]", TargetID, tLevel, tReason) )
        {
            if( tLevel > 6 )                    return SendClientMessage( playerid, -1, "[SYSTEM]: Maximum Level: 6." );
            if( pInfo[TargetID][Adminlevel] == tLevel )                    return SendClientMessage( playerid, -1, "[SYSTEM]: This player is already this level." );
            if( strlen( tReason ) > 50 )        return SendClientMessage( playerid, -1, "[SYSTEM]: Please use between 0-50 characters." );
            if( !IsPlayerConnected(TargetID)) return SendClientMessage( playerid, -1, "[SYSTEM]: Invalid ID. Please try again." );
            new
                MyString[128],
                TargetString[128];
            if( pInfo[TargetID][Adminlevel] < tLevel )
            {
                format( MyString, sizeof MyString, "[SYSTEM]: You promoted %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(TargetID), TargetID, AdminRank(TargetID), tLevel, tReason );
                format( TargetString, sizeof TargetString, "[SYSTEM]: You have been promoted by %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(playerid), playerid, AdminRank(playerid), tLevel, tReason );
                SendClientMessage( TargetID, -1, TargetString );
            }
            else
            {
                format( MyString, sizeof MyString, "[SYSTEM]: You demoted %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(TargetID), TargetID, AdminRank(TargetID), tLevel, tReason );
                format( TargetString, sizeof TargetString, "[SYSTEM]: You have been demoted by %s(ID:%d) to a %s. Level: (%i). Reason: %s", GetName(playerid), playerid, AdminRank(playerid), tLevel, tReason );
                SendClientMessage( TargetID, -1, TargetString );
            }
            SendClientMessage( playerid, -1, MyString );
            pInfo[TargetID][Adminlevel] = tLevel;
        }
        else
            return SendClientMessage( playerid, -1, "[SYSTEM]: /setadmin <TargetID> <Level> <(OPTIONAL)Reason>" );
    }
    else
        return SendClientMessage( playerid, -1, "[SYSTEM]: You have to be a moderator to use this command!" );
    return 1;
}
Try that.
Reply
#4

I never knew a switch was needed for this, I thought AdmRank was pretty much like tLevel, variables where it would just get the rank after the guy was demoted/promoted. I'll try it out.
Reply
#5

By the way it still isn't working.

Reply
#6

switch tLevel instead. That should do it.


pawn Код:
switch(tLevel)
{
    case 0: AdmRank = "Regular Player";
    case 1: AdmRank = "Moderator";
    case 2: AdmRank = "Professional Moderator";
    case 3: AdmRank = "Administrator";
    case 4: AdmRank = "Head Administrator";
    case 5,6: AdmRank = "Owner";
}
Reply
#7

Thanks!
Reply
#8

Would an array be faster Alex? And would it possible for an example?
Reply
#9

I don't believe it's faster, but it's convenient because you can use it across your entire script. But that's beside the point of this topic. The actual problem is that the current admin level is retrieved, rather than the updated admin level because the messages are sent before the new level is actually set. If that made sense.

Edit: no strikethrough tag
Reply
#10

Yeah sorry for hijacking the topic, I just like finding out that I can make things faster.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)