Format text directly into "SendClientMessage" ?
#1

Hello!

I know that you can use
pawn Код:
format(stringname, length, string[])
in order to format variables into a client message sent to the player(s).

I'm not that good with stocks and functions, but how could you possibly make a fast way to format AND send the client message at the same time? So i don't have to use format and SendClientMessage over and over again?

let's say this:

pawn Код:
SendClientMessage2(playerid, -1, "You have $%d in your wallet", GetPlayerMoney(playerid))
Is that possible? And how could you do it?

Thanks
Reply
#2

nvmmmm
Reply
#3

Actually I have a very good define for that:
Код:
new g_szBuffer[10000 char];
#define form(%0) (format(g_szBuffer, sizeof g_szBuffer, %0), g_szBuffer)
Then use it like this:
Код:
SendClientMessage(playerid,-1,form("You have %d money",money));
Reply
#4

Quote:
Originally Posted by zaibaslr2
Посмотреть сообщение
Actually I have a very good define for that:
Код:
new g_szBuffer[10000 char];
#define form(%0) (format(g_szBuffer, sizeof g_szBuffer, %0), g_szBuffer)
Then use it like this:
Код:
SendClientMessage(playerid,-1,form("You have %d money",money));
I'm a bit unsure about this:
pawn Код:
"new g_szBuffer[10000 char];
^ Isn't that the same as defining a new string with lenght: 1000 ?
It would use a lot of unnecessary memory; or am i wrong?

Thanks anyway for your replies.
Reply
#5

Have much fun

pawn Код:
#define SendFormatMessage(%0,%1,%2,%3) format(str, sizeof(str),%2,%3) && SendClientMessage(%0, %1, str)

SendFormatMessage(playerid, COLOR, "I am %s", thisismyname);
Reply
#6

You could do that if you knew how to use #emit (the assembly behind pawn)
The other solution would be to use a macro /\ or you use 'y_va' from YSI

y_va -> https://sampforum.blast.hk/showthread.php?tid=399069
YSI wiki -> http://ysi.wikia.com/wiki/Library:YSI%5Cy_va

If you don't want to use y_va for any reason
Reply
#7

I use something similar to the others:

Quote:

new scfmString[250];
#define SCM SendClientMessage
#define SCFM(%1,%2,%3) format(scfmString,sizeof(scfmString),%3), SCM(%1,%2,scfmString)

Sample:
Quote:

SCFM(playerid,COLOR_ORANGE,"Spectating stopped; %s disconnected. IP: %s",PD(pid,playerName),PD(pid,playerIP));

Yes I have a define for SendClientMessage (and SendClientMessageToAll). I hate typing out the full text while coding.
Reply
#8

pawn Код:
// Salute to YSI & Lorenc_

#include <YSI/y_va>


stock SendClientMessageEx(playerid, colour, format[], va_args<>)
{
    new
        out[128]
    ;
    va_format(out, sizeof(out), format, va_start<3>);
    SendClientMessage(playerid, colour, out);
}

stock SendClientMessageToAllEx(colour, format[], va_args<>)
{
    new
        out[128]
    ;
    va_format(out, sizeof(out), format, va_start<2>);
    SendClientMessageToAll(colour, out);
}
Reply
#9

Quote:
Originally Posted by airplanesimen
Посмотреть сообщение
I'm a bit unsure about this:
pawn Код:
"new g_szBuffer[10000 char];
^ Isn't that the same as defining a new string with lenght: 1000 ?
It would use a lot of unnecessary memory; or am i wrong?

Thanks anyway for your replies.
Well you can change it to 1000 if you want.
Reply
#10

Quote:
Originally Posted by Jakku
Посмотреть сообщение
Have much fun

pawn Код:
#define SendFormatMessage(%0,%1,%2,%3) format(str, sizeof(str),%2,%3) && SendClientMessage(%0, %1, str)

SendFormatMessage(playerid, COLOR, "I am %s", thisismyname);
This is great, almost perfect. Thankyou!


Quote:
Originally Posted by Nero_3D
You could do that if you knew how to use #emit (the assembly behind pawn)
The other solution would be to use a macro /\ or you use 'y_va' from YSI

y_va -> https://sampforum.blast.hk/showthread.php?tid=399069
YSI wiki -> http://ysi.wikia.com/wiki/Library:YSI%5Cy_va

If you don't want to use y_va for any reason
I'll read on this and check it out, thank you.


Thanks to you others as well, actually quite smart methods to use. This would indeed help my coding-flow get a bit better, along with other methods. I guess it's all about efficiency, right?

However, i guess i got what i needed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)