I need a reason
#6

Introducing the String Tokenise method!

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Put that badboy in your script and you will be able to use it in your /kick command as such:

pawn Код:
new cmd[128]; new idx;
cmd = strtok(cmdtext, idx);
    if(strcmp("/kick", cmd, true) == 0)
    {
        if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "RCON needed.");
        idx++; cmd = strtok(cmdtext, idx);
        if(!strlen(cmd)) return SendClientMessage(playerid, 0xFF0000AA, "Use: /kick [PLAYERID] [REASON]");
        new gp = strval(cmd);
        if(!IsPlayerConnected(gp)) return SendClientMessage(playerid, 0xFF0000AA, "Invalid Playerid");
        idx++; cmd = strtok(cmdtext, idx);
        if(!strlen(cmd)) return SendClientMessage(playerid, 0xFF0000AA, "Use: /kick [playerid] [REASON]");
        new reason[128];
        while(strlen(cmd)) {
            strcat(reason, cmd, sizeof(reason));
            strcat(reason, " ", sizeof (reason));
            idx++; cmd = strtok(cmdtext, idx);
        }
        strdel(reason, strlen(reason)-1, strlen(reason));
        new pn[24], an[24], str[70];
        GetPlayerName(playerid, an, 24); GetPlayerName(gp, pn, 24);
        format(str, sizeof(str), "%s kicked by admin %s (reason: %s)", pn, an, reason);
        SendClientMessageToAll(0xA9A9A9AA, str);
        Kick(gp);
        return 1;
    }
The strtok method is commonly used along with strcmp. For an explanation on how it method works, visit the wiki page here: https://sampwiki.blast.hk/wiki/Strtok
Reply


Messages In This Thread
I need a reason - by CSMajor - 13.12.2010, 00:34
Re: I need a reason - by Lynn - 13.12.2010, 01:14
Re: I need a reason - by CSMajor - 13.12.2010, 21:18
Re: I need a reason - by notime - 13.12.2010, 21:47
Re: I need a reason - by Lynn - 13.12.2010, 21:53
Re: I need a reason - by Benjo - 13.12.2010, 21:59
Re: I need a reason - by CSMajor - 14.12.2010, 00:18
Re: I need a reason - by XePloiT - 14.12.2010, 01:13
Re: I need a reason - by Steven82 - 14.12.2010, 01:15
Re: I need a reason - by [L3th4l] - 14.12.2010, 01:31

Forum Jump:


Users browsing this thread: 1 Guest(s)