How to restrict a player from using a command ?
#1

Hello guys, i got a question... i've nearly finished my Team Wars script but i have problems.... like i can't think of how should i restrict player from using a cmd.... like i'm the admin and i type (restrict player weapons) /rpw [id ] [time] because i have cmds like /getm4, /getak47 and stuff... how should i be able to restrict the player from using this commands or just forbid any weapon posession.
Reply
#2

Using a variable and 'if' statement.

Example:

pawn Код:
CMD:whatever(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF,"ERROR: You are not admin!");  //You can change IsPlayerAdmin to your variable
   //Your codes
   return 1;
}
IsPlayerAdmin is default sa-mp RCON administrator check. This will check if the player is an RCON administrator.
You need to create your own variable to make this, i prefer you should check some of admin scripts on this forums.
Reply
#3

Quote:
Originally Posted by Jarnu
Посмотреть сообщение
Using a variable and 'if' statement.

Example:

pawn Код:
CMD:whatever(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF,"ERROR: You are not admin!");  //You can change IsPlayerAdmin to your variable
   //Your codes
   return 1;
}
IsPlayerAdmin is default sa-mp RCON administrator check. This will check if the player is an RCON administrator.
You need to create your own variable to make this, i prefer you should check some of admin scripts on this forums.
I don't think you red my post... i already have an admin system and know how to do admin only commands... i gotta be able to restrict players when i'm in-game.... please check the post
Reply
#4

Oh sorry never mind i got it.

Create a global variable called anything you want. For example:

pawn Код:
new Restrict; //Your variable
OnFilterScript or OnGameModeInit
pawn Код:
Restrict = 0; //Disabling when the GameMode is loaded.
Now when you type rpw
pawn Код:
CMD:rpw(playerid, params[])
{  
    Restrict = 1;
    return 1;
}
Now the command you want to restrict
pawn Код:
CMD:getm4(playerid, params[])
{
    if(Restrict == 0) //If the restrict is 0 then continue.
    {
          //Your codes
    }
    else return SendClientMessage(playerid, 0xFF0000FF,"ERROR: An administrator has restricted this command!"); //If restrict is 1 .. then breaking the usage of command.
    return 1;
}
It will help you. ^^
Reply
#5

It helped very much man thanks... i was thinking about this too but i was not sure that's why i posted
Reply
#6

@Jarnu,
Код:
CMD:rpw(playerid, params[])
{  
    Restrict = 1;
    return 1;
}
That will disable the commands to the admin, it needs to specify the ID.
Код:
// Global variable
new
    Allowed_To_Use[ MAX_PLAYERS ]
;

public OnPlayerConnect( playerid )
{
    Allowed_To_Use[ playerid ] = 0;
    return 1;
}

public OnPlayerDisconnect( playerid, reason )
{
    Allowed_To_Use[ playerid ] = 0;
    return 1;
}

CMD:rpw( playerid, params[ ] )
{
    new
        id
    ;
    if( sscanf( params, "u", id ) ) return SendClientMessage( playerid, -1, "Syntax: /rpw [ID/Part Of Name]" );
    if( !IsPlayerConnected( id ) && id == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Invalid player ID!" );
    if( Allowed_To_Use[ id ] == 1 ) return SendClientMessage( playerid, -1, "You have already disabled the weapon commands from that player!" );
    Allowed_To_Use[ id ] = 1
    return 1;
}

CMD:getm4( playerid, params[ ] )
{
    if( Allowed_To_Use[ playerid ] == 1 ) return SendClientMessage( playerid, -1, "Weapons commands are disabled for you!" );
    // rest of your code
    return 1;
}
Reply
#7

He wants for everyone i guess. For a specific player your code is correct. and yea, i am incorrect. for everyone there will be a loop.
Reply
#8

He didn't say for everyone as far as I can read correct.
Quote:
Originally Posted by ZackBoolaro
Посмотреть сообщение
[..]/rpw [id ] [time] [..]
If you need to specify the time, you'll need to use 'SetTimerEx'.
Reply
#9

Can help me on the timer also ? I don't know where actually to put it... i also want a msg when the time expires saying something like "Your restriction is over, you can now posess weapons again".
Reply
#10

Nevermind... i fixed it myself i'm requesting a lock now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)