Is there a way if player is admin to disable player command ?
#1

If player is admin is there a way to dizable command and player cant use that command ?
Reply
#2

Yes, using variables.
Reply
#3

Yes, you can.
pawn Код:
new
    bool: Disabled_Command[ MAX_PLAYERS ]
;

// OnPlayerConnect
Disabled_Command[ playerid ] = false;

// command to disable (an example)
CMD:disablecmd( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not admin" );
    new
        id
    ;
    if( sscanf( params, "r", id ) ) return SendClientMessage( playerid, -1, "Usage: /disablecmd <ID/Part Of Name>" );
    if( id == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Offline player" );
    if( Disabled_Command[ id ] ) return SendClientMessage( playerid, -1, "The commands are disabled for that player already!" );
   
    Disabled_Command[ id ] = true;
    return 1;
}

// command to enable (an example)
CMD:enablecmd( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not admin" );
    new
        id
    ;
    if( sscanf( params, "r", id ) ) return SendClientMessage( playerid, -1, "Usage: /enablecmd <ID/Part Of Name>" );
    if( id == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Offline player" );
    if( !Disabled_Command[ id ] ) return SendClientMessage( playerid, -1, "The commands are enabled for that player already!" );

    Disabled_Command[ id ] = false;
    return 1;
}

// On some commands you want to disable (an example):
CMD:heal( playerid, params[ ] )
{
    if( Disabled_Command[ playerid ] ) return SendClientMessage( playerid, -1, "That command is blocked" );
    SetPlayerHealth( playerid, 100.0 );
    return 1;
}
Reply
#4

Konstantinos i want to disable any command for ALL players !Not for one player
Reply
#5

Then change the 2 commands to:
pawn Код:
// command to disable (an example)
CMD:disablecmd( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not admin" );
   
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( !IsPlayerConnected( i ) || IsPlayerNPC( i ) ) continue;
        Disabled_Command[ i ] = true;
    }
    return 1;
}

// command to enable (an example)
CMD:enablecmd( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not admin" );
   
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( !IsPlayerConnected( i ) || IsPlayerNPC( i ) ) continue;
        Disabled_Command[ i ] = false;
    }
    return 1;
}
It loops throught the online players and it sets the variable to enabled/disabled.
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Then change the 2 commands to:
pawn Код:
// command to disable (an example)
CMD:disablecmd( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not admin" );
   
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( !IsPlayerConnected( i ) || IsPlayerNPC( i ) ) continue;
        Disabled_Command[ i ] = true;
    }
    return 1;
}

// command to enable (an example)
CMD:enablecmd( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "You are not admin" );
   
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( !IsPlayerConnected( i ) || IsPlayerNPC( i ) ) continue;
        Disabled_Command[ i ] = false;
    }
    return 1;
}
It loops throught the online players and it sets the variable to enabled/disabled.

You don't really have to take care of NPC's, do you? Unless it is needed to.
Reply
#7

Quote:
Originally Posted by Cypress
Посмотреть сообщение
You don't really have to take care of NPC's, do you? Unless it is needed to.
No, it's optional.
Reply
#8

I want to disable only one command, not all !
Reply
#9

It does not block all the commands. To the command you want to block, just add:
pawn Код:
if( Disabled_Command[ playerid ] ) return SendClientMessage( playerid, -1, "That command is blocked" );
An example would be: let's say you want to block /heal command if you've disabled it for all the players.
pawn Код:
// On some commands you want to disable (an example):
CMD:heal( playerid, params[ ] )
{
    if( Disabled_Command[ playerid ] ) return SendClientMessage( playerid, -1, "That command is blocked" );
    SetPlayerHealth( playerid, 100.0 );
    return 1;
}
Reply
#10

pawn Код:
CMD:hi(playerid, params[])
{
    if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Admins cannot use this command."); //This checks if they're logged in as RCON Admin, change it to what you use
    SendClientMessage(playerid, -1, "Hello");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)