Raised This Month: $ Target: $400
 0% 

Admin color chat help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
hardboy
Member
Join Date: Jun 2014
Location: Greece
Old 02-27-2015 , 14:21   Admin color chat help
Reply With Quote #1

I need add who msg on admin chat ( Player hardboy: hello and ADMIN hardboy: hello)


PHP Code:
//***************************************************************
//*    Standard Admin Color Chat v. 1.1.1 for AMXX                 *
//*    by Martin J. Van der Cal                                *
//*                                                *
//*    Standard admin chat in color                            *
//*                                                *
//*    Copyright (C) 2005, Martin J. Van der Cal                    *
//*    This plugin is under the GNU General Public License, read        *
//*    "Std Admin Color Chat Readme.doc" for further information.        *
//*                                                *
//*    std_admin_color_chat.sma                            *
//*                                                *
//***************************************************************

#include <amxmodx>
#include <amxmisc>

#define MAX_MESSAGE_SIZE            256
#define MAX_COMMAND_SIZE            10
#define AMX_CHAT_CHAR_RECOGNITION    '@'        // What character we look for when we decide if the message should go to the admins
#define AMX_PSAY_CHAR_RECOGNITION    '#'        // Character to look for when sending PMs

// Error Codes
#define TOO_MANY_MATCHED            -1
#define NONE_MATCHED                -2

#define AMX_PSAY_FINDNICK_ERROR_TOO_MANY    "^x04[ACC] says: Error <Too many found>"
#define AMX_PSAY_FINDNICK_ERROR_NONE        "^x04[ACC] says: Error <None found>"
#define AMX_PSAY_FINDNICK_ERROR_UNKNOWN        "^x04[ACC] says: Error <Unknown error>"

// Text defines, PREFIX is text before and SUFFIX is text after the username in a message.
// Feel free to change these. Also note that ^x01 and ^x04 is color codes.
#define AMX_CHAT_PREFIX                    "^x04"                // Text before the username in amx_chat command
#define AMX_CHAT_SUFFIX                    " Admin Chat: "    // Text after the username in amx_chat command
#define AMX_PSAY_SEND_PREFIX            "^x04"                // Text before the username in a PM that you send
#define AMX_PSAY_SEND_SUFFIX            " PMs you: ^x01"    // Text after the username in a PM that you send
#define AMX_PSAY_BACK_TO_SENDER_PREFIX    "^x04You PM "        // Text before the username in the confimation notice of the PM you send
#define AMX_PSAY_BACK_TO_SENDER_SUFFIX    ": ^x01"            // Text after the username in the confimation notice of the PM you send
#define AMX_SAY_PREFIX                    "^x04"                // Text before the username in the amx_say command
#define AMX_SAY_SUFFIX                    " tells all: ^x01"    // Text after the username in the amx_say command
// E. g. an amx_chat message with the current settings will be as following example shows
// Command by player with the nick "Martin Van der Cal":
// amx_chat Hello admins
// Shows as:
// Martin Van der Cal tells admins: Hello admins
// Also note that with only the color code in the prefix the whole line will show as green to all admins

#define MAX_CLR 10

new g_Colors[MAX_CLR][] = {"COL_WHITE""COL_RED""COL_GREEN""COL_BLUE""COL_YELLOW""COL_MAGENTA""COL_CYAN""COL_ORANGE""COL_OCEAN""COL_MAROON"}
new 
g_Values[MAX_CLR][] = {{255255255}, {25500}, {02550}, {00255}, {2552550}, {2550255}, {0255255}, {227968}, {4589116}, {1034438}}
new 
Float:g_Pos[4][] = {{0.00.0}, {0.050.55}, {-1.00.2}, {-1.00.7}}

new 
amx_show_activity;
new 
gmsgSayText
new g_msgChannel
new g_AdminChatFlag ADMIN_CHAT;
public 
plugin_init()
{
    
register_plugin("Admin chat color""1.1.1""unknow")

    
register_dictionary("adminchat.txt")
    
register_dictionary("common.txt")
    
register_clcmd("say""cmdSayChat"ADMIN_CHAT"@[@|@|@][w|r|g|b|y|m|c]<text> - displays hud message")
    
register_clcmd("say_team",    "SayTeamHandler",    0,            "@ <message> - Displays message to admins")
    
    
register_concmd("amx_say",    "cmdSayChat",        ADMIN_CHAT,    "<message> - Displays message to all players")
    
register_concmd("amx_psay",    "ConCmdACCPM",        ADMIN_CHAT,    "# <name or #userid> <message> - Sends a PM");
    
register_concmd("amx_chat",    "ConCmdACCAdmins",    ADMIN_CHAT,    "<message> - Displays message to admins");
    
register_concmd("amx_tsay""cmdTsay"ADMIN_CHAT"<color> <message> - sends left side hud message to all players")
    
register_concmd("amx_csay""cmdTsay"ADMIN_CHAT"<color> <message> - sends center hud message to all players")
    
gmsgSayText get_user_msgid("SayText")
    
amx_show_activity get_cvar_pointer("amx_show_activity");
    
    if (
amx_show_activity == 0)
    {
        
amx_show_activity register_cvar("amx_show_activity""2");
    }

}

public 
cmdTsay(idlevelcid)
{
    if (!
cmd_access(idlevelcid3))
        return 
PLUGIN_HANDLED
    
    
new cmd[16], color[16], color2[16], message[192], name[32], authid[32], userid 0
    
    read_argv
(0cmd15)
    new 
bool:tsay = (tolower(cmd[4]) == 't')
    
    
read_args(message191)
    
remove_quotes(message)
    
parse(messagecolor15)
    
    new 
found 00
    
new lang[3], langnum get_langsnum()

    for (new 
0MAX_CLR; ++i)
    {
        for (new 
0langnumj++)
        {
            
get_lang(jlang)
            
format(color215"%L"langg_Colors[i])
            
            if (
equali(colorcolor2))
            {
                
i
                found 
1
                
break
            }
        }
        if (
found == 1)
            break
    }
    
    new 
length found ? (strlen(color) + 1) : 0
    
    
if (++g_msgChannel || g_msgChannel 3)
        
g_msgChannel 3

    
new Float:verpos = (tsay 0.55 0.1) + float(g_msgChannel) / 35.0
    
    get_user_authid
(idauthid31)
    
get_user_name(idname31)
    
userid get_user_userid(id)
    
set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], tsay 0.05 : -1.0verpos06.06.00.50.15, -1)

    switch ( 
get_pcvar_num(amx_show_activity) )
    {
        case 
34:
        {
            new 
maxpl get_maxplayers();
            for (new 
pl 1pl <= maxplpl++)
            {
                if (
is_user_connected(pl) && !is_user_bot(pl))
                {
                    if (
is_user_admin(pl))
                    {
                        
show_hudmessage(pl"%s :   %s"namemessage[length])
                        
client_print(plprint_notify"%s :   %s"namemessage[length])
                    }
                    else
                    {
                        
show_hudmessage(pl"%s"message[length])
                        
client_print(plprint_notify"%s"message[length])
                    }
                }
            }
            
console_print(id"%s :  %s"namemessage[length])
        }
        case 
2:
        {
            
show_hudmessage(0"%s :   %s"namemessage[length])
            
client_print(0print_notify"%s :   %s"namemessage[length])
            
console_print(id"%s :  %s"namemessage[length])
        }
        default:
        {
            
show_hudmessage(0"%s"message[length])
            
client_print(0print_notify"%s"message[length])
            
console_print(id"%s"message[length])
        }
    }

    
log_amx("Chat: ^"%s<%d><%s><>^" %s ^"%s^""nameuseridauthidcmd[4], message[length])
    
log_message("^"%s<%d><%s><>^" triggered ^"%s^" (text ^"%s^") (color ^"%s^")"nameuseridauthidcmdmessage[length], color2)

    return 
PLUGIN_HANDLED
}

public 
cmdSayChat(id)
{
    if (!
access(idg_AdminChatFlag))
    {
        return 
PLUGIN_CONTINUE
    
}
    
    new 
said[6], 0
    read_argv
(1said5)
    
    while (
said[i] == '@')
    {
        
i++
    }
    
    if (!
|| 3)
    {
        return 
PLUGIN_CONTINUE
    
}
    
    new 
message[192], 0
    read_args
(message191)
    
remove_quotes(message)
    
    switch (
said[i])
    {
        case 
'r'1
        
case 'g'2
        
case 'b'3
        
case 'y'4
        
case 'm'5
        
case 'c'6
        
case 'o'7
    
}
    
    new 
ni
    
if (a)
    {
        
n++
        
s++
    }
    while (
said[s] && isspace(said[s]))
    {
        
n++
        
s++
    }
    

    new 
name[32], authid[32], userid
    
    get_user_authid
(idauthid31)
    
get_user_name(idname31)
    
userid get_user_userid(id)
    
    
log_amx("Chat: ^"%s<%d><%s><>^" tsay ^"%s^""nameuseridauthidmessage[n])
    
log_message("^"%s<%d><%s><>^" triggered ^"amx_tsay^" (text ^"%s^") (color ^"%L^")"nameuseridauthidmessage[n], "en"g_Colors[a])
    
    if (++
g_msgChannel || g_msgChannel 3)
    {
        
g_msgChannel 3
    
}
    
    new 
Float:verpos g_Pos[i][1] + float(g_msgChannel) / 35.0
    
    set_hudmessage
(g_Values[a][0], g_Values[a][1], g_Values[a][2], g_Pos[i][0], verpos06.06.00.50.15, -1)

    switch ( 
get_pcvar_num(amx_show_activity) )
    {
        case 
34:
        {
            new 
maxpl get_maxplayers();
            for (new 
pl 1pl <= maxplpl++)
            {
                if (
is_user_connected(pl) && !is_user_bot(pl))
                {
                    if (
is_user_admin(pl))
                    {
                        
show_hudmessage(pl"%s :   %s"namemessage[n])
                        
client_print(plprint_notify"%s :   %s"namemessage[n])
                    }
                    else
                    {
                        
show_hudmessage(pl"%s"message[n])
                        
client_print(plprint_notify"%s"message[n])
                    }
                }
            }
        }
        case 
2:
        {
            
show_hudmessage(0"%s :   %s"namemessage[n])
            
client_print(0print_notify"%s :   %s"namemessage[n])
        }
        default:
        {
            
show_hudmessage(0"%s"message[n])
            
client_print(0print_notify"%s"message[n])
        }
    }

    return 
PLUGIN_HANDLED
}

// Runs if anything is said in team_say
public SayTeamHandler(iPlayerID,id)
{
    new 
sTemp[MAX_MESSAGE_SIZE]
    new 
sCmd[MAX_COMMAND_SIZE]
    new 
sMessage[MAX_MESSAGE_SIZE]
    new 
message[192], name[32], authid[32], userid
    
    read_args
(message191)
    
remove_quotes(message)
    
get_user_authid(idauthid31)
    
get_user_name(idname31)
    
userid get_user_userid(id)
    
read_argv(1sTempMAX_MESSAGE_SIZE 1)
    
    
// if the chat starts with AMX_CHAT_CHAR_RECOGNITION then we are supposed to send it to all admins
    
if ( sTemp[0] == AMX_CHAT_CHAR_RECOGNITION )
    {
        if (
is_user_admin(iPlayerID))
            
format(message191"(%L) %s :  %s"id"ADMIN"namemessage[1])
        else
            
format(message191"(%L) %s :  %s"id"PLAYER"namemessage[1])
        
// Somehow I cant get trim to work as I want, so if there are a space after @, then I had to resort to using strbreak
        
if (sTemp[1] == ' ')
        {
            
// Remove the chat recognition chars, sMessage will contain the message and the message only
            
strbreak(sTempsCmdMAX_COMMAND_SIZE-1sMessageMAX_MESSAGE_SIZE-1)
        }
        else
        {
            
// Remove the chat recognition chars without the space.
            
sTemp[0] = ' '
            
trim(sTemp)
            
copy(sMessageMAX_MESSAGE_SIZE-1sTemp)
        }
        
        
remove_quotes(sMessage)
        
        
SendAdminMessage(sMessageiPlayerID)
        
        return 
PLUGIN_HANDLED
    
}
    else if ( 
get_user_flags(iPlayerID) & ADMIN_CHAT )
    {
        
// if the chat starts with AMX_PSAY_CHAR_RECOGNITION. That is, if an admin wants to send a PM
        
if ( sTemp[0] == AMX_PSAY_CHAR_RECOGNITION )
        {
            if (
sTemp[1] == ' ')
            {
                
// Remove the chat recognition chars
                
strbreak(sTempsCmdMAX_COMMAND_SIZE-1sMessageMAX_MESSAGE_SIZE-1)
            }
            else
            {
                
// Remove the chat recognition chars without the space
                
sTemp[0] = ' '
                
trim(sTemp)
                
copy(sMessageMAX_MESSAGE_SIZE-1sTemp)
            }
            
            
BaseSendPM(sMessageiPlayerID)

            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_CONTINUE
}

// Console command, amx_say <message>
public ConCmdACCSay(iPlayerID)
{
    
// if the user is an admin with ADMIN_CHAT flag
    
if ( get_user_flags(iPlayerID) & ADMIN_CHAT )
    {
        new 
sMessage[MAX_MESSAGE_SIZE]
        
read_args(sMessageMAX_MESSAGE_SIZE-1)
        
remove_quotes(sMessage)
        
        new 
sUser[MAX_MESSAGE_SIZE]
        
get_user_name(iPlayerIDsUserMAX_MESSAGE_SIZE-1)
        
        
// The message that we will actually send
        
new sRealMessage[MAX_MESSAGE_SIZE] = AMX_SAY_PREFIX
        add
(sRealMessageMAX_MESSAGE_SIZE-1sUser)
        
add(sRealMessageMAX_MESSAGE_SIZE-1AMX_SAY_SUFFIX)
        
add(sRealMessageMAX_MESSAGE_SIZE-1sMessageMAX_MESSAGE_SIZE-strlen(sRealMessage)-1)

        
// Get the steamid for the sake of logging
        
new sSendSteamID[MAX_MESSAGE_SIZE]
        
get_user_authid(iPlayerIDsSendSteamIDMAX_MESSAGE_SIZE-1)
        
        
// Get all current players
        
new nCurPlayers
        
new iArrCurPlayers[32]
        
get_players(iArrCurPlayersnCurPlayers"c")
        
        
// Log the message
        
log_amx("Chat (ALL), From: ^"%s<%d><%s><>^" Message: ^"%s^""sUseriPlayerIDsSendSteamIDsMessage)
        
log_message("^"%s<%d><%s><>^" triggered ^"amx_say^" (text ^"%s^")",sUseriPlayerIDsSendSteamIDsMessage)
    
        
// For every player
        
for (new iID 0iID nCurPlayersiID++)
            
SendMessage(sRealMessageiArrCurPlayers[iID]) // Send the message to the player
    
}
    return 
PLUGIN_HANDLED;
}

// Console command, amx_psay <nick or steamid> <message>
public ConCmdACCPM(iPlayerID)
{
    
// if the user is an admin
    
if ( get_user_flags(iPlayerID) & ADMIN_CHAT )
    {
        new 
sArgs[MAX_MESSAGE_SIZE]
        
read_args(sArgsMAX_MESSAGE_SIZE-1)

        
BaseSendPM(sArgsiPlayerID)
    }
    return 
PLUGIN_HANDLED
}

// Console Command, amx_chat <message>
public ConCmdACCAdmins(iPlayerID)
{
    new 
sArgs[MAX_MESSAGE_SIZE]
    
read_args(sArgsMAX_MESSAGE_SIZE-1)
    
remove_quotes(sArgs)
    
    
SendAdminMessage(sArgsiPlayerID)

    return 
PLUGIN_HANDLED
}

// Returns the id of the player, IF and only IF it found ONLY one player with which contains the nick provided, otherwise it returns less than 0
FindPlayerWithNick(sNick[MAX_MESSAGE_SIZE])
{
    new 
iArrPlayers[32]
    new 
nPlayers
    
new sUser[MAX_MESSAGE_SIZE]
    new 
iPlayerID = -100
    get_players
(iArrPlayersnPlayers"c")
    
    
// for every player
    
for (new iID 0iID nPlayersiID++)
    {
        
get_user_name(iArrPlayers[iID], sUserMAX_MESSAGE_SIZE-1)

        
// Check if their nick contains the nick part provided, ignore caps
        
if ( containi(sUsersNick) >= 0  || equali(sUser,sNick) )
        {
            
// if we havent found anyone yet, else return we have found too many
            
if (iPlayerID == -100)
                
iPlayerID iArrPlayers[iID]
            else
                return 
TOO_MANY_MATCHED
        
}
    }
    if (
iPlayerID == -100)
        return 
NONE_MATCHED
    
else
        return 
iPlayerID
        
    
return 0
}

// Returns the id of the player with the correct steamid if it find any, otherwise it returns less than 0
FindPlayerWithSteamID(sSteamID[MAX_MESSAGE_SIZE])
{
    new 
iArrPlayers[32]
    new 
nPlayers
    
new sUser[MAX_MESSAGE_SIZE]
    new 
iResult
    get_players
(iArrPlayersnPlayers"c")

    for (new 
iID 0iID nPlayersiID++)
    {
        
get_user_authid(iArrPlayers[iID], sUserMAX_MESSAGE_SIZE-1)
        
// The steam id must be strictly equal
        
iResult equal(sUsersSteamID)
        if ( 
iResult == )
        {
            
// Since steamid is unique, we dont have to check anyone else
            
return iArrPlayers[iID]
        }
    }
    return 
NONE_MATCHED
}

// This is where we build the message to be sent, logs the message and find out who the admins are
SendAdminMessage(sMessage[], iSenderID)
{
    
// The message that is going to be sent. ^x04 is green color
    
new sRealMessage[MAX_MESSAGE_SIZE] = AMX_CHAT_PREFIX

    
// Get the username of the sender
    
new sUser[MAX_MESSAGE_SIZE]
    
get_user_name(iSenderIDsUserMAX_MESSAGE_SIZE 1)
    
    
// Add user, "user friendly text" and the message to the message we are going to send
    
add(sRealMessageMAX_MESSAGE_SIZEsUser)
    
add(sRealMessageMAX_MESSAGE_SIZEAMX_CHAT_SUFFIX)
    
addsRealMessageMAX_MESSAGE_SIZE, (sMessage), (MAX_MESSAGE_SIZE-strlen(sRealMessage)-1) )

    
// Get the steamid for the sake of logging
    
new sSendSteamID[MAX_MESSAGE_SIZE]
    
get_user_authid(iSenderIDsSendSteamIDMAX_MESSAGE_SIZE-1)
    
    
// Get all current players
    
new nCurPlayers
    
new iArrCurPlayers[32]
    
get_players(iArrCurPlayersnCurPlayers"c")
    
    
// Log the message
    
log_amx("ADMINS amx_chat, From: ^"%s<%d><%s><>^" Message: ^"%s^""sUseriSenderIDsSendSteamIDsMessage)
    
log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")",sUseriSenderIDsSendSteamIDsMessage)

    
// For every player
    
for (new iID 0iID nCurPlayersiID++)
        if ( 
get_user_flags(iArrCurPlayers[iID]) & ADMIN_CHAT // If the player is an admin
            
SendMessage(sRealMessageiArrCurPlayers[iID]) // Send the message to the player(admin)
}

// This is where we prepare the PM, breaks out the nick and the message from the original message,
// finds who the reciever is and sends it. Also sends error if none or several matches found
BaseSendPM(sArgs[], iPlayerID)
{
    new 
sNick[MAX_MESSAGE_SIZE]
    new 
sMessage[MAX_MESSAGE_SIZE]
    
    
// Get the nick/steamid
    
strbreak(sArgssNickMAX_MESSAGE_SIZE-1sMessageMAX_MESSAGE_SIZE-1)
    
    
// Remove all those nasty quotes ! ! !
    
remove_quotes(sNick)
    
replace(sMessageMAX_MESSAGE_SIZE-1"^"", "")

    // Get the players id by comparing the players nick with the one the user supplied
    new iResult
    if ( equal(sNick, "
STEAM_", 6) )
        iResult = FindPlayerWithSteamID(sNick)
    else
        iResult = FindPlayerWithNick(sNick)

    if ( iResult >= 0 ) // if we found "
ONE" player with that nick, then we send the PM
    {
        SendPM(sMessage, iPlayerID, iResult)
    }
    else // if we found none or several with that nick. Then we send back an error message to the admin
    {
        new sSendSteamID[MAX_MESSAGE_SIZE]
        get_user_authid(iPlayerID, sSendSteamID, MAX_MESSAGE_SIZE-1)
        
        if ( iResult == TOO_MANY_MATCHED )
            format(sMessage, MAX_MESSAGE_SIZE-1, AMX_PSAY_FINDNICK_ERROR_TOO_MANY)
        else if ( iResult == NONE_MATCHED )
            format(sMessage, MAX_MESSAGE_SIZE-1, AMX_PSAY_FINDNICK_ERROR_NONE)
        else
            format(sMessage, MAX_MESSAGE_SIZE-1, AMX_PSAY_FINDNICK_ERROR_UNKNOWN)
        
        // if the sender is an admin or infact the server itself.
        if ( equal(sSendSteamID, "
STEAM_", 6) )
            SendMessage(sMessage, iPlayerID)
        else
            server_print(sMessage)
    }
}

// Here we build the PM message, logs it and sends it
SendPM(sMessage[], iSenderID, iRecieverID)
{
    new sRealMessage[MAX_MESSAGE_SIZE] = AMX_PSAY_SEND_PREFIX

    // To the person
    new sUser[MAX_MESSAGE_SIZE]
    get_user_name(iSenderID, sUser, MAX_MESSAGE_SIZE - 1)
    
    add(sRealMessage, MAX_MESSAGE_SIZE-1, sUser)
    add(sRealMessage, MAX_MESSAGE_SIZE-1, AMX_PSAY_SEND_SUFFIX)
    add(sRealMessage, MAX_MESSAGE_SIZE-1, sMessage, MAX_MESSAGE_SIZE-strlen(sRealMessage)-1)

    new sRecvSteamID[MAX_MESSAGE_SIZE]
    new sSendSteamID[MAX_MESSAGE_SIZE]
    new sRecvName[MAX_MESSAGE_SIZE]
    
    get_user_authid(iSenderID, sSendSteamID, MAX_MESSAGE_SIZE-1)
    get_user_authid(iRecieverID, sRecvSteamID, MAX_MESSAGE_SIZE-1)

    get_user_name(iRecieverID, sRecvName, MAX_MESSAGE_SIZE - 1)
    
    log_amx("
PM From: ^"%s<%d><%s><>^" To: ^"%s<%d><%s><>^" Message: ^"%s^"", sUser, iSenderID, sSendSteamID, sRecvName, iRecieverID, sRecvSteamID, sMessage)
    log_message("
^"%s<%d><%s><>^" triggered ^"amx_psay^" against ^"%s<%d><%s><>^" (text ^"%s^")",
        sUser, iSenderID, sSendSteamID, sRecvName, iRecieverID, sRecvSteamID, sMessage)

    SendMessage(sRealMessage, iRecieverID)
    
    // And to the admin who sent it
    new sToAdmin[MAX_MESSAGE_SIZE] = AMX_PSAY_BACK_TO_SENDER_PREFIX
    add(sToAdmin, MAX_MESSAGE_SIZE-1, sRecvName)
    add(sToAdmin, MAX_MESSAGE_SIZE-1, AMX_PSAY_BACK_TO_SENDER_SUFFIX)
    add(sToAdmin, MAX_MESSAGE_SIZE-1, sMessage, MAX_MESSAGE_SIZE-strlen(sToAdmin)-1)

    // if the sender is an admin or infact the server
    if ( equal(sSendSteamID, "
STEAM_", 6) )
        SendMessage(sToAdmin, iSenderID)
    else
        server_print(sToAdmin)
}

// General method for sending chat messages, params are the message to be sent and the id of the player who should get it
SendMessage(sMessage[], iRecieverID)
{
    message_begin(MSG_ONE, gmsgSayText, {0,0,0}, iRecieverID)
    write_byte(iRecieverID)
    write_string(sMessage)
    message_end()


Last edited by hardboy; 02-27-2015 at 14:23.
hardboy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode