07.08.2011, 20:14
This is honestly as "clean" as the command can be:
It is pointless to use sscanf for such a simple command. You could also do this with strcmp-based commands, but I find it easier to use ZCMD. Keep in mind, ZCMD is the fastest command processor around if you are going to have under 100 commands. Otherwise, use YCMD.
pawn Код:
#define COLOR_ME 0xFFFFFF // What is the color going to be for the sent message? Currently, it's set to white.
CMD:me(playerid, params[])
{
if(isnull(params)) // Did they enter an action?
return SendClientMessage(playerid, 0xFFFFFF, "SYNTAX: /me [action]");
if(strlen(params) > 124) // Is the action too long (aka. will it fit in a single message)?
return SendClientMessage(playerid, 0xFFFFFF, "SYSTEM: Your /me action is too long.");
new szString[128];
format(szString, sizeof(szString), "* %s %s", GetName(playerid), params); // formatting the string
SendClientMessage(playerid, COLOR_ME, szString);
return 1;
}
stock GetName(playerid) // This function is quite useful.
{
new szName[25];
GetPlayerName(playerid, szName, sizeof(szName));
return szName;
}