Kick Message.
#1

Hi Niggas,I have made /kick command it's working but i dont know how to give a kick message when a player gets kick.I want the message will be given to all other players,Please help me
This is my code:
CMD:kick(playerid,params[])
{
new TargetID,Reason[200];
if(sscanf(params, "u", TargetID))
{
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /kick (Name/Id) (Reason).");
return 1;
}
sscanf(params, "us[200]", TargetID, Reason);
if(!IsPlayerConnected(TargetID) || TargetID == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "That Player Is Not Connected.");
return 1;
}
if(IsPlayerNPC(TargetID))
{
SendClientMessage(playerid,COLOR_ERROR,"You Cannot Kick a BOT.");
return 1;
}
if(!strlen(Reason))
{
Reason = "No Reason Given.";
}
Kick(TargetID);
return 1;
}
Reply
#2

Код:
CMD:kick(playerid,params[])
{
new TargetID,Reason[200];
if(sscanf(params, "u", TargetID))
{
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /kick (Name/Id) (Reason).");
return 1;
}
sscanf(params, "us[200]", TargetID, Reason);
if(!IsPlayerConnected(TargetID) || TargetID == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "That Player Is Not Connected.");
return 1;
}
if(IsPlayerNPC(TargetID))
{
SendClientMessage(playerid,COLOR_ERROR,"You Cannot Kick a BOT.");
return 1;
}
if(!strlen(Reason))
{
Reason = "No Reason Given.";
}
SendClientMessageToAll(COLOR_RED/*idk what color*/," %s has been kicked from the server by %s,  reason: %s", GetPlayerName(TargetID),GetPlayerName(playerid), Reason);
Kick(TargetID);
return 1;
}
Reply
#3

You need to put this on your kick command

PHP код:
    SendClientMessageToAll(COLOR_HEREYOURMESSEGE); 
Reply
#4

If you want the kicked player to be able to see the message, you need to use a timer of about 100 milliseconds that kicks him.
Reply
#5

I have tested it but it shut'sdown the server! Anyways i will test the timer.
Reply
#6

CMD:kick(playerid,params[])
{
new TargetID,Reason[200];
if(sscanf(params, "u", TargetID))
{
SendClientMessage(playerid, COLOR_ERROR, "USAGE: /kick (Name/Id) (Reason).");
return 1;
}
sscanf(params, "us[200]", TargetID, Reason);
if(!IsPlayerConnected(TargetID) || TargetID == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "That Player Is Not Connected.");
return 1;
}
if(IsPlayerNPC(TargetID))
{
SendClientMessage(playerid,COLOR_ERROR,"You Cannot Kick a BOT.");
return 1;
}
if(!strlen(Reason))
{
Reason = "No Reason Given.";
}
SetTimer ("Kick message",100,False);//Is it ok?
Kick(TargetID);
return 1;
}
Reply
#7

No, write it like this:

PHP код:
CMD:kick(playerid,params[])
{
    new 
TargetID,Reason[145];
    if(
sscanf(params"uS(No reason)[144]"TargetIDReason)) return SendClientMessage(playeridCOLOR_ERROR"USAGE: /kick (Name/Id) (Reason).");
    if(!
IsPlayerConnected(TargetID)) return SendClientMessage(playeridCOLOR_ERROR"That Player Is Not Connected.");
    if(
IsPlayerNPC(TargetID)) return SendClientMessage(playerid,COLOR_ERROR,"You Cannot Kick a BOT.");
    if(!
Reason[0]) return SendClientMessage(playerid,COLOR_ERROR,"No Reason Given.");
    
format(Reason,sizeof Reason,"* %s kicked %s for %s!",GetName(playerid),GetName(TargetID),Reason);
    
SendClientMessageToAll(-1,Reason);
    
SetTimerEx("@Kick",100,0,"i",TargetID);
    return 
1;
}
@
Kick(i);@Kick(i) return Kick(i);
//If you dont have it:
stock GetName(playerid) {
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    return 
name;

Greekz
Reply
#8

No, you have to time the kick, and send the message immediately in your cmd.
Reply
#9

Keep in mind that if the reason is not given, it'll keep giving the usage message so you've to use optional string in sscanf.

PHP код:
new
    
ID,
    
Reason[64];
if (
ssacnf(params"rS(No reason)[64]"IDReason)) return .. // usage message.. 
and just format it normally, it'll either show the reason you input or "No reason" if it was empty.

By the way, use a timer to delay the kick only if you want the player who is about to get kicked to see the message. If the message is shown to the rest of the players only, you don't need it.
Reply
#10

Ok Thanks,I will chect it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)