Small Coding Help
#9

This is honestly as "clean" as the command can be:

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;
}
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.
Reply


Messages In This Thread
Small Coding Help - by meD maN - 07.08.2011, 18:40
Re: Small Coding Help - by Backwardsman97 - 07.08.2011, 18:44
Re: Small Coding Help - by Kingunit - 07.08.2011, 18:48
Re: Small Coding Help - by Cypress - 07.08.2011, 19:45
Re: Small Coding Help - by Vince - 07.08.2011, 20:01
Re: Small Coding Help - by AndreT - 07.08.2011, 20:06
Re: Small Coding Help - by Cypress - 07.08.2011, 20:12
Re: Small Coding Help - by Sasino97 - 07.08.2011, 20:14
Re: Small Coding Help - by Scenario - 07.08.2011, 20:14
Re: Small Coding Help - by meD maN - 07.08.2011, 22:33

Forum Jump:


Users browsing this thread: 4 Guest(s)