Kick
From SA-MP Wiki
Description:
Kicks a player from the server. They will have to quit the game and re-connect if they wish to continue playing.
(playerid)
playerid | The ID of the player to kick. |
Return Values:
This function always returns 1, even if the function failed to execute (player specified doesn't exist).
Example Usage:
public OnPlayerCommandText(playerid, cmdtext[]) { if(strcmp(cmdtext, "/kickme", true) == 0) { // Kicks the player who executed this command Kick(playerid); return 1; } return 0; }
Important | As of SA-MP 0.3x, any action taken directly before Kick() (such as sending a message with SendClientMessage) will not reach the player. A timer must be used to delay the kick. |
The following code snippet shows a way of displaying a message for the player before they are kicked:
// In order to display a message (eg. reason) for the player before the connection is closed // you have to use a timer to create a delay. This delay only needs to be a few milliseconds long, // but this example uses a full second just to be on the safe side. public OnPlayerCommandText(playerid, cmdtext[]) { if(strcmp(cmdtext, "/kickme", true) == 0) { // Kick the player who executed this command. // First, send them a message. SendClientMessage(playerid, 0xFF0000FF, "You have been kicked!"); // Actually kick them a second later on a timer. SetTimerEx("DelayedKick", 1000, false, "i", playerid); return 1; } return 0; } forward DelayedKick(playerid); public DelayedKick(playerid) { Kick(playerid); return 1; }
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.