Small Coding Help
#1

Hi, I'm new to coding on SAMP and PAWNO and I was wondering if somebody could help me code a "Clean" /me and /do command for an RP server I'm making.

I want the Commands to be kindof like this:

"/meeeeee" --> "Unknown Command"
"/melolol" --> "Unkown Command"
"/me" --> "USAGE: /me [MESSAGE]"
"/me logs onto his PC" --> "Mr.Mister logs onto his PC"

Instead of:

"/meeeeee" --> "Mr.Mister eeeeee"
"/melol" --> "Mr.Mister lolol"
"/me" --> "Mr.Mister"
"/me logs onto his PC" --> "Mr.Mister logs onto his PC"

And the same Concept for the /do Command.
Any help would be Appreciated! Thank you.
Reply
#2

Show the command.
Reply
#3

Use SCANF
Reply
#4

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
Use SCANF
It's sscanf.

Without sscanf:

pawn Код:
dcmd_me(const playerid, message[])
{
  if (!strlen(message)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /me [message]");
  new pnames[ MAX_PLAYER_NAME ], string[ 128 ];
  GetPlayerName( playerid, pnames, sizeof( pnames ));
  format(string, sizeof(string), "* %s %s", pnames, message );
  SendClientMessageToAll( COLOR_PINK, string );
  return 1;
}
with sscanf:
pawn Код:
dcmd_me(const playerid, message[])
{
  if(sscanf(params, "u[128]",params[0]))return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /me [message]");
  new pnames[MAX_PLAYER_NAME], string[128];
  GetPlayerName(playerid, pnames, sizeof(pnames));
  format(string, sizeof(string), "* %s %s", pnames, params[0]);
  SendClientMessageToAll(COLOR_PINK, string);
  return 1;
}
Reply
#5

pawn Код:
if(sscanf(params, "u[128]",params[0]))
What is that supposed to mean? A /me command is like the easiest thing to make and you don't even need sscanf for that if you're using DCMD/ZCMD.

pawn Код:
dcmd_me(playerid, params[])
{
  if(isnull(params)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /me [message]");
  new pnames[MAX_PLAYER_NAME], string[128];
  GetPlayerName(playerid, pnames, sizeof(pnames));
  format(string, sizeof(string), "* %s %s", pnames, params);
  SendClientMessageToAll(COLOR_PINK, string);
  return 1;
}
Reply
#6

I just have to jump in and mention that DCMD is not the best method anymore. It still uses string comparing while ZCMD tries to call for the function, which is way better when it comes to having more than just a few commands.
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
if(sscanf(params, "u[128]",params[0]))
What is that supposed to mean? A /me command is like the easiest thing to make and you don't even need sscanf for that if you're using DCMD/ZCMD.

pawn Код:
dcmd_me(playerid, params[])
{
  if(isnull(params)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /me [message]");
  new pnames[MAX_PLAYER_NAME], string[128];
  GetPlayerName(playerid, pnames, sizeof(pnames));
  format(string, sizeof(string), "* %s %s", pnames, params);
  SendClientMessageToAll(COLOR_PINK, string);
  return 1;
}

True. I found that around on so don't mind.
Reply
#8

strtok extacts word by word from a string. You could use it. It's in a lot of scripts, but the official version is with the PAWN package (http://www.compuphase.com/pawn).
Reply
#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
#10

I just want the command to be 'secure' and not to mix in with any other commands that start with '/me' and for it to also be compiled easily. Plus I'd like to know how to do it for other Commands like Text Messages, and please also explain me how you done this and how I can do this. Thanks

Code:
Quote:

#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;
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)