Kick

From SA-MP Wiki

Jump to: navigation, search


This function can be used to kick a player who currently is in your server.


Parameters:
(playerid)
playeridThe ID of the player you want to kick.
ReturnsThis function doesn't return a specific value


public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/kickme", true) == 0)
    {
        //Kicks the player who the executed this command
        Kick(playerid);
        return 1;
    }
    return 0;
}


Image:32px-Circle-style-warning.png Important Note: As of SA-MP 0.3x, any message sent to the player with SendClientMessage before Kick() will not be displayed for them.


The following code snippet shows a way of displaying a message for the player before he is being kicked:

//In order to display a message (eg. reason) for the player before the connection is closed you have to use a delay:
 
forward KickPublic(playerid);
public KickPublic(playerid) { Kick(playerid); }
 
stock KickWithMessage(playerid, color, message[])
{
    SendClientMessage(playerid, color, message);
    SetTimerEx("KickPublic", 1000, 0, "d", playerid); 	//Delay of 1 second before kicking the player so he recieves the message
}
 
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/kickme", true) == 0)
    {
        //Kicks the player who the executed this command
        KickWithMessage(playerid, 0xFF0000FF, "You have been kicked.");
        return 1;
    }
    return 0;
}
//by Kye

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

  • Ban: Ban a player from playing on the server.
  • BanEx: Ban a player with a custom reason.
Personal tools