About Kick(playerid)
#1

Hi, I have a simple question about the Kick(playerid).
I made this function:
Код:
stock KickPlayer(playerid, kickedby, reason[])
{
	new string[256];
	format(string, sizeof(string), "You've been kicked by %s. Reason: %s\n", GetName(playerid), reason);
	SendClientMessage(kickedby, COLOR_RED, string);
	return Kick(kickedby);
}
and I called this function on some OnPlayerCommandText code.
Why when I use the function I can't see the SendCliendMessage? It displays just the "Server close the connection." message, why? How can I fix that?
Reply
#2

You have to use a timer to kick the player out, it's one of the SA-MP's bugs.
Reply
#3

Most likely you're being kicked before the message is sent, you can fix that by using a timer to actually Kick the player (SetTimerEx) with a delay of a second or so.

EDIT: ninja'd
Reply
#4

Use a timer.
pawn Код:
stock KickPlayer(playerid, kickedby, reason[])
{
    new string[256];
    format(string, sizeof(string), "You've been kicked by %s. Reason: %s\n", GetName(playerid), reason);
    SendClientMessage(kickedby, COLOR_RED, string);
    return SetTimerEx("Kick", 5000, false, "i",kickedby);
}
Reply
#5

Ok, thanks! I tried with a delay of a 1 sec. Another question: the timer delay can be shorter than 1 second?
Reply
#6

Well, why would you make a timer that's less than 1 second? What's the purpose of this?
Reply
#7

Just to make the kick faster.
Reply
#8

1. Took me only 15 minutes to figure out what you did ...whay?... in your code var. "kickedby" - is the person you trying to kick... when i read "kickedby" i think is the admin not the player...
2. I hope that when you test the function alone "responsiblePlayer & kickedPlayer" they will have the same id (responsiblePlayer == kickedPlayer)

Код:
/*
 * KickPlayer
 * responsiblePlayer	The player that is responsible for the event
 * kickedPlayer		The player that will be kicked from the server
 * reason		The reason for the kick
 */
stock KickPlayer(responsiblePlayer, kickedPlayer, reason[])
{
	new string[256];
	format(string, sizeof(string), "You've been kicked by %s. Reason: %s\n", GetName(responsiblePlayer), reason);
	SendClientMessage(kickedPlayer, COLOR_RED, string);
	
	return Kick(kickedPlayer);
}
Reply
#9

Quote:
Originally Posted by Gilmar
Посмотреть сообщение
Ok, thanks! I tried with a delay of a 1 sec. Another question: the timer delay can be shorter than 1 second?
Yeah, it can. 300ms is enough if I'm not remembering wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)