SA-MP Forums Archive
Format text directly into "SendClientMessage" ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Format text directly into "SendClientMessage" ? (/showthread.php?tid=543257)



Format text directly into "SendClientMessage" ? - denNorske - 25.10.2014

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


Re: Format text directly into "SendClientMessage" ? - Rudy_ - 25.10.2014

nvmmmm


Re: Format text directly into "SendClientMessage" ? - zaibaslr2 - 25.10.2014

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));



Re: Format text directly into "SendClientMessage" ? - denNorske - 25.10.2014

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.


Re: Format text directly into "SendClientMessage" ? - Jakku - 25.10.2014

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);



AW: Format text directly into "SendClientMessage" ? - Nero_3D - 25.10.2014

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


Re: Format text directly into "SendClientMessage" ? - nemesis- - 25.10.2014

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.


Re: Format text directly into "SendClientMessage" ? - gurmani11 - 25.10.2014

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



Re: Format text directly into "SendClientMessage" ? - zaibaslr2 - 26.10.2014

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.


Re: Format text directly into "SendClientMessage" ? - denNorske - 26.10.2014

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.