Not too familiar with #emit. -
itsCody - 30.01.2016
I'm trying to transform
PHP код:
SendAdminMsg(msg[])
{
foreach(new i : Player)
{
if(!IsSpawned[i]) continue;
if(PlayerInfo[i][Admin_Level] > 1)
SendClientMessage(i, -1, msg);
}
}
into something like
PHP код:
SendAdminMsgEx(color, const text[], {Float, _}:...)
{
static args, str[144];
if((args = numargs()) == 3)
{
foreach(new i : Player)
{
if(!IsSpawned[i]) continue;
if(PlayerInfo[i][Admin_Level] > 1)
SendClientMessage(i, 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
foreach(new i : Player)
{
if(!IsSpawned[i]) continue;
if(PlayerInfo[i][Admin_Level] > 1)
SendClientMessage(i, color, str);
}
#emit RETN
}
return 1;
}
SendAdminMsgEx just outputs a blank string.
The example usage of SendAdminMsgEx would be
PHP код:
SendAdminMsgEx(-1, "%s bla bla", PlayerName(playerid));
instead of doing the whole new string[50]; and formatting it lmao
Re: Not too familiar with #emit. -
Gammix - 30.01.2016
You are checking if the number of arguments are 3:
pawn Код:
if((args = numargs()) == 3)
And then sending an empty string (str).
Of course if you see your example, the number of arguments is 3 because the arg count starts from Natural numbers. So in your example,
PlayeName(playeid) is the 3rd argument, so according to your code, it will send a empty client message. (the number should be 2, in the first check)
And also, you can directly send your message if there is no args like this:
Код:
foreach(new i : Player)
{
if(!IsSpawned[i]) continue;
if(PlayerInfo[i][Admin_Level] > 1)
SendClientMessage(i, color, text);
}
Re: Not too familiar with #emit. -
itsCody - 30.01.2016
Even if I change that, the string sends but it doesn't format the string.
It'll just output "bla bla" without the name.
Re: Not too familiar with #emit. -
Yashas - 31.01.2016
You really need to go through the basics. You are not aware of the difference between PUSH.S and PUSH.C.
Go through this tutorial,
AMX Assembly
Before calling a function, you first need to pass the arguments in reverse order then push the number of arguments in terms of its size.
Код:
#emit PUSH.S text
#emit PUSH.C 144
#emit PUSH.C str
#emit PUSH.S 8
#emit SYSREQ.C format
#emit PUSH.S 8??
PUSH.S pushes an element in the stack but the PUSH before SYSREQ must push a constant value which tells the number of arguments in terms of its size. So you must have used PUSH.C (size of arguments).
And still why push 8? Firstly, you have str, 144, text which makes 3 arguments so you need to push at least 12. Why at least? You have already pushed so many arguments already in your while loop and you haven't accounted for that.
And this
Код:
if((args = numargs()) == 3)
must be
Код:
if((args = numargs()) == 2)
because if just color and message is passed, it accounts for two arguments not 3 and you would want to send such messages which require no formatting directly.
Re: Not too familiar with #emit. -
itsCody - 31.01.2016
I'm not the type to read tutorials on such stuff, I like to learn without them.
I think I fixed this issue earlier today but haven't tested it, thanks though.
Re: Not too familiar with #emit. -
jamesbond007 - 31.01.2016
why are u doing it this way? is there really no other way to do this in normal pawn code? i feel like ur over thinking it because u probably dont need to use emit