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