SendClientMessageToAllCops [rep+]
#1

Hello. I want to do a system that I can write for example: "SendClientMessageToAllCops(COLOR_RED, "The bank in Las Venturas has been robbed - get there immediatly");"

The definition of cops in my server is:
pawn Код:
#define TEAM_COPS 0
.
I'd really appreciate some help

I'll rep for anyone who helps me.
Reply
#2

I use something similar:

pawn Код:
// bottom of script

stock FindTeam(playerid)
{
    new Team = GetPVarInt(playerid,"Team");
    return Team;
}

// bottom of script

forward MessageToCops(color,const string[]);
public MessageToCops(color,const string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new Team = FindTeam(i);
       
        if(IsPlayerConnected(i))
        {
            if(Team == TEAM_COPS)
            {
                SendClientMessage(i,color,string);
            }
        }
    }
    return 1;
}
Then for your message when the robber robs the bank, for example:

pawn Код:
new string[128], name[24]; // name will be the robbers name
GetPlayerName(playerid,name,24);

format(string,128,"Attention All Units!  The Bank In Las Venturas Has Been Robbed By %s!",name);
MessageToCops(your_color,string);
Reply
#3

You could use the following:

pawn Код:
stock SendClientMessageToAllCops(color[], message[])
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerTeam(i) == TEAM_COPS)
        {
            SendClientMessage(i, color, message);
        }
    }
    return 1;
}
Then you can use this line:
pawn Код:
SendClientMessageToAllCops(COLOR_RED, "The bank in Las Venturas has been robbed - get there immediatly");
I have to say, my stock is better than the one above mine, because for his 'system' you'll have to set a variable for the players, with my stock you don't have to do anything except what you already did, setting the players to a team. (SetPlayerTeam)
Reply
#4

I got C:\Users\Chuck Norris\Desktop\samp\gamemodes\Scratch.pwn(32) : error 035: argument type mismatch (argument 2)

Argument 2 = color
Reply
#5

pawn Код:
stock SendClientMessageToAllCops(color, const message[])
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerTeam(i) == TEAM_COPS)
        {
            SendClientMessage(i, color, message);
        }
    }
    return 1;
}
Reply
#6

Why use loops? "foreach" is so much more efficient. Simply replace
Код:
for(new i=0; i < MAX_PLAYERS; i++)
with,
Код:
foreach(Player, i)
If you don't know, you can find foreach here. Or the direct download for it here..
Reply
#7

Quote:
Originally Posted by [MWR]Blood
Посмотреть сообщение
pawn Код:
stock SendClientMessageToAllCops(color, const message[])
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerTeam(i) == TEAM_COPS)
        {
            SendClientMessage(i, color, message);
        }
    }
    return 1;
}
I think someone here doesn't know what const is and that colors are strings.
Reply
#8

Actually a color is an integer
Try to use it with color[], and then with color, you will see you get an error (Probably a tag mismatch not sure about that though)
Reply
#9

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Actually a color is an integer
Try to use it with color[], and then with color, you will see you get an error (Probably a tag mismatch not sure about that though)
Actually it's a hexadecimal number, not an integer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)