SA-MP Forums Archive
How to Make a Custom Message Function - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to Make a Custom Message Function (/showthread.php?tid=316602)



How to Make a Custom Message Function - milanosie - 07.02.2012

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?


Re: How to Make a Custom Message Function - iTorran - 07.02.2012

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


Re: How to Make a Custom Message Function - Max_Coldheart - 07.02.2012

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.


Re: How to Make a Custom Message Function - milanosie - 07.02.2012

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,


Re: How to Make a Custom Message Function - milanosie - 07.02.2012

[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?