[Tutorial] Kick/Ban command using SSCANF and YCMD
#1

Hello today i will show you how to make a /ban and /kick command for your samp server.

Lets begin,

First of all you need to make variables at the top of the script,like this.
pawn Code:
new player;//The target ID which is going to be banned or kicked.
new reason[126]; //the Reason for which the player is going to be kicked.
new string[126];//String
Now you need to start with the command so i will prefer using YCMD and I will show the code in YCMD.
pawn Code:
YCMD:kick(playerid, params[])
{
        if(sscanf(params, "us[126]", player, reason)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /kick [Part of Name/Player ID] [Reason]");//This will check that a player has typed ID and reason if he has given that this will kick other wise this message will show up.

        if(!IsPlayerConnected(player)) return SendClientMessage(playerid, COLOR_WHITE, "Player is not connected.");//Once its checked the id is there this will check that weather the ID is valid or not.
       
             format(string, sizeof(string), "[ADMCMD]: %s has been kicked by %s, reason: %s", PlayerName(player), PlayerName(playerid), reason);//This will make up the reason for the player being kicked.
        SendClientMessageToAll(COLOR_LIGHTRED, string);//This will send client message to all if you can remove this if you dont want message to be sent to all.
        Kick(player);//This will finnally kick the player.
}
The ban Command is almost similar just you have to change the client message and [pawn]Kick(player); to Ban(player); and else all the functions are same.

I hope I helped some one,Let me know if I did a mistaqe somewhere instead of making fun thankyou.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)