Format help
#1

i got this
PHP код:
SendPlayerFormattedText(playeridcolorstr[], define1[], define2[])
{
    new 
tstr[256];
    
format(tstr256strdefine1define2);
    
SendClientMessage2(playeridcolortstr);
    return 
1;

that make it easy on me and send the player an formatted text without making sting and format it but the problem is what if i want to have more than 2 defines like i want have 10 is there a possible way to make the format work with how much defines i got?
Reply
#2

It should be:

PHP код:
SendPlayerFormattedText(playeridcolorstr[], define1[], define2[], define3[]) 

    new 
tstr[256]; 
    
format(tstr256strdefine1define2define3); 
    
SendClientMessage2(playeridcolortstr); 
    return 
1

Just add on to the format and to the function, or did I misunderstand u?

EDIT: Increase the string size too
Reply
#3

Search around the forum a bit. If you don't want to y_va then there are a couple of standalone versions that use some #emit trickery, for example: http://forum.sa-mp.com/showpost.php?...postcount=4225
Reply
#4

Quote:
Originally Posted by Immortal99
Посмотреть сообщение
It should be:

PHP код:
SendPlayerFormattedText(playeridcolorstr[], define1[], define2[], define3[]) 

    new 
tstr[256]; 
    
format(tstr256strdefine1define2define3); 
    
SendClientMessage2(playeridcolortstr); 
    return 
1

Just add on to the format and to the function, or did I misunderstand u?

EDIT: Increase the string size too
no lol what if i want to put like 50 defines ill need to make the SendPlayerFormatedText looks like this SendPlayerFormatedText(playerid, -1, "message", "", "", "", "", "", "", "" and till 50
Reply
#5

The same as vince showed you,
PHP код:
stock sprintf(const fmat[], {Float_}:...) {
    static 
output[STRLIB_RETURN_SIZE], frm_header[3], heap;
    
    const 
output_size sizeof(output);
    
    if (
ispacked(fmat)) {
        
heap CopyArgumentToHeap(0);
    } else {
        
heap 0;
    }{}
    
    
// Store current frame header
    #emit LCTRL      5
    #emit CONST.alt  frm_header
    #emit MOVS       12
    
    // Change the stack pointer to FRM + 12
    #emit ADD.C    12 // pri is FRM (see above)
    #emit SCTRL    4
    
    // Push sizeof(output)
    #emit PUSH.C      output_size
    
    // Push output
    #emit PUSH.C      output
    
    // Push the argument count
    #emit LOAD.S.pri  8
    #emit ADD.C       8
    #emit PUSH.pri
    
    #if !STRLIB_USE_FORMATEX
        
const formatex 0// Dummy used to avoid "unknown symbol" error
        
        
goto do_sysreq;
    
#endif

    // Call formatex (unless this was skipped above)
    #emit LCTRL       6
    #emit ADD.C       36
    #emit PUSH.pri
    #emit CONST.pri   formatex
    #emit SCTRL       6
    
    #if !STRLIB_USE_FORMATEX
        
do_sysreq:
    
#endif
    
    // Call format (unless formatex was called, in which case this is skipped)
    #emit SYSREQ.C    format
    
    // Restore the stack pointer to FRM
    #emit LCTRL       5
    #emit SCTRL       4
    
    // Copy back the frame header
    #emit MOVE.alt
    #emit CONST.pri   frm_header
    #emit MOVS        12
    
    // Restore heap if needed
    
if (heap) {
        
RestoreHeapToAddress(heap);
    }{}
    
    
// IMPORTANT: Fix compiler bug (returning strings in variadic functions)
    #emit LOAD.S.pri  8
    #emit ADD.C       12
    #emit MOVE.alt
    #emit LCTRL       5
    #emit ADD
    #emit LOAD.I
    #emit STOR.S.pri  20 // 16 + (static_args * 4)
    
    
return output;
    
    
// It is actually used, just not by its symbol name
    #pragma unused fmat

I'm not going to pretend Like I understand how every line works, if you're like me and don't want to bother working with #emit, use this include https://sampforum.blast.hk/showthread.php?tid=362764 , It has lots of useful function, to work with strings, you'll filnd a function sprintf It does what you're looking for.
Reply
#6

Thanks Both @Eoussma and @Vince
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)