Need a little help with kick command
#1

How can i add a reason why was player kicked to this command, example: Admin Matej kicked John for weapon hax.

pawn Код:
dcmd_kick(playerid,params[])
{
    new id,n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
    new tmp[256], Index, str[49];
    tmp = strtok(params,Index), id = strval(tmp);
    GetPlayerName(id,on,sizeof(on));
    GetPlayerName(playerid,n,sizeof(n));
    if(PInfo[playerid][Level] < 3) return SendClientMessage(playerid,ORANGE,"You need to be level 3 to use this command!");
    if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /kick <ID> ");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,GREY,"Invalid ID");
    format(str,sizeof(str),"Administrator %s has kicked %s",n,on);
    SendClientMessageToAll(0xFF0000FF,str);
    Kick(id);
    return 1;
}
Reply
#2

I use this
pawn Код:
stock GetStringText(const string[],idx,text[256])
{
    new length = strlen(string);
    while ((idx < length) && (string[idx] <= ' ')) { idx++; }
    new offset = idx; new result[256];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))) { result[idx - offset] = string[idx]; idx++; }
    result[idx - offset] = EOS;
    text = result;
    return result;
}
in cmd make
pawn Код:
new text[256];
than put this in place where you usual use strtok to get some value etc
pawn Код:
GetStringText(params,idx,text);

EDIT: whole cmd
pawn Код:
dcmd_kick(playerid,params[])
{
    new n[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
    new tmp[32], Index, string[128];
    tmp = strtok(params,Index);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid,GREY,"USAGE: /kick <ID> [reason]"); return 1;
    }
    new id = strval(tmp);
    if(PInfo[playerid][Level] < 3)
    {
        SendClientMessage(playerid,ORANGE,"You need to be level 3 to use this command!"); return 1;
    }
    if(IsPlayerConnected(id))
    {
        GetPlayerName(id,on,sizeof(on));
        GetPlayerName(playerid,n,sizeof(n));
        new text[256];
        GetStringText(params,Index,text);
        if(!strlen(text))
        {
            SendClientMessage(playerid,GREY,"USAGE: /kick <ID> [reason]"); return 1;
        }
        format(string,sizeof(string),"Administrator %s has kicked %s Reason: %s",n,on,text);
        SendClientMessageToAll(0xFF0000FF,string);
        Kick(id);
        return 1;
    }
    else
    {
        SendClientMessage(playerid,GREY,"Invalid ID");
    }
    return 1;
}
check things like, you get player name before you check if he is connected, its BIG mistake, also you dont need to check if params is strlen, but you need to check if its strlen(tmp), compare whole cmd to yours, to see how you need to make something in future
Reply
#3

Thanks Voldemort, the command is working perfectly
Reply
#4

Sorry for the double post, but if i kick/ban myself i can go back in the server and play.
Reply
#5

Код:
if(playerid == id)
{
      return SendClientMessage(playerid, RED, "You can't kick/ban yourself.");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)