/am problem
#1

Hello, i have a little problem here. I have this cmd, but everyone can see /am messages, and the admins should be the only ones able to see it!


pawn Код:
CMD:am(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
        new toid, message[80];
        if(sscanf(params, "us[80]", toid, message)) return SendClientMessageEx(playerid, COLOR_WHITE,"USAGE: /[a]dmin[m]essage [playerid] [message]");
        if(strlen(message) > 80) return SendClientMessageEx(playerid, COLOR_RED,"Your message cannot be longer than 80 characters.");
        if(!IsPlayerConnected(toid)) return SendClientMessageEx(playerid, COLOR_RED,"That player is not connected!");
        new string[128];
        format(string, sizeof(string), "Admin message from %s: %s", GetPlayerNameEx(playerid), message);
        SendClientMessageEx(AMReplyId[playerid], COLOR_GREEN, string);
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][pAdmin] >= 1)
            {
                format(string, sizeof(string), "Admin %s [%d] > %s [%d]: %s", GetPlayerNameEx(playerid), playerid, GetPlayerNameEx(toid), toid, message);
                SendClientMessageEx(i,COLOR_GREEN,string);
            }
        }
    }
    else
    {
        new message[80];
        if(sscanf(params, "s[80]", message)) return SendClientMessageEx(playerid, COLOR_WHITE,"USAGE: /am [message]");
        if(strlen(message) > 80) return SendClientMessageEx(playerid, COLOR_RED,"Your message cannot be longer than 80 characters.");
        new string[128];
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][pAdmin] >= 1)
            {
                format(string, sizeof(string), "Admin message from %s [%d]: %s", GetPlayerNameEx(playerid), playerid, message);
                SendClientMessageEx(i,COLOR_GREEN,string);
                AMReplyId[i] = playerid;
            }
        }
        format(string, sizeof(string), "Your message, %s, has been sent.", message);
        SendClientMessageEx(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "Player %s [%d] > Admins: %s", GetPlayerNameEx(playerid), playerid, message);
    }
    return 1;
}
Reply
#2

change this:
pawn Код:
SendClientMessageEx(i,COLOR_GREEN,string);
to this
pawn Код:
SendAdminMessage(i,COLOR_GREEN,string);
and if you don't have a stock for sendadminmessage
pawn Код:
stock SendAdminMessage(color, admlvl, string[])
{
    foreach(Player, i)
    {
        if(IsPlayerLoggedIn(i) && PlayerInfo[i][pAdmin] >= admlvl)
        {
            SendClientMessage(i, color, string);
        }
    }
    return 1;
}
Reply
#3

Try this:

Add this on top if you don't have isnull stock:
PHP код:
#if !defined isnull
    #define isnull(%1) \
                
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif 
Command:
PHP код:
CMD:am(playeridparams[])
{
    new 
toidmessage[80];
    if(
isnull(params)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /am [id/name] [message] or /am [message]");
    if(
sscanf(params"us[80]"toidmessage
    {
        if(
sscanf(params"s[80]"message)) return SendClientMessageEx(playeridCOLOR_WHITE,"USAGE: /am [message]");
        if(
strlen(message) > 80) return SendClientMessageEx(playeridCOLOR_RED,"Your message cannot be longer than 80 characters.");
        new 
string[128];
        for(new 
i=0i<MAX_PLAYERSi++)
        {
            if(
PlayerInfo[i][pAdmin] >= 1)
            {
                
format(stringsizeof(string), "Admin message from %s [%d]: %s"GetPlayerNameEx(playerid), playeridmessage);
                
SendClientMessageEx(i,COLOR_GREEN,string);
                
AMReplyId[i] = playerid;
            }
        }
        
format(stringsizeof(string), "Your message, %s, has been sent."message);
        
SendClientMessageEx(playeridCOLOR_GREENstring);
        
format(stringsizeof(string), "Player %s [%d] > Admins: %s"GetPlayerNameEx(playerid), playeridmessage);
    }
    else
    {
        if(
strlen(message) > 80) return SendClientMessageEx(playeridCOLOR_RED,"Your message cannot be longer than 80 characters.");
        if(!
IsPlayerConnected(toid)) return SendClientMessageEx(playeridCOLOR_RED,"That player is not connected!");
        new 
string[128];
        
format(stringsizeof(string), "Admin message from %s: %s"GetPlayerNameEx(playerid), message);
        
SendClientMessageEx(AMReplyId[playerid], COLOR_GREENstring);
        for(new 
i=0i<MAX_PLAYERSi++)
        {
            if(
PlayerInfo[i][pAdmin] >= 1)
            {
                
format(stringsizeof(string), "Admin %s [%d] > %s [%d]: %s"GetPlayerNameEx(playerid), playeridGetPlayerNameEx(toid), toidmessage);
                
SendClientMessageEx(i,COLOR_GREEN,string);
            }
        }
    }
    return 
1;

Reply
#4

@ATGOggy -
Код:
C:\Users\GHT\Desktop\OARPsv\OARP\gamemodes\OARP.pwn(40693) : error 001: expected token: ")", but found "{"
Line:
Код:
new toid, message[80];
    if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /am [id/name] [message] or /am [message]");
    if(sscanf(params, "us[80]", toid, message)
 [[[HERE]]]] ->   {
        if(sscanf(params, "s[80]", message)) return SendClientMessageEx(playerid, COLOR_WHITE,"USAGE: /am [message]");
        if(strlen(message) > 80) return SendClientMessageEx(playerid, COLOR_RED,"Your message cannot be longer than 80 characters.");
        new string[128];
        for(new i=0; i<MAX_PLAYERS; i++)
Reply
#5

Change this
Код:
 [[[HERE]]]] ->   {
to
Код:
 [[[HERE]]]] ->   )
Reply
#6

Command Copyright from P:LA
You should copy functions and others stock need for that COMMAND.
Reply
#7

Change this:
pawn Код:
if(sscanf(params, "us[80]", toid, message)
to this:[pawn if(sscanf(params, "us[80]", toid, message)) [/psawn]
Reply
#8

Quote:

expected token: ")", but found "{"

You should read the error message, it expected to find a " ) ", but instead the next thing it found, was a " { ".
Which would indicate you forgot to put a " ) " in that place.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)