Admin Chat
#1

What's the problem with this

It's not showing message. It's showing: "[Admin Chat] Name [ID]: "
Код:
CMD:a(playerid, params[])
{
    if(PlayerInfo[playerid][pAdminLevel] >= 1)
    {
    	new name[24];
     	new string[300];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, string[1]);
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
	return 1;
}
Reply
#2

pawn Код:
CMD:a(playerid, params[])
{
    if(PlayerInfo[playerid][pAdminLevel] >= 1)
    {
        new name[MAX_PLAYER_NAME];
        new string[128];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, string);
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Try this.
Reply
#3

Still wont work.
Reply
#4

in your format, you must replace string with params.
but still this will only send the message to the one who uses the cmd. you must make a loop that detects who is admin and send the message to them all.
Here is how you can do it, better yet use foreach for it.
pawn Код:
CMD:a(playerid, params[])
{
    if(PlayerInfo[playerid][pAdminLevel] >= 1)
    {
        new name[24];
        new string[300];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, params);
        for(new i = 0; i < MAX_PLAYERS; i++) if(PlayerInfo[i][pAdminLevel] > 0) SendClientMessage(i, COLOR_WHITE, string);
    }
    return 1;
}
Reply
#5

How do I do that? I am kinda noob.

Edit:Testing
Reply
#6

i updated the post with with the loop that finds who is admin.
Reply
#7

Quote:
Originally Posted by Richie©
Посмотреть сообщение
i updated the post with with the loop that finds who is admin.
The message pops up now but wont show to other players
Reply
#8

Better option would be to use OnPlayerText.

In this example if an admin types "@ lets ban some players!"; Then just the message without the '@' will be sent to online admins.

pawn Код:
public OnPlayerText(playerid, text[])
{
    //if first char is '@' and player is admin...
    if( text[0] == '@' && PlayerInfo[playerid][pAdminLevel] >= 1 )
    {
        new name[24];
        new string[300];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, text[1]);

        for(new i=0; i < MAX_PLAYERS; ++i)//if you use foreach that is better
        {
            if( !IsPlayerConnected(i) )continue;

            if( PlayerInfo[i][pAdminLevel] >= 1 )
            {
                SendClientMessage(i, COLOR_WHITE, string);
            }
        }
        return 0;//return 0 so message isnt sent to normal chat
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Better option would be to use OnPlayerText.

In this example if an admin types "@ lets ban some players!"; Then just the message without the '@' will be sent to online admins.

pawn Код:
public OnPlayerText(playerid, text[])
{
    //if first char is '@' and player is admin...
    if( text[0] == '@' && PlayerInfo[playerid][pAdminLevel] >= 1 )
    {
        new name[24];
        new string[300];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, text[1]);

        for(new i=0; i < MAX_PLAYERS; ++i)//if you use foreach that is better
        {
            if( !IsPlayerConnected(i) )continue;

            if( PlayerInfo[i][pAdminLevel] >= 1 )
            {
                SendClientMessage(i, COLOR_WHITE, string);
            }
        }
        return 0;//return 0 so message isnt sent to normal chat
    }
    return 1;
}
Works perfectly! Thanks. But also it shows on global thingie like

"@You are noobs with boobs"
"[Admin Chat] Squirrel [4]: You are all noobs with boobs"



It might be problem since my other thing

Код:
public OnPlayerText(playerid, text[])
{
    new Rank[20];
    if(!Playerchatoff[playerid])
    {
	    switch(GetPlayerScore(playerid))
	    {
	        case 0 .. 10: format(Rank, sizeof(Rank),"[Trainee]");
	        case 11 .. 20: format(Rank, sizeof(Rank),"[Trainee 2]");
	        case 21 .. 30: format(Rank, sizeof(Rank),"[Solider]");
	        case 31 .. 40: format(Rank, sizeof(Rank),"[Solider Rank 2]");
	        case 41 .. 50: format(Rank, sizeof(Rank),"[Solider Rank 3]");
	        case 51 .. 60: format(Rank, sizeof(Rank),"[Corporal]");
	        case 61 .. 70: format(Rank, sizeof(Rank),"[Sargeant]");
	       	case 71 .. 80: format(Rank, sizeof(Rank),"[Staff Sargeant]");
	        case 81 .. 90: format(Rank, sizeof(Rank),"[Major Of The Army]");
	        case 91 .. 100: format(Rank, sizeof(Rank),"[First Lieutenant]");
	        case 101 .. 110: format(Rank, sizeof(Rank),"[Second Lieutenant]");
	        case 111 .. 120: format(Rank, sizeof(Rank),"[Captain]");
	        case 121 .. 130: format(Rank, sizeof(Rank),"[Major]");
	        case 131 .. 140: format(Rank, sizeof(Rank),"[Lieutenant Colonel]");
	        case 141 .. 150: format(Rank, sizeof(Rank),"[Colonel]");
	        case 151 .. 160: format(Rank, sizeof(Rank),"[General]");
	        case 161 .. 170: format(Rank, sizeof(Rank),"[General Of The Army]");
	        case 171 .. 9999: format(Rank, sizeof(Rank),"[God Of War]");
	    }
	    new ChatText[128], Nameasd[MAX_PLAYER_NAME];
	    GetPlayerName(playerid, Nameasd, MAX_PLAYER_NAME);
	    format(ChatText, sizeof(ChatText),"{F3FF02}%s %s:{FFFFFF} %s", Rank, Nameasd, text);
	    SendClientMessageToAll(-1, ChatText);
	}
	else
	{
	    SendClientMessage(playerid, COLOR_RED, "<!>Your chat is toggled off! Type /togchat!");
	}
	if( text[0] == '@' && PlayerInfo[playerid][pAdminLevel] >= 1  )
    {
        new name[24];
        new string[300];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, text[1]);

        for(new i=0; i < MAX_PLAYERS; ++i)
        {
            if( !IsPlayerConnected(i) )continue;

            if( PlayerInfo[i][pAdminLevel] >= 1 )
            {
                SendClientMessage(i, COLOR_WHITE, string);
            }
        }
        return 0;//return 0 so message isnt sent to normal chat
    }
	return 0;
}
Reply
#10

Put the code i posted at the top, so after the return 0 nothing else is processed.

pawn Код:
public OnPlayerText(playerid, text[])
{
    //if first char is '@' and player is admin...
    if( text[0] == '@' && PlayerInfo[playerid][pAdminLevel] >= 1 )
    {
        new name[24];
        new string[300];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof(string), "[Admin Chat] %s [%d]: %s", name, playerid, text[1]);

        for(new i=0; i < MAX_PLAYERS; ++i)//if you use foreach that is better
        {
            if( !IsPlayerConnected(i) )continue;

            if( PlayerInfo[i][pAdminLevel] >= 1 )
            {
                SendClientMessage(i, COLOR_WHITE, string);
            }
        }
        return 0;//return 0 so message isnt sent to normal chat
    }
    //your code here
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)