/warn command in chat
#1

Hey guys,

i got a /warn [playerid] [reason] command, but i want to add this:
Player [warned-player-name] has been warned by admin: [admin-name]
in the color: RED

This message have to be sended to the mainchat (that everybody can see the player is warned ).

This is what I have, but I don't know how/where to add the SendClientMessageToAll

PHP код:
// Warn a player
COMMAND:warn(playeridparams[])
{
    new 
PlayerToWarnReason[128], ReasonMsg[128], Name[24];
    
// Send the command to all admins so they can see it
    
SendAdminText(playerid"/warn"params);
    
// Check if the player has logged in
    
if (APlayerData[playerid][LoggedIn] == true)
    {
        
// Check if the player's admin-level is at least 1
        
if (APlayerData[playerid][PlayerLevel] >= 1)
        {
            if (
sscanf(params"us[128]"PlayerToWarnReason)) SendClientMessage(playerid0xFF0000AA"Usage: \"/warn <PlayerToWarn> <Reason>\"");
            else
                if (
IsPlayerConnected(PlayerToWarn)) // If the player is a valid playerid (he's connected)
                
{
                    
// Increase the number of warnings
                    
APlayerData[PlayerToWarn][Warnings]++;
                    
// Get the name of the player who warned the player
                    
GetPlayerName(playeridNamesizeof(Name));
                    
// Send the warned player a message who warned him and why he's been warned
                    
format(ReasonMsg128"You have been warned by %s %s"AdminLevelName[APlayerData[playerid][PlayerLevel]], Name);
                    
SendClientMessage(PlayerToWarn0xFF0000FFReasonMsg);
                    
format(ReasonMsg128"Reason: %s"Reason);
                    
SendClientMessage(PlayerToWarn0xFF0000FFReasonMsg);
                    
format(ReasonMsg128"~w~Warning %i/%i: ~r~%s~w~"APlayerData[PlayerToWarn][Warnings], AutoKickWarningsReason);
                    
GameTextForPlayer(PlayerToWarnReasonMsg50004);
                    
// Get the name of the warned player
                    
GetPlayerName(PlayerToWarnNamesizeof(Name));
                    
// Let the admin know who has been warned and why
                    
format(ReasonMsg128"You have warned %s (warnings: %i/%i)"NameAPlayerData[PlayerToWarn][Warnings], AutoKickWarnings);
                    
SendClientMessage(playerid0x00FF00FFReasonMsg);
                    
format(ReasonMsg128"Reason: %s"Reason);
                    
SendClientMessage(playerid0xFF0000FFReasonMsg);
                    
// Automatically kick the player if he got 3 warnings (if autokick is enabled)
                    
if ((APlayerData[PlayerToWarn][Warnings] == AutoKickWarnings) && (AutoKickAfterWarn == 1))
                        
Kick(PlayerToWarn);
                }
                else
                    
SendClientMessage(playerid0xFF0000FF"That player isn't online");
        }
        else
            return 
0;
    }
    else
        return 
0;
    
// Let the server know that this was a valid command
    
return 1;

Reply
#2

This should work:

pawn Код:
COMMAND:warn(playerid, params[])
{
    new PlayerToWarn, Reason[128], ReasonMsg[128], Name[24];

    // Send the command to all admins so they can see it
    SendAdminText(playerid, "/warn", params);

    // Check if the player has logged in
    if (APlayerData[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 1
        if (APlayerData[playerid][PlayerLevel] >= 1)
        {
            if (sscanf(params, "us[128]", PlayerToWarn, Reason)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/warn <PlayerToWarn> <Reason>\"");
            else
                if (IsPlayerConnected(PlayerToWarn)) // If the player is a valid playerid (he's connected)
                {
                    // Increase the number of warnings
                    APlayerData[PlayerToWarn][Warnings]++;

                    // Get the name of the player who warned the player
                    GetPlayerName(playerid, Name, sizeof(Name));
                    // Send the warned player a message who warned him and why he's been warned
                    format(ReasonMsg, 128, "You have been warned by %s %s", AdminLevelName[APlayerData[playerid][PlayerLevel]], Name);
                    SendClientMessage(PlayerToWarn, 0xFF0000FF, ReasonMsg);
                    format(ReasonMsg, 128, "Reason: %s", Reason);
                    SendClientMessage(PlayerToWarn, 0xFF0000FF, ReasonMsg);
                    format(ReasonMsg, 128, "~w~Warning %i/%i: ~r~%s~w~", APlayerData[PlayerToWarn][Warnings], AutoKickWarnings, Reason);
                    GameTextForPlayer(PlayerToWarn, ReasonMsg, 5000, 4);

                    // Get the name of the warned player
                    GetPlayerName(PlayerToWarn, Name, sizeof(Name));
                    // Let the admin know who has been warned and why
                    format(ReasonMsg, 128, "You have warned %s (warnings: %i/%i)", Name, APlayerData[PlayerToWarn][Warnings], AutoKickWarnings);
                    SendClientMessage(playerid, 0x00FF00FF, ReasonMsg);
                    format(ReasonMsg, 128, "Reason: %s", Reason);
                    SendClientMessage(playerid, 0xFF0000FF, ReasonMsg);
                   
                    //Sends message to all players that a player as been warned
                    format(ReasonMsg, 128, "Player %s has been warned by admin: %s", Name, GetPlayerName(playerid, name, sizeof(name)));
                    SendClientMessageToAll(0xFFFFFFFF, ReasonMsg);

                    // Automatically kick the player if he got 3 warnings (if autokick is enabled)
                    if ((APlayerData[PlayerToWarn][Warnings] == AutoKickWarnings) && (AutoKickAfterWarn == 1))
                        Kick(PlayerToWarn);
                }
                else
                    SendClientMessage(playerid, 0xFF0000FF, "That player isn't online");
        }
        else
            return 0;
    }
    else
        return 0;

    // Let the server know that this was a valid command
    return 1;
}
I added two things. It should be easy to see what I added.
Reply
#3

Quote:
Originally Posted by Kindred
Посмотреть сообщение
This should work:

pawn Код:
COMMAND:warn(playerid, params[])
{
    new PlayerToWarn, Reason[128], ReasonMsg[128], Name[24];

    // Send the command to all admins so they can see it
    SendAdminText(playerid, "/warn", params);

    // Check if the player has logged in
    if (APlayerData[playerid][LoggedIn] == true)
    {
        // Check if the player's admin-level is at least 1
        if (APlayerData[playerid][PlayerLevel] >= 1)
        {
            if (sscanf(params, "us[128]", PlayerToWarn, Reason)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/warn <PlayerToWarn> <Reason>\"");
            else
                if (IsPlayerConnected(PlayerToWarn)) // If the player is a valid playerid (he's connected)
                {
                    // Increase the number of warnings
                    APlayerData[PlayerToWarn][Warnings]++;

                    // Get the name of the player who warned the player
                    GetPlayerName(playerid, Name, sizeof(Name));
                    // Send the warned player a message who warned him and why he's been warned
                    format(ReasonMsg, 128, "You have been warned by %s %s", AdminLevelName[APlayerData[playerid][PlayerLevel]], Name);
                    SendClientMessage(PlayerToWarn, 0xFF0000FF, ReasonMsg);
                    format(ReasonMsg, 128, "Reason: %s", Reason);
                    SendClientMessage(PlayerToWarn, 0xFF0000FF, ReasonMsg);
                    format(ReasonMsg, 128, "~w~Warning %i/%i: ~r~%s~w~", APlayerData[PlayerToWarn][Warnings], AutoKickWarnings, Reason);
                    GameTextForPlayer(PlayerToWarn, ReasonMsg, 5000, 4);

                    // Get the name of the warned player
                    GetPlayerName(PlayerToWarn, Name, sizeof(Name));
                    // Let the admin know who has been warned and why
                    format(ReasonMsg, 128, "You have warned %s (warnings: %i/%i)", Name, APlayerData[PlayerToWarn][Warnings], AutoKickWarnings);
                    SendClientMessage(playerid, 0x00FF00FF, ReasonMsg);
                    format(ReasonMsg, 128, "Reason: %s", Reason);
                    SendClientMessage(playerid, 0xFF0000FF, ReasonMsg);
                   
                    //Sends message to all players that a player as been warned
                    format(ReasonMsg, 128, "Player %s has been warned by admin: %s", Name, GetPlayerName(playerid, name, sizeof(name)));
                    SendClientMessageToAll(0xFFFFFFFF, ReasonMsg);

                    // Automatically kick the player if he got 3 warnings (if autokick is enabled)
                    if ((APlayerData[PlayerToWarn][Warnings] == AutoKickWarnings) && (AutoKickAfterWarn == 1))
                        Kick(PlayerToWarn);
                }
                else
                    SendClientMessage(playerid, 0xFF0000FF, "That player isn't online");
        }
        else
            return 0;
    }
    else
        return 0;

    // Let the server know that this was a valid command
    return 1;
}
I added two things. It should be easy to see what I added.
Thanks its working! +rep!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)