Parameters in a define -
n00el - 02.08.2016
Hello i dant to define a clientmessage with some parameter
Here is my define:
Код:
#define SendServerSikeres(%0,%1) \
SendClientMessageEx(%0, COLOR_SIKERES, "(( "%1" ))")
I woud like call it like SendServerSikeres(playerid, "test");
and show this: "(( test ))". But i can't do this in a define. Any idea? Thanks.
Here are the errors:
Код:
error 035: argument type mismatch (argument 2)
warning 215: expression has no effect
error 001: expected token: ";", but found ")"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
Re: Parameters in a define -
Luicy. - 02.08.2016
#define SendServerSikeres(%0,%1); SendClientMessageEx(%0,COLOR_SIKERES,"(( "%1" ))");
May we see SendClientMessageEx too?
Re: Parameters in a define -
AndySedeyn - 02.08.2016
PHP код:
#define SendServerSikeres(%0,%1) SendClientMessageEx(%0, COLOR_SIKERES, "(( "%1" ))")
Re: Parameters in a define -
n00el - 02.08.2016
Код:
#define SendServerMessage(%0,%1) \
SendClientMessageEx(%0, COLOR_SERVER, "[SZERVER]:{FFFFFF} "%1)
Here is a working one. Itw working, 'cause i dont nedd to put antother string after %1.
But i want to close the OOC with "))".
What you write, similar to me. Its not working.
Re: Parameters in a define -
Luicy. - 02.08.2016
Quote:
Originally Posted by Meller
May we see SendClientMessageEx too?
|
If you want help, read what I said.
Re: Parameters in a define -
n00el - 02.08.2016
If i can do this SCMEx withouth 'color' parameter, it can be good. But i can't, beasuse if I am remove the 'color' its dosent format my string.. Whetst the reason because i want to do it with #define
Here is it:
Код:
stock SendClientMessageEx(playerid, color, const text[], {Float, _}:...)
{
static
args,
str[144];
/*
* Custom function that uses #emit to format variables into a string.
* This code is very fragile; touching any code here will cause crashing!
*/
if ((args = numargs()) == 3)
{
SendClientMessage(playerid, color, text);
}
else
{
while (--args >= 3)
{
#emit LCTRL 5
#emit LOAD.alt args
#emit SHL.C.alt 2
#emit ADD.C 12
#emit ADD
#emit LOAD.I
#emit PUSH.pri
}
#emit PUSH.S text
#emit PUSH.C 144
#emit PUSH.C str
#emit PUSH.S 8
#emit SYSREQ.C format
#emit LCTRL 5
#emit SCTRL 4
SendClientMessage(playerid, color, str);
#emit RETN
}
return 1;
}
Re: Parameters in a define -
Stinged - 02.08.2016
If you're not going to add dynamic stuff (like variables) in a message, you shouldn't use format.
It's a waste of memory (str is 144 cells big)
Re: Parameters in a define -
n00el - 02.08.2016
But i only use this function with varibles, sometime 2, or 3-4. This is the reason, because i want to use this funcion. I can use it with infinity varibles.
Re: Parameters in a define -
n00el - 02.08.2016
I am done with it, its working in 50%, because
SendServerSikeres(playerid, "You set %s's health to: %.2f", ReturnName(userid, 0), amount);
And its showing, "You set TestName's health to "
So the last varible dosent set to the string. Anyone?
Код:
stock SendServerSikeres(playerid, const text[], {Float, _}:...)
{
static
args,
str[144],
string[144];
/*
* Custom function that uses #emit to format variables into a string.
* This code is very fragile; touching any code here will cause crashing!
*/
if ((args = numargs()) == 2)
{
format(string, 144, "(( %s ))", text);
SendClientMessage(playerid, COLOR_SIKERES, string);
}
else
{
while (--args >= 2)
{
#emit LCTRL 5
#emit LOAD.alt args
#emit SHL.C.alt 2
#emit ADD.C 12
#emit ADD
#emit LOAD.I
#emit PUSH.pri
}
#emit PUSH.S text
#emit PUSH.C 144
#emit PUSH.C str
#emit PUSH.S 8
#emit SYSREQ.C format
#emit LCTRL 5
#emit SCTRL 4
format(string, 144, "(( %s ))", str);
SendClientMessage(playerid, COLOR_SIKERES, string);
#emit RETN
}
return 1;
}
Re: Parameters in a define -
Nero_3D - 02.08.2016
PHP код:
// note! compiler will crash if you never used format before this function!
SendServerSikeres(playerid, const text[], {Float, _}:...) {
#pragma unused playerid, text
static
retn,
args,
pid,
prefix[] = {'(', '(', ' '},
tmp[141];
const n4 = -4;
#emit addr.pri 4
#emit const.alt retn
#emit movs 12
playerid = sizeof tmp - 3;
#emit stack 12
#emit push.c tmp
#emit load.pri args
#emit add.c 4
#emit push.pri
#emit sysreq.c format
strcat(tmp, " ))");
#emit const.pri retn
#emit stack n4
#emit movs 8
return SendClientMessage(pid, COLOR_SIKERES, prefix);
}