Macro SendFormatMessage, SendFormattedMessage, FormatMessage, or whatever
#1

I see lots of people making complex defines like
pawn Код:
#define SendFormat(%0,%1,%2,%3) do{new str[128];format(_str,128,%2,%3);SendClientMessage(%0,%1,_str);}while(FALSE)
not to write
pawn Код:
new string[128];
format(string, sizeof(string), "grdgr %d rgsrg", integer);
SendClientMessage(playerid, COLOR, string);
But why don't just do:
pawn Код:
#define FormatMsg(%0,%1,%2,%3) format(%2, sizeof(%2), %3); \
SendClientMessage(%0, %1, %2)

//%0 = playerid, %1 = color, %2 = string to format then send, %3 = string content
//Example of use:
new string[128];
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name));
FormatMsg(playerid, COLOR, string, "Message sent to pl %d named %s", playerid, name);
Or
pawn Код:
#define FormatMsgEx(%0,%1,%2) new STRING[128]; \
format(STRING, 128, %2); \
SendClientMessage(%0, %1, %2)

//%0 = playerid, %1 = color, %2 = string content
//Example of use:
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name));
FormatMsgEx(playerid, COLOR, "Message sent to pl %d named %s", playerid, name);
?

This works perfectly and it's very simple. It can take a infinite number of argument, and it's much faster than all the other SendFormattedMessage functions I've seen. At least I'm sure of it, am I wrong?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)