Setlevel Command Help -
Vasu99 - 27.02.2014
Hi,
Thanks for reading once again. This time I need help with the same command, although I would like to limit it somehow. By that, I mean I'd like to set a limit to which admin level you may set with that command, because right now there's no limit to which level I may set a player. I'd like to set the limit to 4, although I can't figure out how to do this. If you do decide to help me out, please also explain exactly what you're doing as I'd like to learn how to script and I feel like that's a great start.
Код:
CMD:setlevel(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0x3740B3,"Only rcon admins can set admin levels!");//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,0x3740B3,"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,0x3740B3,"The specified player is currently not connected!");//Checking if the selected user is connected or not.
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,0x3740B3,"You have successfully changed the selected user's admin level");
SendClientMessage(id,0x3740B3,"Your admin level has successfully been changed, congratulations!");
return 1;
}
Cheers!
Re: Setlevel Command Help -
Konstantinos - 27.02.2014
Just compare the level with the values you want. It can be either:
pawn Код:
if (!(0 <= level <= 4)) return SendClientMessage(playerid,0x3740B3,"Admin level must be between 0 and 4");
or:
pawn Код:
if (level < 0 || level > 4) return SendClientMessage(playerid,0x3740B3,"Admin level must be between 0 and 4");
Add that statement after IsPlayerConnected check.
Re: Setlevel Command Help -
Vasu99 - 27.02.2014
I don't really understand what you mean, I'm sorry. I mean, I don't understand what those codes do, could you perhaps try explaining it again?
Cheers mate!
Re: Setlevel Command Help -
Konstantinos - 27.02.2014
https://sampwiki.blast.hk/wiki/Control_Structures#if
https://sampwiki.blast.hk/wiki/Control_Structures#Operators
Those are basic. Read the above articles and you will understand how to compare variables with values or other variables.
It basically checks if the level is lesser than 0 (negative which is invalid level) or greater than 4 (which goes 5 and higher which is still invalid level). Pretty much the same thing the first one does as well. It checks if the level is not between 0 and 4.
Re: Setlevel Command Help -
Vasu99 - 27.02.2014
Alright, but how can I add this into my command? I think the first command you posted is the one I need, now that I've gone through it, although I'm not sure where in my command to put it. What it does is limit the /setlevel command to 0-4, right?
Re: Setlevel Command Help -
Konstantinos - 27.02.2014
Quote:
Originally Posted by Vasu99
Alright, but how can I add this into my command? ... although I'm not sure where in my command to put it.
|
I told you in my first post:
Quote:
Originally Posted by Konstantinos
Add that statement after IsPlayerConnected check.
|
Quote:
Originally Posted by Vasu99
What it does is limit the /setlevel command to 0-4, right?
|
Yes, it limits the "level" to 0-4. Any invalid level is given, it will return an error message to the player.
Re: Setlevel Command Help -
Miado_Hulk - 27.02.2014
You just need to add a condition "if" to see if the level exceeds 4, if it does, you simply return an error message.
Or you can also use a "While":
While (level < 0 || level > 4)
{
return SendClientMessage(playerid,0x3740B3,"Admin level must be between 0 and 4");
}
Re: Setlevel Command Help -
Konstantinos - 27.02.2014
Quote:
Originally Posted by Miado_Hulk
Or you can also use a "While":
While (level < 0 || level > 4)
{
return SendClientMessage(playerid,0x3740B3,"Admin level must be between 0 and 4");
}
|
What's the point of using while when it's going to be called only once? It could also cause problem if someone forgot to use
return and that would cause an infinite loop. Plus it's
while and not While.
Re: Setlevel Command Help -
Miado_Hulk - 27.02.2014
Quote:
Originally Posted by Konstantinos
What's the point of using while when it's going to be called only once? It could also cause problem if someone forgot to use return and that would cause an infinite loop. Plus it's while and not While.
|
Lol Stop being a smartass, I'm sure he knows how to write the "while" in it's correct form in Pawn.
I gave him the idea. It's not gonna do damage, it's going to keep returning the message as long as he keeps putting the wrong levels.