SA-MP Forums Archive
[Tutorial] Kick/Ban command using SSCANF and YCMD - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Kick/Ban command using SSCANF and YCMD (/showthread.php?tid=376506)



Kick/Ban command using SSCANF and YCMD - Dare Devil..... - 10.09.2012

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.