Help with /kick
#1

Hi everyone

I am having some problems with my /kick command

What happens is when I type /kick 0 It kicks the player but without a reason
The next problem is when I type a ID in when the player isn't connected it shows I kicked someone but without a name and a reason.

Here is the code:
pawn Код:
CMD:kick(playerid,params[])
{
    new nub, str[128], reason[128], an[MAX_PLAYER_NAME], nub1[MAX_PLAYER_NAME];
    if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be an RCON to use this command!");
    if(!IsPlayerConnected(nub)) return SCM(playerid, COLOR_RED, "ERROR: That player isn't connected!");
    if(sscanf(params,"is", nub)) return SCM(playerid, COLOR_RED, "USAGE: /kick <playerid> <reason>");
    GPN(playerid, an, MAX_PLAYER_NAME);
    GPN(nub, nub1, MAX_PLAYER_NAME);
    FT(str, sizeof(str), "[KICK]:%s has kicked %s! Reason: %s", an, nub1, reason);
    SCMTA(COLOR_RED, str);
    Kick(nub);
    return 1;
}
I changed the sscanf params to "ud" but still doesn't work.

Thank you
Reply
#2

if(sscanf(params,"is", nub)) return SCM(playerid, COLOR_RED, "USAGE: /kick <playerid> <reason>");
It needs to be
pawn Код:
if(sscanf(params,"us[128]", nub, reason)) return SCM(playerid, COLOR_RED, "USAGE: /kick <playerid> <reason>");
u = Player's ID(nub)
s[128] = String(reason)
Reply
#3

I recommend you to make the reason smaller, you don't need 128 characters and if it is that big, it won't fit in the "str" string.
pawn Код:
CMD:kick(playerid, params[])
{
    new nub, str[128], reason[128], an[MAX_PLAYER_NAME], nub1[MAX_PLAYER_NAME];
    if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be an RCON to use this command!");
    if(sscanf(params,"is[128]", nub, reason)) return SCM(playerid, COLOR_RED, "USAGE: /kick <playerid> <reason>");
    //you might want to make sure that "nub" is between 0 and 999 [ if(nub < 0 || nub > 999) return SCM(playerid, COLOR_RED, "error"); ]
    if(!IsPlayerConnected(nub)) return SCM(playerid, COLOR_RED, "ERROR: That player isn't connected!");
    GPN(playerid, an, MAX_PLAYER_NAME);
    GPN(nub, nub1, MAX_PLAYER_NAME);
    FT(str, sizeof(str), "[KICK]:%s has kicked %s! Reason: %s", an, nub1, reason);
    SCMTA(COLOR_RED, str);
    Kick(nub);
    return 1;
}
Reply
#4

You need to put the kick function into a timer of e.g. 1000ms so the kicked player gets the message, otherwise they won't know why they were kicked.
Reply
#5

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
I recommend you to make the reason smaller, you don't need 128 characters and if it is that big, it won't fit in the "str" string.
pawn Код:
CMD:kick(playerid, params[])
{
    new nub, str[128], reason[128], an[MAX_PLAYER_NAME], nub1[MAX_PLAYER_NAME];
    if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_RED, "ERROR: You must be an RCON to use this command!");
    if(sscanf(params,"is[128]", nub, reason)) return SCM(playerid, COLOR_RED, "USAGE: /kick <playerid> <reason>");
    //you might want to make sure that "nub" is between 0 and 999 [ if(nub < 0 || nub > 999) return SCM(playerid, COLOR_RED, "error"); ]
    if(!IsPlayerConnected(nub)) return SCM(playerid, COLOR_RED, "ERROR: That player isn't connected!");
    GPN(playerid, an, MAX_PLAYER_NAME);
    GPN(nub, nub1, MAX_PLAYER_NAME);
    FT(str, sizeof(str), "[KICK]:%s has kicked %s! Reason: %s", an, nub1, reason);
    SCMTA(COLOR_RED, str);
    Kick(nub);
    return 1;
}
Thank you very much

Your one worked!
Thanks again
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)