SetLevel problem..
#1

pawn Код:
CMD:setlevel(playerid,params[])
{
    new targetid, alevel, arank[32];
    new string[256], string2[256], name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
    if(IsPlayerAdmin(playerid) || pInfo[playerid][ALevel] > 4)
    {
        if(sscanf(params, "ui", targetid, alevel)) return SendClientMessage(playerid, yellow, "[USAGE]: /setlevel [playerid] [level]");
        else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "[ERROR]: The player is not connected!");
        else if(alevel < 0|| alevel > 4) return SendClientMessage(playerid, red, "[ERROR]: Invalid level, only 1 - 4.");
        if(alevel == pInfo[targetid][ALevel]) return SendClientMessage(playerid, red, "[ERROR]: Player is in current level!");
        if(alevel >= 1)
        {
            switch(alevel)
            {
                case 0:arank = "Player";
                case 1:arank = "Moderator";
                case 2:arank = "Administrator";
                case 3:arank = "Head Administrator";
                case 4:arank = "Server Owner";
            }
            GetPlayerName(playerid, name, sizeof(name));
            GetPlayerName(targetid, name2, sizeof(name2));
            GameTextForPlayer(targetid, "PROMOTED!", 5000, 3);
            format(string, sizeof(string), "Server Owner %s (ID: %i) has promoted you to %s (Level %i)", name, playerid, arank, alevel);
            format(string2, sizeof(string2), "%s (ID: %i) has been promoted to %s (Level %i)", name2, playerid, arank, alevel);
            SendClientMessage(targetid, aqua, string);
            SendClientMessageToAll(aqua, string2);
            PlayerPlaySound(targetid, 1057, 0, 0, 0);
            PlayerPlaySound(playerid, 1057, 0, 0, 0);
            pInfo[targetid][ALevel] = alevel;
        }
        else if(alevel != pInfo[targetid][ALevel])
        {
            switch(alevel)
            {
                case 0:arank = "Player";
                case 1:arank = "Moderator";
                case 2:arank = "Administrator";
                case 3:arank = "Head Administrator";
                case 4:arank = "Server Owner";
            }
            GameTextForPlayer(targetid, "DEMOTED!", 5000, 3);
            GetPlayerName(playerid, name, sizeof(name));
            GetPlayerName(targetid, name2, sizeof(name2));
            format(string, sizeof(string), "Server Owner %s (ID: %i) has demoted you to %s (Level %i)", name, playerid, arank, alevel);
            format(string2,sizeof(string2), "%s (ID: %i) has been demoted to %s (Level %i)", name2, playerid, arank, alevel);
            SendClientMessage(targetid, aqua, string);
            SendClientMessageToAll(aqua, string2);
            PlayerPlaySound(targetid, 1057, 0, 0, 0);
            PlayerPlaySound(playerid, 1057, 0, 0, 0);
            pInfo[targetid][ALevel] = alevel;
        }
        new INI:file = INI_Open(Path(targetid));
        INI_WriteInt(file, "AdminLevel", pInfo[targetid][ALevel]);
        INI_Close(file);
    }
    else return SendClientMessage(playerid, red, "[ERROR]: You're not supposed to use this, admin-hunger.");
    return 1;
}
Updated...
Reply
#2

Please designate the lines that the errors occur on. This makes troubleshooting 10 times easier.
Reply
#3

The errors are at /* and */, that's the error lines...
Reply
#4

Quote:
Originally Posted by LeeXian99
Посмотреть сообщение
The errors are at /* and */, that's the error lines...
It means that in your enumeration ALevel is not an array, so when you try to save a string to it, it will tell you that it needs to be an array.. You need to add a size after it, such as what appears to be [18] in your case (the number of characters in the longest rank).
Reply
#5

How to do it, for an example please?
Reply
#6

Search for ALevel in your script. When you find where ALevel is first designated in an enum, just add [18] to the end of it.
Reply
#7

After I added [18] on the enum, but it shows error again...
pawn Код:
case 0:pInfo[targetid][ALevel] = "Moderator";
                case 1:pInfo[targetid][ALevel] = "Administrator";
                case 2:pInfo[targetid][ALevel] = "Head Administrator";
                case 3:pInfo[targetid][ALevel] = "Server Owner";
Код:
C:\Documents and Settings\User\Desktop\0.3x Script\gamemodes\stuntproject.pwn(1298) : error 047: array sizes do not match, or destination array is too small
C:\Documents and Settings\User\Desktop\0.3x Script\gamemodes\stuntproject.pwn(1299) : error 047: array sizes do not match, or destination array is too small
C:\Documents and Settings\User\Desktop\0.3x Script\gamemodes\stuntproject.pwn(1300) : error 047: array sizes do not match, or destination array is too small
C:\Documents and Settings\User\Desktop\0.3x Script\gamemodes\stuntproject.pwn(1301) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#8

First of all.
That is not a string.
You need a string to do that level.

pawn Код:
new Rank[71];
case 0:Rank = "Moderator";
                case 1:Rank = "Administrator";
                case 2:Rank = "Head Administrator";
                case 3:Rank = "Server Owner";
Don't do ALevel as arrary. Make it integer.
Reply
#9

Jake, I don't know why the code works but it doesn't promote a player when I tried to promote myself... is there any problem with this script? Anyone please?

pawn Код:
CMD:setlevel(playerid,params[])
{
    new targetid, alevel, arank[32];
    new string[256], string2[256], name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
    if(IsPlayerAdmin(playerid), pInfo[playerid][ALevel] > 4)
    {
        if(sscanf(params, "ui", targetid, alevel)) return SendClientMessage(playerid, yellow, "[USAGE]: /setlevel [playerid] [level]");
        else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "[ERROR]: The player is not connected!");
        else if(alevel < 0|| alevel > 4) return SendClientMessage(playerid, red, "[ERROR]: Invalid level, only 1 - 4.");
        if(alevel == pInfo[targetid][ALevel]) return SendClientMessage(playerid, red, "[ERROR]: Player is in current level!");
        if(alevel >= 1)
        {
            switch(alevel)
            {
                case 0:arank = "Player";
                case 1:arank = "Moderator";
                case 2:arank = "Administrator";
                case 3:arank = "Head Administrator";
                case 4:arank = "Server Owner";
            }
            GetPlayerName(playerid, name, sizeof(name));
            GetPlayerName(targetid, name2, sizeof(name2));
            GameTextForPlayer(targetid, "PROMOTED!", 5000, 3);
            format(string, sizeof(string), "Server Owner %s (ID: %i) has promoted you to %s (Level %i)", name, playerid, alevel, alevel);
            format(string2, sizeof(string2), "%s (ID: %i) has been promoted to %s (Level %i)", name2, playerid, alevel, alevel);
            SendClientMessage(targetid, aqua, string);
            SendClientMessageToAll(aqua, string2);
            PlayerPlaySound(targetid, 1057, 0, 0, 0);
            PlayerPlaySound(playerid, 1057, 0, 0, 0);
            pInfo[targetid][ALevel] = alevel;
        }
        else if(alevel == 0)
        {
            GameTextForPlayer(targetid, "DEMOTED!", 5000, 3);
            format(string, sizeof(string), "Server Owner %s (ID: %i) has demoted you to %s (Level %i)", name, playerid, alevel, alevel);
            format(string2,sizeof(string2), "%s (ID: %i) has been demoted to %s (Level %i)", name2, playerid, alevel, alevel);
            SendClientMessage(targetid, aqua, string);
            SendClientMessageToAll(aqua, string2);
            PlayerPlaySound(targetid, 1057, 0, 0, 0);
            PlayerPlaySound(playerid, 1057, 0, 0, 0);
            pInfo[targetid][ALevel] = alevel;
        }
        new INI:file = INI_Open(Path(targetid));
        INI_WriteInt(file, "Admin Level", pInfo[targetid][ALevel]);
    }
    else return SendClientMessage(playerid, red, "[ERROR]: You're not supposed to use this, admin-hunger.");
    return 1;
}
Reply
#10

The only problem I see is this :
pawn Код:
new INI:file = INI_Open(Path(targetid));
INI_WriteInt(file, "Admin Level", pInfo[targetid][ALevel]);
You didn't close the file when you should.
pawn Код:
new INI:file = INI_Open(Path(targetid));
INI_WriteInt(file, "Admin Level", pInfo[targetid][ALevel]);
INI_Close(file);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)