Admin Message Command
#1

Hello Guys ,i have a problem with /am command ,its supposed to be for Admins only but even regular players can do it
Here is The Code
pawn Код:
CMD:am(playerid, params[])
{
    if(IsAdmin(playerid))
    {
        new toid, message[65];
        if(sscanf(params, "us[65]", toid, message)) return Syntax(playerid, "[a]dmin[m]essage: [playerid] [message]");
        if(strlen(message) > 65) return Error(playerid, "Your message cannot be longer than 65 characters.");
        if(!IsPlayerConnected(toid)) return Error(playerid, "That player is not connected!");
        new string[128];
        format(string, sizeof(string), "Admin message from %s: %s", GetPlayerNameEx(playerid), message);
        SendClientMessageEx(toid, COLOR_GREEN, string);
        format(string, sizeof(string), "Admin %s [%d] > %s [%d]: %s", GetPlayerNameEx(playerid), playerid, GetPlayerNameEx(toid), toid, message);
        SendAdminMessage(COLOR_GREEN,string);
    }
    else
    {
        new message[80];
        if(sscanf(params, "s[80]", message)) return Syntax(playerid, "[a]dmin[m]essage: [message]");
        if(strlen(message) > 80) return Error(playerid, "Your message cannot be longer than 80 characters.");
        new string[128];
        format(string, sizeof(string), "Admin message from %s [%d]: %s", GetPlayerNameEx(playerid), playerid, message);
        SendAdminMessage(COLOR_GREEN,string);
        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;
}
and i hope if you can SendClientMessage With the usage of the command ,For Regular Players will be like this
Код:
Usage:/[a]dmin[m]essage [Text]
For admins it will be like this
Код:
Usage:/[a]dmin[m]essage [Playerid] [Text]
Reply
#2

The reason normal players can do it is because when you check to see if they are an admin; your 'else'(which basically means if the player is not admin) still sends the message. You need the else to send the player an error message stating that this command is for administrators only.

Your code should be something like this;
pawn Код:
CMD:am(playerid, params[])
{
    if(IsAdmin(playerid))
    {
        new toid, message[128];
        if(sscanf(params, "us[128]", toid, message)) return Syntax(playerid, "[a]dmin[m]essage: [playerid] [message]");
        if(strlen(message) > 65) return Error(playerid, "Your message cannot be longer than 65 characters.");
        if(!IsPlayerConnected(toid)) return Error(playerid, "That player is not connected!");
        new string[128];
        format(string, sizeof(string), "Admin message from %s: %s", GetPlayerNameEx(playerid), message);
        SendClientMessageEx(toid, COLOR_GREEN, string);
        format(string, sizeof(string), "Admin %s [%d] > %s [%d]: %s", GetPlayerNameEx(playerid), playerid,   GetPlayerNameEx(toid), toid, message);
        SendAdminMessage(COLOR_GREEN,string);
    }
    else
    {
       SendClientMessage(playerid, COLOR_RED, "ERROR: This message is for administrators only!");
    }
    return 1;
}
Reply
#3

no i dont want it for admins only ,/am will be for Normal Players and Admins ,Normal players can use it like this
Код:
/am [Text]
so the admins can see their Message
and /am will be like this when admin uses it
Код:
/am [ID] [Text]
so the admins can reply to the players
if you can do it post please
Reply
#4

Oooh. When you said "Hello Guys ,i have a problem with /am command ,its supposed to be for Admins only but even regular players can do it", I thought you meant it's suppose to be an admin only command but the problem was that normal players could do it XD

Heres something i created fast to get the basic structure done; you'll have to rename the SCM's and everything back to your ones though. This is VERY basic and will only send messages to the last person that sent the 'am' message.
You can work on it to make it better.

pawn Код:
//removed due to being wrong
EDIT: Hmm.. I just realised after re-reading your post that I just over complicated this for no reason lol.

What exactly is the problem?
Reply
#5

i got these Errors
Код:
C:\Users\Win 7\Downloads\Compressed\LSRP.pwn(48198) : error 028: invalid subscript (not an array or too many subscripts): "IsAdmin"
C:\Users\Win 7\Downloads\Compressed\LSRP.pwn(48198) : warning 215: expression has no effect
C:\Users\Win 7\Downloads\Compressed\LSRP.pwn(48198) : error 001: expected token: ";", but found "]"
C:\Users\Win 7\Downloads\Compressed\LSRP.pwn(48198) : error 029: invalid expression, assumed zero
C:\Users\Win 7\Downloads\Compressed\LSRP.pwn(48198) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Line (48198 )
pawn Код:
if(IsAdmin[playerid])
Reply
#6

Here is the whole command with Defines
pawn Код:
stock IsAdmin( playerid )
{
    if(PlayerInfo[playerid][pAdmin]<=2) return 1;
    return 0;
}
new AMReplyId[MAX_PLAYERS];
CMD:am(playerid, params[])
{
    if(IsAdmin[playerid])
    {
        new toid, message[65];
        if(sscanf(params, "us[65]", toid, message)) return SendClientMessageEx(playerid, COLOR_WHITE,"USAGE: /[a]dmin[m]essage [playerid] [message]");
        if(strlen(message) > 65) return SendClientMessageEx(playerid, COLOR_RED,"Your message cannot be longer than 65 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(IsAdmin[i])
            {
                format(string, sizeof(string), "Admin %s [%d] > %s [%d]: %s", GetName(playerid), playerid, GetName(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(IsAdmin[i])
            {
                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;
}
pawn Код:
#define Syntax(%0,%1) SendClientMessage(%0, 0xFFFF00FF, %1)
#define Error(%0,%1) SendClientMessage(%0, 0xFF0000FF, %1)
Reply
#7

Try this; let me know what happens.
pawn Код:
CMD:am(playerid, params[])
{
    if(IsAdmin(playerid))
    {
        new toid, message[65];
        if(sscanf(params, "us[65]", toid, message)) return SendClientMessageEx(playerid, COLOR_WHITE,"USAGE: /[a]dmin[m]essage [playerid] [message]");
        if(strlen(message) > 65) return SendClientMessageEx(playerid, COLOR_RED,"Your message cannot be longer than 65 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(IsAdmin(i))
            {
                format(string, sizeof(string), "Admin %s [%d] > %s [%d]: %s", GetName(playerid), playerid, GetName(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(IsAdmin(i))
            {
                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
#8

Its working ,thanks man you are very helpful
Reply
#9

Np

I'm not sure it's going to work exactly how you want it to. Looking at it; it's only going to reply to the latest message.
If it doesn't, let me know in a PM incase i forget to check back here.
Reply
#10

Quote:
Originally Posted by Drago987
Посмотреть сообщение
Here is the whole command with Defines
pawn Код:
stock IsAdmin( playerid )
{
    if(PlayerInfo[playerid][pAdmin]<=2) return 1;
    return 0;
}
It should be >=, because you want if the player's admin level is greater or equal to 2, return true (that he's indeed an admin), else if it's level 0 or 1 (that he's not an admin).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)