#include <sscanf2>
#include <zcmd>
native BlockIpAddress(ip_address[], timems); // blocks an IP address from further communication (wildcards allowed)
native UnBlockIpAddress(ip_address[]); // IP unblock
// at the top of your script, under includes and defines, add this.
stock GetPlayersName( playerid )
{
// creating a variable to store the player's name in.
new name[ MAX_PLAYER_NAME ];
// getting the player's name and storing it into the variable
GetPlayerName( playerid, name, sizeof( name ) );
return name; // returning the player's name.
}
stock ReturnPlayerIp( playerid )
{
// creating a variable to store the player's IP address in.
new Ip[ 16 ];
// getting the IP address of the player and storing it into the variable.
GetPlayerIp( playerid, Ip, sizeof( Ip ) );
return Ip; // returning the IP address.
}
CMD:ban( playerid, params[ ] )
{
// checking whether the player is an RCON admin or not, if you have your own admin variables/arrays, you can simply replace it.
// if the player isn't logged into the RCON system, it'll send a message saying he can't use this command.
if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, 0xFFFF0000, "Error: You aren't authorized to use this command!" );
// Defining variables for our parameters.
new targetid, reason[ 64 ];
// grabbing the parameters with sscanf, let's go through it step-by-step.
// params --> Checks the parameters of the command that's submitted, if the parameters are empty, it'll send a message on how to use this command.
// targetid and reason are stored into this function to assign the parameters to them, so we can then use those variables later.
// for more documentation on how the sscanf function works, please read: https://github.com/Y-Less/sscanf/wiki
if( sscanf( params, "us[64]", targetid, reason ) ) return SendClientMessage( playerid, 0xFF7100FF, "Usage: /ban [playerid] [reason]" );
// targetid == INVALID_PLAYER_ID --> checks whether the targeted player is an invalid playerid, which means the player either disconnected, or an invalid playerid has been entered.
// playerid == targetid --> checks whether the targeted player isn't the player sending the command, this makes sure you can't ban yourself, remove it if you want to ban yourself :P
if( targetid == INVALID_PLAYER_ID || playerid == targetid ) return SendClientMessage( playerid, 0xFFFF0000, "Error: Invalid playerid." );
// creating a string to store the message in.
new str[ 128 ];
// formatting the message, and sending it to everyone online. for more information on this function please visit the SA-MP wiki.
format( str, sizeof( str ), "%s has banned %s for %s.", GetPlayersName( playerid ), GetPlayersName( targetid ), reason );
SendClientMessageToAll( -1, str );
// Blocks the targeted player's IP from any furthur communication with the server
// for more documentation on this function, please check https://sampwiki.blast.hk/wiki/BlockIpAddress
BlockIpAddress( ReturnPlayerIp( targetid ), 0 );
return 1;
}
CMD:suspend( playerid, params[ ] )
{
// checking whether the player is an RCON admin or not, if you have your own admin variables/arrays, you can simply replace it.
// if the player isn't logged into the RCON system, it'll send a message saying he can't use this command.
if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, 0xFFFF0000, "Error: You aren't authorized to use this command!" );
// Defining variables for our parameters.
new targetid, reason[ 64 ], hours, days;
// grabbing the parameters with sscanf, let's go through it step-by-step.
// params --> Checks the parameters of the command that's submitted, if the parameters are empty, it'll send a message on how to use this command.
// targetid, hours, days and reason are stored into this function to assign the parameters to them, so we can then use those variables later.
// for more documentation on how the sscanf function works, please read: https://github.com/Y-Less/sscanf/wiki
if( sscanf( params, "uiis[64]", targetid, hours, days, reason ) ) return SendClientMessage( playerid, 0xFF7100FF, "Usage: /suspend [playerid] [hours] [days] [reason]" );
// targetid == INVALID_PLAYER_ID --> checks whether the targeted player is an invalid playerid, which means the player either disconnected, or an invalid playerid has been entered.
// playerid == targetid --> checks whether the targeted player isn't the player sending the command, this makes sure you can't ban yourself, remove it if you want to ban yourself :P
if( targetid == INVALID_PLAYER_ID || playerid == targetid ) return SendClientMessage( playerid, 0xFFFF0000, "Error: Invalid playerid." );
// creating a new variable which will convert our hours and days into milliseconds, as the BlockIpAddress uses milliseconds as second parameter.
new total_suspension = ( ( ( ( hours * 60 ) * 60 ) * 1000 ) + ( ( ( ( days * 24 ) * 60 ) * 60 ) * 1000 ) );
// creating a string to store the message in.
new str[ 186 ];
// formatting the message, and sending it to everyone online. for more information on this function please visit the SA-MP wiki.
format( str, sizeof( str ), "%s has suspended %s for %i days and %i hours, reason: %s", ReturnPlayerName( playerid ), ReturnPlayerName( targetid ), days, hours, reason );
SendClientMessageToAll( -1, str );
// Blocks the targeted player's IP from any furthur communication with the server for the given amount of time.
// for more documentation on this function, please check https://sampwiki.blast.hk/wiki/BlockIpAddress
BlockIpAddress( ReturnPlayerIp( targetid ), total_suspension );
return 1;
}
CMD:unban( playerid, params[ ] )
{
// checking whether the player is an RCON admin or not, if you have your own admin variables/arrays, you can simply replace it.
// if the player isn't logged into the RCON system, it'll send a message saying he can't use this command.
if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, 0xFFFF0000, "Error: You aren't authorized to use this command!" );
// Defining a variable for our parameter.
new ip_address[ 16 ];
// grabbing the parameters with sscanf, let's go through it step-by-step.
// params --> Checks the parameters of the command that's submitted, if the parameters are empty, it'll send a message on how to use this command.
// playername will simply store the given playername into our variable, so we can use it later on.
// for more documentation on how the sscanf function works, please read: https://github.com/Y-Less/sscanf/wiki
if( sscanf( params, "s[16]", ip_address ) ) return SendClientMessage( playerid, 0xFF7100FF, "Usage: /unban [ip-address]" );
// creating a string to store the message in.
new str[ 94 ];
// formatting the message, and sending it to everyone online. for more information on this function please visit the SA-MP wiki.
format( str, sizeof( str ), "You've unbanned IP: %s", ip_address );
SendClientMessagel(playerid, -1, str );
UnBlockIpAddress( ip_address );
return 1;
}
|
CMD:unban( playerid, params[ ] ) { // checking whether the player is an RCON admin or not, if you have your own admin variables/arrays, you can simply replace it. // if the player isn't logged into the RCON system, it'll send a message saying he can't use this command. if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, 0xFFFF0000, "Error: You aren't authorized to use this command!" ); // Defining a variable for our parameter. new playername[ 34 ]; // grabbing the parameters with sscanf, let's go through it step-by-step. // params --> Checks the parameters of the command that's submitted, if the parameters are empty, it'll send a message on how to use this command. // playername will simply store the given playername into our variable, so we can use it later on. // for more documentation on how the sscanf function works, please read: https://github.com/Y-Less/sscanf/wiki if( sscanf( params, "s[34]", playername ) ) return SendClientMessage( playerid, 0xFF7100FF, "Usage: /unban [player-name]" ); // creating a string to store the message in. new str[ 94 ]; // formatting the message, and sending it to everyone online. for more information on this function please visit the SA-MP wiki. format( str, sizeof( str ), "\"%s\" been unbanned from the server!", playername ); SendClientMessageToAll( -1, str ); return 1; } |

if( targetid == INVALID_PLAYER_ID || playerid == targetid ) return SendMessage( playerid, 0xFFFF0000, "Error: Invalid playerid." );
if( targetid == INVALID_PLAYER_ID || playerid == targetid ) return SendClientMessage( playerid, 0xFFFF0000, "Error: Invalid playerid." );