Setlevel doesn't work properly
#1

Hello,

I'm making a /setlevel command where I want the player to be either logged into RCON or level 4 admin to be able to use it, but it isn't working. When I get on and log into RCON and attempt to use the command it tells me that I can't use it.

pawn Код:
CMD:setlevel(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 4) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");//Doesn't let admins under level 4 set an admin level
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");//Checking if the player is rcon admin to set an admin level
    new id, level;//Creating the id variable to store the selected id and a level variable for the chosen admin level.
    if(sscanf(params,"ui",id,level)) return SendClientMessage(playerid,0xF69521AA,"USAGE: /setlevel [id] [level(1-4)]");//Check if the player inputted a username or id and a admin level.
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.
    if (!(0 <= level <= 4)) return SendClientMessage(playerid,0xF69521AA,"Please specify an admin level between 0 and 4");
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(id,PlayerName,sizeof PlayerName);//Retrieving the selected id's name,
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    PlayerInfo[id][Level] = level;
    SendClientMessage(playerid,0xF69521AA,"You have successfully changed the selected user's admin level");
    SendClientMessage(id,0xF69521AA,"Your admin level has successfully been changed, congratulations!");
    return 1;
}
Reply
#2

I assume that you don't set a player's admin level to 5 when you login into RCON.

pawn Код:
CMD:setlevel(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 4 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");//Doesn't let admins under level 4 set an admin level
    new id, level;//Creating the id variable to store the selected id and a level variable for the chosen admin level.
    if(sscanf(params,"ui",id,level)) return SendClientMessage(playerid,0xF69521AA,"USAGE: /setlevel [id] [level(1-4)]");//Check if the player inputted a username or id and a admin level.
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.
    if (!(0 <= level <= 4)) return SendClientMessage(playerid,0xF69521AA,"Please specify an admin level between 0 and 4");
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(id,PlayerName,sizeof PlayerName);//Retrieving the selected id's name,
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    PlayerInfo[id][Level] = level;
    SendClientMessage(playerid,0xF69521AA,"You have successfully changed the selected user's admin level");
    SendClientMessage(id,0xF69521AA,"Your admin level has successfully been changed, congratulations!");
    return 1;
}
OR instead, simply do -

pawn Код:
stock GetPlayerFromIP( ip[] )
{
    new pIP[16];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
          GetPlayerIp(playerid, pIP, 16);
          if( !strcmp( pIP, ip ) ) return i;
          else continue;
    }
    return -1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    if(success)
    {
         if( GetPlayerFromIP( ip ) != -1 ) return ( PlayerInfo[playerid][Level] = 4 );
    }
    return 1;
}
Reply
#3

pawn Код:
CMD:setlevel(playerid,params[])
{
    if(PlayerInfo[playerid][Level] > 4 || IsPlayerAdmin(playerid))
    {
       new id, level;//Creating the id variable to store the selected id and a level variable for the chosen admin level.
       if(sscanf(params,"ui",id,level)) return SendClientMessage(playerid,0xF69521AA,"USAGE: /setlevel [id] [level(1-4)]");//Check if the player inputted a username or id and a admin level.
       if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.
       if (!(0 <= level <= 4)) return SendClientMessage(playerid,0xF69521AA,"Please specify an admin level between 0 and 4");
       new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
       GetPlayerName(id,PlayerName,sizeof PlayerName);//Retrieving the selected id's name,
       format(file,sizeof file,"Admin/%s.ini",PlayerName);
       PlayerInfo[id][Level] = level;
       SendClientMessage(playerid,0xF69521AA,"You have successfully changed the selected user's admin level");
       SendClientMessage(id,0xF69521AA,"Your admin level has successfully been changed, congratulations!");
       return 1;
   }
   else SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");//Doesn't let admins under level 4 set an admin level
   return 1;
}
Reply
#4

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
I assume that you don't set a player's admin level to 5 when you login into RCON.

pawn Код:
CMD:setlevel(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 4 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");//Doesn't let admins under level 4 set an admin level
    new id, level;//Creating the id variable to store the selected id and a level variable for the chosen admin level.
    if(sscanf(params,"ui",id,level)) return SendClientMessage(playerid,0xF69521AA,"USAGE: /setlevel [id] [level(1-4)]");//Check if the player inputted a username or id and a admin level.
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xF69521AA,"The specified player is currently not connected!");//Checking if the selected user is connected or not.
    if (!(0 <= level <= 4)) return SendClientMessage(playerid,0xF69521AA,"Please specify an admin level between 0 and 4");
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(id,PlayerName,sizeof PlayerName);//Retrieving the selected id's name,
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    PlayerInfo[id][Level] = level;
    SendClientMessage(playerid,0xF69521AA,"You have successfully changed the selected user's admin level");
    SendClientMessage(id,0xF69521AA,"Your admin level has successfully been changed, congratulations!");
    return 1;
}
OR instead, simply do -

pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(success)
    {
         return ( PlayerInfo[playerid][Level] = 4 );
    }
    return 1;
}
That last part seems amazing actually, just what I needed. Although, I can't find public OnRconLoginAttempt in my script somewhy?
Reply
#5

Quote:
Originally Posted by Vasu99
Посмотреть сообщение
That last part seems amazing actually, just what I needed. Although, I can't find public OnRconLoginAttempt in my script somewhy?
Search for it in your mode - if you can't, just add it as it is outside any other callbacks!
Reply
#6

That's weird, I got the following error:

pawn Код:
C:\Users\vasu\Desktop\Sa-Mp Roleplay Serv\gamemodes\Roleplay.pwn(1343) : error 017: undefined symbol "playerid"
Reply
#7

Stupid me! You'd have to find the playerID from the IP.
Updated previous post.
Reply
#8

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
pawn Код:
if(PlayerInfo[playerid][Level] < 4 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");
It should be:
pawn Код:
if(PlayerInfo[playerid][Level] < 4 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");
because the OR (||) makes it to return an error if the player is not both rcon and admin >= 4 level.
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It should be:
pawn Код:
if(PlayerInfo[playerid][Level] < 4 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xF69521AA,"You can't use this command!");
because the OR (||) makes it to return an error if the player is not both rcon and admin >= 4 level.
Not really, you said it yourself though it means OR, if the player level lower than 4 OR not RCON logged in.
Reply
#10

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
Not really, you said it yourself though it means OR, if the player level lower than 4 OR not RCON logged in.
Why don't you test it yourself and see?

It's like when using NOT. The OR becomes AND.

If the player is neither admin with level >= 4, nor rcon admin return error.

What you're saying is:
A player is level 2 and rcon admin so your code will return an error because the player is not 4+ level, HOWEVER he's rcon admin.

Using AND instead will make the command to work for the player who are only level 4+ admins, or only RCON admins or both.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)