How to make this command shorter - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to make this command shorter (
/showthread.php?tid=169429)
How to make this command shorter -
mrcoolballs - 19.08.2010
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?
Re: How to make this command shorter -
FUNExtreme - 19.08.2010
zcmd and sscanf, enough said
Re: How to make this command shorter -
playbox12 - 19.08.2010
Quote:
Originally Posted by FUNExtreme
zcmd and sscanf, enough said
|
Agreed.
(Its much better, faster, shorter)