Need a little help with kick command
#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


Messages In This Thread
Need a little help with kick command - by Matej_ - 18.10.2010, 10:10
Re: Need a little help with kick command - by Voldemort - 18.10.2010, 10:54
Re: Need a little help with kick command - by Matej_ - 18.10.2010, 11:23
Re: Need a little help with kick command - by Matej_ - 18.10.2010, 11:31
Re: Need a little help with kick command - by Ironboy500[TW] - 18.10.2010, 12:27

Forum Jump:


Users browsing this thread: 1 Guest(s)