Admin Chat
#1



Код:
    if(!strcmp(strget(cmdtext,0),"/c"))
	{
	if(Spieler[playerid][AdminLevel] >=2)
	{
	if(!strlen(strget(cmdtext,1)))
	return
	SendClientMessage(playerid,COLOR_GREY,"Use: /c [Text]");
	new string[256];
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
 	format(string,sizeof(string), "Server - AdminChat [%d] %s: %s",playerid, name, cmdtext);
	print(string);
	{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(Spieler[i][AdminLevel] >=2)
	{
	PlayerPlaySound(i,1057 ,0,0,0);
 	SendClientMessage(i,COLOR_LIGHTGREEN,string);
	}}}}
	return 1;
}
This is my Admin Chat. But when we Chat in the Chat We see always the command for writing ( /c ). I ask you how to improve this. I hope you can help me =)

]B4E[kengston
Reply
#2

I know this is said alot but if you use a better command processor such as zcmd, you wouldn't have this problem.
Reply
#3

I also made this command with
Код:
new text1[128]; 
text1 = strval(strget(cmdtext,1);
. But this is not good.
Reply
#4

Use ZCMD and sscanf:
pawn Код:
COMMAND:c(playerid, params[])
{
  new chat[100], name[MAX_PLAYER_NAME];
  if(/PlayerInfo[playerid][pAdminLevel] >=2)
  {
    if(sscanf(params, "s", chat)) SendClientMessage(playerid, COLOR_GREY, "Use: /c [text]");
    GetPlayerName(playerid,name,sizeof(name));
    format(chat,sizeof(chat), "Server - AdminChat [%d] %s: %s",playerid, name, chat);
    print(chat);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(Spieler[i][AdminLevel] >=2)
        {
            PlayerPlaySound(i,1057 ,0,0,0);
            SendClientMessage(i,COLOR_LIGHTGREEN,chat);
        }
    }
  }
  return 1;
}
untested but it should work afaik
Reply
#5

I suggest you use zmcd but if you must use strcmp alone then...

pawn Код:
if(strcmp(cmd, "/admin", true) == 0 || strcmp(cmd, "/c", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: (/c) [admin chat]");
                return 1;
            }
            format(string, sizeof(string), "*%d Admin %s: %s", PlayerInfo[playerid][pAdmin], sendername, result);
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if (PlayerInfo[i][pAdmin] >= 1)
                {
                    SendAdminMessage(i, COLOR_LIGHTGREEN, string);
                }
            }
                                 format(string,sizeof(string), "Server - AdminChat [%d] %s: %s",playerid, sendername, result);
        }
        return 1;
    }
Edit: Damn got ninja'd
Reply
#6

Thanks =)
Reply
#7

Even better, don't use commands for admin chat use OnPlayerText like this,
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[0] == '#' && Spieler[playerid][AdminLevel] > 0)
    {
        new
            pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName , MAX_PLAYER_NAME);
        format(text,128 ,"|ADMIN CHAT| %s: %s", pName, text[1]);
        for(new i; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i))continue;
            if(Spieler[i][AdminLevel] > 0)
                SendClientMessage(i, COLOR_LIGHTGREEN, text);
        }
        return 0;
    }
    return 1;
}
Most admin systems use this method. Anything typed after '#' will be sent to admins.
Reply
#8

pawn Код:
//In OnPlayerCommandText
    if(!strcmp(cmdtext,"/c",true))
    {
        if(Spieler[playerid][AdminLevel] <2)return SendClientMessage(playerid,COLOR_GREY,"You're cannot use this command");
        GetPlayerName(playerid,string,24);
        if(!cmdtext[3])return SendClientMessage(playerid,COLOR_GREY,"Use: /c [Text]");
        format(string,sizeof(string), "Server - AdminChat [%d] %s: %s",playerid, string, cmdtext[3]);
        print(string);
        for(new player;player<MAX_PLAYERS;player++)
        {
            if(!IsPlayerConnected(player))continue;
            if(Spieler[playerid][AdminLevel] <2)continue;
            PlayerPlaySound(player,1057 ,0,0,0);
            SendClientMessage(player,COLOR_LIGHTGREEN,string);
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)