Help with stock
#1

Hello , i made a stock and i have a problem ...

Код:
stock SendMessage(playerid, Color, String[], {Float,_}:...)
{
	new String1[128];
	format(String1, sizeof(String1), String, {Float,_}:...);
	
	SendClientMessage(playerid, Color, String1);
	
	return String1;
}
You will understand what i want with that
Reply
#2

You can do it like this:

PHP код:
//Write this @top of the script
#define SendMessage(%0,%1,%2,%3) format(string,sizeof(string),%2,%3),SendClientMessage(%0,%1,string)
//You can use it like this in cmds:
new string[128]; //Must declare a string
SendMessage(playerid,0xFF4800FF,"Hello player with id: %d",playerid); 
Greekz
Reply
#3

check please https://sampwiki.blast.hk/wiki/Format
Reply
#4

can't use this stock ! use easy format and SendClientMessage
Reply
#5

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
You can do it like this:

PHP код:
//Write this @top of the script
#define SendMessage(%0,%1,%2,%3) format(string,sizeof(string),%2,%3),SendClientMessage(%0,%1,string)
//You can use it like this in cmds:
new string[128]; //Must declare a string
SendMessage(playerid,0xFF4800FF,"Hello player with id: %d",playerid); 
Greekz
Ok , thanks but i just found y_va.inc by ****** ... That include it's amazing :O

Quote:
Originally Posted by morjan
Посмотреть сообщение
Why do you think i tried to do that stock ? To use 100 times format and new string No thanks :P

Quote:
Originally Posted by M0HAMMAD
Посмотреть сообщение
can't use this stock ! use easy format and SendClientMessage
What mean easy format ?? I searched on ****** and didn't find anything ..
Reply
#6

Here you go.

pawn Код:
//EG: SendFormattedMessage(playerid, COLOR_WHITE, "Hello there %d", playerid);
//EG 2: SendFormattedMessage(playerid, COLOR_WHITE, "HEY!!");

stock SendFormattedMessage(playerid, color, const msg[], {Float,_}:...)
{
    static
        string[144];

    if (numargs() == 3)
    {
        SendClientMessage(playerid, color, msg);
    }
    else
    {
        new args = numargs();

        while (--args >= 3)
        {
            #emit LCTRL 5
            #emit LOAD.S.alt args
            #emit SHL.C.alt 2
            #emit ADD
            #emit ADD.C 12
            #emit LOAD.I
            #emit PUSH.pri
        }
        #emit PUSH.S msg
        #emit PUSH.C 144
        #emit PUSH.C string

        #emit LOAD.S.pri 8
        #emit PUSH.pri
        #emit SYSREQ.C format

        SendClientMessage(playerid, color, string);

        #emit LCTRL 5
        #emit SCTRL 4
        #emit RETN
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by zT KiNgKoNg
Посмотреть сообщение
Here you go.

pawn Код:
//EG: SendFormattedMessage(playerid, COLOR_WHITE, "Hello there %d", playerid);

stock SendFormattedMessage(playerid, color, const msg[], {Float,_}:...)
{
    static
        string[144];

    if (numargs() == 3)
    {
        SendClientMessage(playerid, color, msg);
    }
    else
    {
        new args = numargs();

        while (--args >= 3)
        {
            #emit LCTRL 5
            #emit LOAD.S.alt args
            #emit SHL.C.alt 2
            #emit ADD
            #emit ADD.C 12
            #emit LOAD.I
            #emit PUSH.pri
        }
        #emit PUSH.S msg
        #emit PUSH.C 144
        #emit PUSH.C string

        #emit LOAD.S.pri 8
        #emit PUSH.pri
        #emit SYSREQ.C format

        SendClientMessage(playerid, color, string);

        #emit LCTRL 5
        #emit SCTRL 4
        #emit RETN
    }
    return 1;
}
i founded it too , but founded too that:

Код HTML:
stock SendMessage(playerid, Color, Format[], va_args<>)
{
	new String[128];
	va_format(String, sizeof(String), Format, va_start<3>);
	SendClientMessage(playerid, Color, String);
}
much easiest , no ?
Reply
#8

Quote:
Originally Posted by Mariciuc223
Посмотреть сообщение
much easiest , no ?
You must know, that behind that is an Library (impl.inc)

The real code you use is this: https://github.com/eider-i128/YSI-In.../y_va/impl.inc

And the function you call is this:

PHP код:
stock va_format(out[], size, const fmat[], va_:STATIC_ARGS)
{
    new
        
num_args,
        
arg_start,
        
arg_end;
    
// Get the pointer to the number of arguments to the last function.
    #emit LOAD.S.pri   0
    #emit ADD.C        8
    #emit MOVE.alt
    // Get the number of arguments.
    #emit LOAD.I
    #emit STOR.S.pri   num_args
    // Get the variable arguments (end).
    #emit ADD
    #emit STOR.S.pri   arg_end
    // Get the variable arguments (start).
    #emit LOAD.S.pri   STATIC_ARGS
    #emit SMUL.C       4
    #emit ADD
    #emit STOR.S.pri   arg_start
    // Using an assembly loop here screwed the code up as the labels added some
    // odd stack/frame manipulation code...
    
while (arg_end != arg_start)
    {
        
#emit MOVE.pri
        #emit LOAD.I
        #emit PUSH.pri
        #emit CONST.pri    4
        #emit SUB.alt
        #emit STOR.S.pri   arg_end
    
}
    
// Push the additional parameters.
    #emit PUSH.S       fmat
    #emit PUSH.S       size
    #emit PUSH.S       out
    // Push the argument count.
    #emit LOAD.S.pri   num_args
    #emit ADD.C        12
    #emit LOAD.S.alt   STATIC_ARGS
    #emit XCHG
    #emit SMUL.C       4
    #emit SUB.alt
    #emit PUSH.pri
    #emit MOVE.alt
    // This gets confused if you have a local variable of the same name as it
    // seems to factor in them first, so you get the offset of the local
    // variable instead of the index of the native.
    #emit SYSREQ.C     format
    // Clear the stack.
    #emit CONST.pri    4
    #emit ADD
    #emit MOVE.alt
    // The three lines above get the total stack data size, now remove it.
    #emit LCTRL        4
    #emit ADD
    #emit SCTRL        4
    // Now do the real return.

So...yeah it's nearly the same

But with my macro you wouldn't call a function...
Reply
#9

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
You must know, that behind that is an Library (impl.inc)

The real code you use is this: https://github.com/eider-i128/YSI-In.../y_va/impl.inc

And the function you call is this:

PHP код:
stock va_format(out[], size, const fmat[], va_:STATIC_ARGS)
{
    new
        
num_args,
        
arg_start,
        
arg_end;
    
// Get the pointer to the number of arguments to the last function.
    #emit LOAD.S.pri   0
    #emit ADD.C        8
    #emit MOVE.alt
    // Get the number of arguments.
    #emit LOAD.I
    #emit STOR.S.pri   num_args
    // Get the variable arguments (end).
    #emit ADD
    #emit STOR.S.pri   arg_end
    // Get the variable arguments (start).
    #emit LOAD.S.pri   STATIC_ARGS
    #emit SMUL.C       4
    #emit ADD
    #emit STOR.S.pri   arg_start
    // Using an assembly loop here screwed the code up as the labels added some
    // odd stack/frame manipulation code...
    
while (arg_end != arg_start)
    {
        
#emit MOVE.pri
        #emit LOAD.I
        #emit PUSH.pri
        #emit CONST.pri    4
        #emit SUB.alt
        #emit STOR.S.pri   arg_end
    
}
    
// Push the additional parameters.
    #emit PUSH.S       fmat
    #emit PUSH.S       size
    #emit PUSH.S       out
    // Push the argument count.
    #emit LOAD.S.pri   num_args
    #emit ADD.C        12
    #emit LOAD.S.alt   STATIC_ARGS
    #emit XCHG
    #emit SMUL.C       4
    #emit SUB.alt
    #emit PUSH.pri
    #emit MOVE.alt
    // This gets confused if you have a local variable of the same name as it
    // seems to factor in them first, so you get the offset of the local
    // variable instead of the index of the native.
    #emit SYSREQ.C     format
    // Clear the stack.
    #emit CONST.pri    4
    #emit ADD
    #emit MOVE.alt
    // The three lines above get the total stack data size, now remove it.
    #emit LCTRL        4
    #emit ADD
    #emit SCTRL        4
    // Now do the real return.

So...yeah it's nearly the same

But with my macro you wouldn't call a function...
But with your macro i will make a string every time when i want to use it And that sucks
Reply
#10

Quote:
Originally Posted by Mariciuc223
Посмотреть сообщение
But with your macro i will make a string every time when i want to use it And that sucks
Yes i know you're problem

Just use this from ****** it's fine
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)