18.10.2010, 10:54
I use this
in cmd make
than put this in place where you usual use strtok to get some value etc
EDIT: whole cmd
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
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;
}
pawn Код:
new text[256];
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;
}