Kick command.
#1

I have this command:

Код:
CMD:kick(playerid, params[])
{
	new pid, reason[256], str[256], query[256];
	new year, month, day, hour, mins, data[256];
	if(!CheckAdmin(playerid, 1)) return NotAuthMSG(playerid);
	if(sscanf(params,"ds[256]",pid,reason)) return SyntaxMSG(playerid, "/kick [playerid] [reason]");
	if(!IsPlayerConnected(pid)) return SCM(playerid, COLOR_GREY,"Invalid player id");
	getdate(year, month, day);
	gettime(hour, mins);
	format(data, sizeof(data), "%d-%d-%d | %d:%d", day, month, year, hour, mins);
	format(query, sizeof(query), "INSERT INTO `kicks` (player, victim, reason, data) VALUES ('%s', '%s', '%s', '%s')", GetName(playerid), GetName(pid), reason, data);
	mysql_function_query(dbHandle, query, true, "", "");
	format(str, sizeof(str), "AdmCmd: %s was kicked by %s, reason: %s", GetName(pid), GetName(playerid), reason);
	SendClientMessageToAll(COLOR_LIGHTRED,str);
	Kick(pid);
	return 1;
}
it doesn't show the message to the kicked player... only kicks him
and it shows for other people.
Reply
#2

//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, message[])
{
SendClientMessage(playerid, 0xFF4444FF, 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, "You have been kicked.");
return 1;
}
return 0;
}
//by Kye
Reply
#3

pawn Код:
CMD:kick(playerid, params[])
{
    new pid, reason[256], str[256], query[256];
    new year, month, day, hour, mins, data[256];
    if(!CheckAdmin(playerid, 1)) return NotAuthMSG(playerid);
    if(sscanf(params,"ds[256]",pid,reason)) return SyntaxMSG(playerid, "/kick [playerid] [reason]");
    if(!IsPlayerConnected(pid)) return SCM(playerid, COLOR_GREY,"Invalid player id");
    getdate(year, month, day);
    gettime(hour, mins);
    format(data, sizeof(data), "%d-%d-%d | %d:%d", day, month, year, hour, mins);
    format(query, sizeof(query), "INSERT INTO `kicks` (player, victim, reason, data) VALUES ('%s', '%s', '%s', '%s')", GetName(playerid), GetName(pid), reason, data);
    mysql_function_query(dbHandle, query, true, "", "");
    format(str, sizeof(str), "AdmCmd: %s was kicked by %s, reason: %s", GetName(pid), GetName(playerid), reason);
    SendClientMessageToAll(COLOR_LIGHTRED,str);
    SendClientMessage(pid, COLOR_LIGHTRED, "You have been kicked");
    Kick(pid);
    return 1;
}
Reply
#4

Quote:
Originally Posted by BlackRaven
Посмотреть сообщение
pawn Код:
CMD:kick(playerid, params[])
{
    new pid, reason[256], str[256], query[256];
    new year, month, day, hour, mins, data[256];
    if(!CheckAdmin(playerid, 1)) return NotAuthMSG(playerid);
    if(sscanf(params,"ds[256]",pid,reason)) return SyntaxMSG(playerid, "/kick [playerid] [reason]");
    if(!IsPlayerConnected(pid)) return SCM(playerid, COLOR_GREY,"Invalid player id");
    getdate(year, month, day);
    gettime(hour, mins);
    format(data, sizeof(data), "%d-%d-%d | %d:%d", day, month, year, hour, mins);
    format(query, sizeof(query), "INSERT INTO `kicks` (player, victim, reason, data) VALUES ('%s', '%s', '%s', '%s')", GetName(playerid), GetName(pid), reason, data);
    mysql_function_query(dbHandle, query, true, "", "");
    format(str, sizeof(str), "AdmCmd: %s was kicked by %s, reason: %s", GetName(pid), GetName(playerid), reason);
    SendClientMessageToAll(COLOR_LIGHTRED,str);
    SendClientMessage(pid, COLOR_LIGHTRED, "You have been kicked");
    Kick(pid);
    return 1;
}
That is wrong. Please read 0.3X topic for more info. You have to use the kick function after a delay, since kick intervenes and stops any 'packets' being sent. - Kalcor.
Reply
#5

thanks it works, I changed the delay to 100.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)