Not too familiar with #emit.
#1

I'm trying to transform

PHP код:
SendAdminMsg(msg[])
{
    foreach(new 
Player)
    {
        if(!
IsSpawned[i]) continue;
        if(
PlayerInfo[i][Admin_Level] > 1)
            
SendClientMessage(i, -1msg);
    }

into something like

PHP код:
SendAdminMsgEx(color, const text[], {Float_}:...)
{
    static 
argsstr[144];
    if((
args numargs()) == 3)
    {
        foreach(new 
Player)
        {
            if(!
IsSpawned[i]) continue;
            if(
PlayerInfo[i][Admin_Level] > 1)
                
SendClientMessage(icolortext);
        }
    }
    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 Player)
        {
            if(!
IsSpawned[i]) continue;
            if(
PlayerInfo[i][Admin_Level] > 1)
                
SendClientMessage(icolorstr);
        }
        
#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
Reply
#2

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); 
        }
Reply
#3

Even if I change that, the string sends but it doesn't format the string.

It'll just output "bla bla" without the name.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)