Cant set the level.
#1

I type in Example: /setlevel 0 3 but it sets level to 0
pawn Код:
CMD:setlevel(playerid, params[])
{
    new targetid;
    new level;
    new string[128];
    if (IsPlayerAdmin(playerid) || PlayerInfo[playerid][AdminLevel] == 5)
    {
        if (level > 5) return SendClientMessage(playerid,COLOR_RED,"Error:Max level is 5!");
        if (level < 0) return SendClientMessage(playerid,COLOR_RED,"Error:Min level is 0!");
        if (level >= 0 && level <= 5)
        {
            new name[MAX_PLAYER_NAME];
            new PlayerName[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));
            GetPlayerName(targetid, PlayerName, sizeof(PlayerName));
            format(string, sizeof(string), "%s Has Given You Admin Level %d .", name, level);
            SendClientMessage(targetid, 0xD8D8D8FF, string);
            format(string, sizeof(string), "You Gave Admin Level %d To %s .", level, PlayerName);
            SendClientMessage(playerid, 0xD8D8D8FF, string);
            PlayerInfo[targetid][AdminLevel] = level;
            return 1;
        }
    }
    return 1;
}
Reply
#2

You forgot about sscanf
Reply
#3

I tryed to add it i had same error so i deleted it thinking it isnt sscanf...
Reply
#4

pawn Код:
CMD:setlevel(playerid, params[])
{
    new string[128];
    if (IsPlayerAdmin(playerid) || PlayerInfo[playerid][AdminLevel] == 5)
    {
        new tmp[20], tmp2[20], idx;
        tmp = strtok(params, idx); tmp2 = strtok(params, idx);
        if(!strlen(tmp) || strlen(tmp2))  return SendClientMessage(playerid,COLOR_RED,"Usage: /setlevel [playerid] [level]!");
        new targetid = strval(tmp);
        new level = strval(tmp2);
        if (level > 5) return SendClientMessage(playerid,COLOR_RED,"Error:Max level is 5!");
        if (level < 0) return SendClientMessage(playerid,COLOR_RED,"Error:Min level is 0!");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"Error:Player not connected!");
        new name[MAX_PLAYER_NAME];
        new PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        GetPlayerName(targetid, PlayerName, sizeof(PlayerName));
        format(string, sizeof(string), "%s Has Given You Admin Level %d .", name, level);
        SendClientMessage(targetid, 0xD8D8D8FF, string);
        format(string, sizeof(string), "You Gave Admin Level %d To %s .", level, PlayerName);
        SendClientMessage(playerid, 0xD8D8D8FF, string);
        PlayerInfo[targetid][AdminLevel] = level;
        return 1;
    }
    return 1;
}

//from https://sampwiki.blast.hk/wiki/Strtok
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Some might say use sscanf, that's up to you. I made it with strtok now, because I prefer it.
Reply
#5

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Some might say use sscanf, that's up to you. I made it with strtok now, because I prefer it.
Yikes!

pawn Код:
CMD:setlevel ( playerid, params[] )
{
    new
        user,
        level;
       
    if( !IsPlayerAdmin ( playerid ) || PlayerInfo [ playerid ] [ AdminLevel ] < 5)
        return false; // Invalid permissions!
       
    if( sscanf( params, "ui", user, level ) )
        return SendClientMessage(playerid,COLOR_RED,"Usage: /setlevel [playerid] [level]!");
       
    PlayerInfo [ user ] [ AdminLevel ] = level;
   
    new
        name [ MAX_PLAYER_NAME ],
        PlayerName [ MAX_PLAYER_NAME ];
       
    GetPlayerName ( playerid, name, sizeof ( name ) );
    GetPlayerName ( user, PlayerName, sizeof ( PlayerName ) );
       
    format ( string, sizeof ( string ), "%s Has Given You Admin Level %d .", name, level );
    SendClientMessage ( user, 0xD8D8D8FF, string );
       
    format ( string, sizeof ( string ), "You Gave Admin Level %d To %s .", level, PlayerName );
    SendClientMessage( playerid, 0xD8D8D8FF, string );
    return true;
}
With sscanf.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)