/** * Handle Chat Messages */ public handleSayText( id ) { new s_Message[192]
// get the message read_args( s_Message, charsmax(s_Message) )
// clean up remove_quotes( s_Message ) trim( s_Message )
// no message? we're done if ( !s_Message[0] ) return PLUGIN_HANDLED
// only process if we found a command if ( isCommand( s_Message, strlen( s_Message ) ) ) { // go through all registered chat commands for ( new i; i < sizeof g_ChatCommands; i++ ) { // check if it's a registered command of this plugin if ( equali( g_ChatCmd, g_ChatCommands[i] ) ) { // debug client_print( 0, print_chat, "Command: %s", g_ChatCmd ) client_print( 0, print_chat, "Argument: %s", g_ChatArg ) } }
new s_cmd[32] read_argv( 0, s_cmd, charsmax(s_cmd) )
new is_TeamMessage = s_cmd[3] == '_' ? true : false new is_UserAlive = is_user_alive( id ) new CsTeams:id_UserTeam = cs_get_user_team( id )
new i_Players[32], i_PlayersCount new c_MsgType = id ? MSG_ONE : MSG_ALL new ChatChannel = getChatChannel( id, id_UserTeam, is_TeamMessage )
get_players( i_Players, i_PlayersCount, "ch" )
for ( new i; i < i_PlayersCount; i++ ) { if ( is_UserAlive == is_user_alive( i_Players[i] ) ) { if ( !is_TeamMessage || ( is_TeamMessage && id_UserTeam == cs_get_user_team( i_Players[i] ) ) ) { // actually write the message now emessage_begin( c_MsgType, g_MsgSayText, _, i_Players[i] )
ewrite_byte( id ) // Channel, e.g. #Cstrike_Chat_All ewrite_string( g_ChatChannelTypes[ChatChannel] ) // Username ewrite_string( "^x04Username" ) // Message ewrite_string( s_Message )
emessage_end() } } }
return PLUGIN_HANDLED }
return PLUGIN_CONTINUE }
/** * Check if the message is actually a command, e.g. /rank */ bool:isCommand( const p_msg[], p_msg_len ) { // check if first character is a slash if ( !strfind( p_msg, "/", 0, 0 ) ) { // set g_ChatCmd to passed command strtok( p_msg, g_ChatArg, p_msg_len, g_ChatCmd, p_msg_len, '/', 1 )
// set g_ChatArg to passed argument strtok( p_msg, g_ChatCmd, p_msg_len, g_ChatArg, p_msg_len, ' ', 1 )