Format message
#1

Hello guys, I want to now how can I create a message format like this

Код:
SFM(playerid, -1, "Hello %s", "Bonjour %s", GetName(playerid));
I currently use this, but I want what I have shown above, for something quicker to write
Код:
if(playerVariables[playerid][pLanguage] == 2) format(string, sizeof(string), "Bonjour %s", GetName(playerid));
else format(string, sizeof(string), "Hello %s", GetName(playerid));
SendClientMessage(playerid, -1, string);
I saw in some people scripting on ytb and I want to know how I can do that for myself.
Reply
#2

PHP код:
stock SFM(playeridcolorlang1[ ], lang2[ ])
{
if(
playerVariables[playerid][pLanguage] == 2SendClientMessage(playerid, -1lang2);
else 
SendClientMessage(playerid, -1lang1);

Reply
#3

Quote:
Originally Posted by iLearner
Посмотреть сообщение
PHP код:
stock SFM(playeridcolorlang1[ ], lang2[ ])
{
if(
playerVariables[playerid][pLanguage] == 2SendClientMessage(playerid, -1lang2);
else 
SendClientMessage(playerid, -1lang1);

This is just for SendClientMessage, i want to know how can I make for format message.
Reply
#4

Credit goes to Nero_3D. (http://forum.sa-mp.com/showpost.php?...postcount=4226).


So you just re-word it

PHP код:
stock SFM(playeridcolorform[], {Float_}: ...) {
    
#pragma unused form
    
static
        
tmp[145]
    ;
    new
        
t1 playerid,
        
t2 color
    
;
    const
        
n4 = -4,
        
n16 = -16,
        
size sizeof tmp
    
;
    
#emit stack 28
    #emit push.c size
    #emit push.c tmp
    #emit stack n4
    #emit sysreq.c format
    #emit stack n16
    
return SendClientMessage(t1t2tmp);

Quote:
Originally Posted by iLearner
Посмотреть сообщение
PHP код:
stock SFM(playeridcolorlang1[ ], lang2[ ])
{
if(
playerVariables[playerid][pLanguage] == 2SendClientMessage(playerid, -1lang2);
else 
SendClientMessage(playerid, -1lang1);

Indent? o.O
Reply
#5

I was writing using my mobile phone, and vbulletin does not allow any indentation.
Reply
#6

Quote:
Originally Posted by iLearner
Посмотреть сообщение
I was writing using my mobile phone, and vbulletin does not allow any indentation.
Oh hell yeah it does:

PHP код:
CMD:blabla
{
    
blabla
    
{
        
blabla
    
}

Reply
#7

Quote:
Originally Posted by iLearner
Посмотреть сообщение
PHP код:
stock SFM(playeridcolorlang1[ ], lang2[ ])
{
if(
playerVariables[playerid][pLanguage] == 2SendClientMessage(playerid, -1lang2);
else 
SendClientMessage(playerid, -1lang1);

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Oh hell yeah it does:

PHP код:
CMD:blabla
{
    
blabla
    
{
        
blabla
    
}

Nah it doesn't lol.


PHP код:
stock SFM(playeridcolorlang1[ ], lang2[ ]) 

     if(
playerVariables[playerid][pLanguage] == 2) return SendClientMessage(playerid, -1lang2); 
     
SendClientMessage(playerid, -1lang1); 

Reply
#8

I tried this

Код:
SFM(playerid, color, en[], fr[], va_args<>)
{
    switch( playerVariables[ playerid ][ pLanguage ] )
    {
        case 2: va_format(gString, sizeof (gString), fr, va_start<3>);
        case 1: va_format(gString, sizeof (gString), en, va_start<3>);
    }
    return SendClientMessage(playerid, color, gString);
}
But the server crash...
Reply
#9

Код:
#define BYTES_PER_CELL 				4

stock SFM(playerid, color, fstring[], {Float, _}:...)
{
    static const STATIC_ARGS = 3;
    new n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
    if(n)
    {
        new message[144],arg_start,arg_end;
        #emit CONST.alt        fstring
        #emit LCTRL          5
        #emit ADD
        #emit STOR.S.pri        arg_start

        #emit LOAD.S.alt        n
        #emit ADD
        #emit STOR.S.pri        arg_end
        do
        {
            #emit LOAD.I
            #emit PUSH.pri
            arg_end -= BYTES_PER_CELL;
            #emit LOAD.S.pri      arg_end
        }
        while(arg_end > arg_start);

        #emit PUSH.S          fstring
        #emit PUSH.C          144
        #emit PUSH.ADR         message

        n += BYTES_PER_CELL * 3;
        #emit PUSH.S          n
        #emit SYSREQ.C         format

        n += BYTES_PER_CELL;
        #emit LCTRL          4
        #emit LOAD.S.alt        n
        #emit ADD
        #emit SCTRL          4

        if(playerid == INVALID_PLAYER_ID)
        {
            #pragma unused playerid
            return SendClientMessageToAll(color, message);
        } else {
            return SendClientMessage(playerid, color, message);
        }
    } else {
        if(playerid == INVALID_PLAYER_ID)
        {
            #pragma unused playerid
            return SendClientMessageToAll(color, fstring);
        } else {
            return SendClientMessage(playerid, color, fstring);
        }
    }
}
Credits to ******.
Reply
#10

Quote:
Originally Posted by None1337
Посмотреть сообщение
I tried this

Код:
SFM(playerid, color, en[], fr[], va_args<>)
{
    switch( playerVariables[ playerid ][ pLanguage ] )
    {
        case 2: va_format(gString, sizeof (gString), fr, va_start<3>);
        case 1: va_format(gString, sizeof (gString), en, va_start<3>);
    }
    return SendClientMessage(playerid, color, gString);
}
Tried but the server crash when i use thsi command for example:

Код:
CMD:test(playerid, params[]) {
      new name[24];
      GetPlayerName(playerid, name, sizeof(name);
      SFM(playerid, -1, "Hello %s", "Bonjour %s");
      return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)