stock SendMessage(playerid, Color, String[], {Float,_}:...) { new String1[128]; format(String1, sizeof(String1), String, {Float,_}:...); SendClientMessage(playerid, Color, String1); return String1; }
//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);
You can do it like this:
PHP код:
![]() |
check please https://sampwiki.blast.hk/wiki/Format
|
//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;
}
Here you go.
pawn Код:
|
stock SendMessage(playerid, Color, Format[], va_args<>)
{
new String[128];
va_format(String, sizeof(String), Format, va_start<3>);
SendClientMessage(playerid, Color, String);
}
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.
}
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 код:
![]() 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
![]() ![]() |