How to make this command shorter
#1

Okay, I am developing my new admin script, this is the /kick command I have come up with:

Код:
if(strcmp(cmd,"/kick",true) == 0)
{
new tmp[256];
tmp = strtok(cmdtext, idx);
new id;
tmp = strtok(cmdtext, idx);

if(PlayerInfo[playerid][Level] <= 3)
{
    SendClientMessage(playerid,RED,"You have to be Level 4 to use this command!");
	return 1;
}
if(Logged[playerid] == 0)
{
	SendClientMessage(playerid,BRIGHTRED,"Please login before you use this command!");
	return 1;
}
if(!strlen(tmp))
{
	SendClientMessage(playerid,WHITE,"Usage: /kick [id] [reason]");
	return 1;
}
id = strval(tmp);
if(IsPlayerConnected(id))
{
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
	SendClientMessage(playerid,RED, "SERVER: /kick [id] [reason]");
}
else
{
	tmp = strtok(cmdtext, idx);
	new string[128];
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	new nname[MAX_PLAYER_NAME];
	GetPlayerName(id,nname,sizeof(nname));
	format(string,sizeof(string)," * You have kicked %s Reason: %s",nname,result);
	SendClientMessage(playerid,YELLOW,string);
	format(string,sizeof(string)," * you have been kicked by %s Reason: %s ",name,result);
	SendClientMessage(id,BRIGHTRED,string);
	format(string,sizeof(string)," * %s has been kicked by %s. Reason: %s *",nname,name,result);
	SendClientMessageToAll(BRIGHTRED,string);
	}
return 1;
}
}
as you can see it is fairly long, It works okay but I want it shorter. What could I do to make this code as short as possible?
Reply
#2

zcmd and sscanf, enough said
Reply
#3

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
zcmd and sscanf, enough said
Agreed.

(Its much better, faster, shorter)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)