[Tutorial] Easy /Ban and /Kick
#1

Hello everybody, this is my first thread here so both good critics and bad are accepted. However, Iґve been working with PAWN for several years. In this topic you will learn how to do a /ban and /kick command easily.

First include this files on top of your script:
Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
Then we can proceed to creating the commands:

The ban command:
Code:
CMD:ban(playerid,params[])
{
new targetid;
if(!sscanf(params, "u", targetid))
{
if(IsPlayerAdmin(playerid)) //Checks if player is RCON. Can also change it to PlayerInfo[playerid][pAdmin]
{
if(IsPlayerConnected(targetid)) //Checks if the player to be banned is connected
{
SendClientMessage(playerid,-1,"SERVER: You have been banned from the server.");//Sends the banned a message
Ban(targetid); //Bans him
}
}
}
return 1;
}
The kick command:
Code:
CMD:kick(playerid,params[])
{
new targetid;
if(!sscanf(params, "u", targetid))
{
if(IsPlayerAdmin(playerid)) //Checks if player is RCON. Can also change it to PlayerInfo[playerid][pAdmin]
{
if(IsPlayerConnected(targetid)) //Checks if the player to be kicked is connected
{
SendClientMessage(playerid,-1,"SERVER: You have been kicked from the server.");//Sends the kicked a message
Kick(targetid); //Kicks him
}
}
}
return 1;
}
Please comment if it didnґt work for you or if you have any request to be added, because iґm more than happy to help you.
Reply
#2

pawn Code:
Ban(targetid); //Kicks him
lolwut ?
Reply
#3

LOL Sorry i confused. Its now fixed to Kick(targetid);
Reply
#4

Change this:

Code:
Kick(targetid); //Kicks him
SendClientMessage(playerid,-1,"SERVER: You have been banned from the server.");//Sends the kicked a message
To this:

Code:
SendClientMessage(targetid,-1,"SERVER: You have been banned from the server.");//Sends the kicked a message
Kick(targetid); //Kicks him
Reply
#5

Change This:
pawn Code:
SendClientMessage(playerid,-1,"SERVER: You have been banned from the server.");//Sends the kicked a message
To This:
pawn Code:
SendClientMessage(playerid,-1,"SERVER: You have been kicked from the server.");//Sends the kicked a message
Reply
#6

LOL Iґm very sorry guys, I did this in a hurry
I edited now
Reply
#7

Every one make mistakes :3
Reply
#8

Quote:
Originally Posted by budelis
View Post
Change this:

Code:
Kick(targetid); //Kicks him
SendClientMessage(playerid,-1,"SERVER: You have been banned from the server.");//Sends the kicked a message
To this:

Code:
SendClientMessage(targetid,-1,"SERVER: You have been banned from the server.");//Sends the kicked a message
Kick(targetid); //Kicks him
or maybe use this.
pawn Code:
new pname[MAX_PLAYER_NAME], str[256];
    new targetid;
    GetPlayerName(targetid, pname, sizeof(pname));
    format(str, sizeof(str), "%s has been kicked from the server", pname);
    SendClientMessageToAll(-1, str);
Reply
#9

Yes, but that would fill up the chat a lot, and if you want a RP for example it wouldnґt be good
But if you donґt care about it or are not making a RP server it would be good too.
@GoldenFox you can use the RCON command for that:
Code:
/rcon unban <ip>
Reply
#10

Quote:
Originally Posted by SAMPHacker
View Post
Change This:
pawn Code:
SendClientMessage(playerid,-1,"SERVER: You have been banned from the server.");//Sends the kicked a message
To This:
pawn Code:
SendClientMessage(playerid,-1,"SERVER: You have been kicked from the server.");//Sends the kicked a message
Whats the difference ?. Its same shit.

If is 'playerid' the message will appear only to admin ...

Change 'playerid' to 'targetid' and then the message will appear to banned player.

And also, you could add and a reason for kick / ban .. /ban [id] [reason] ..

Anyway is more a snippet then a tutorial.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)