How to Make a Custom Message Function
#1

Hi there, I am getting kinda tired of typing:
pawn Код:
foreach(Player, i) {
        if(PlayerInfo[i][AdminLevel] >= 3) {
            new
                string[ 128 ], name[ MAX_PLAYER_NAME ];
            GetPlayerName(playerid, name, sizeof(name));
            format(string, sizeof(string), "[ADMIN]:%s: %s", name, params);
            SendClientMessage(i,COLOR_RED, string);
over and over again on every action a player does, like pm'in, /me action etc,
How could I make a function like messageadmin() or something?

How would my public/stock look like?
Reply
#2

pawn Код:
stock SendAdminMessage(color, message[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][AdminLevel] >= 3)
            {
                SendClientMessage(i, color, message);
            }
        }
    }
}
Something like that
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
It depends on how far you want to go. The code above (apart from ignoring that you were using "foreach" and "format") will send messages of a certain form to a certain set of players. If you want to send them to another set of players or in another form you will need another function (and hence will need one for every possible combination). Or you can try and generalise your code (or get a library) so that you only need one function that can do it all for you (though it would be a more complex function).
and if he is a new scripter, he doesn't understand a word from this.
I wouldn't call myself a new scripter as I've been here from the December 2009, but I still don't understand what you're saying in any of your posts.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
It depends on how far you want to go. The code above (apart from ignoring that you were using "foreach" and "format") will send messages of a certain form to a certain set of players. If you want to send them to another set of players or in another form you will need another function (and hence will need one for every possible combination). Or you can try and generalise your code (or get a library) so that you only need one function that can do it all for you (though it would be a more complex function).
Well, I understand most part of this, but all I need is to make a shorter function that sends a message to all admins online with lvl 4 or higher,

The message must be defined in the cmd that is executed,
Reply
#5

[QUOTE=iTorran;1666703]
pawn Код:
stock SendAdminMessage(color, message[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][AdminLevel] >= 3)
            {
                SendClientMessage(i, color, message);
            }
        }
    }
}
wouldn't that give warnings in the cmd that the function message is never used?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)