2014-08-04 12:12:15 +00:00
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// Info. Messages Plugin
//
2004-01-31 20:56:22 +00:00
2004-03-05 19:35:38 +00:00
# include <amxmodx>
2004-03-07 14:30:53 +00:00
# include <amxmisc>
2004-01-31 20:56:22 +00:00
2022-07-11 13:22:45 +00:00
const MAX_MSG_LEN = 384 ;
const TASK_MSG = 12345 ;
2004-01-31 20:56:22 +00:00
2022-07-11 13:22:45 +00:00
enum _ : MessageInfo
{
Message [ MAX_MSG_LEN ] ,
R ,
G ,
B
}
new Array : g_messages ;
new g_messagesNum ;
new g_hudObject ;
new g_current ;
2004-01-31 20:56:22 +00:00
2022-07-11 13:22:45 +00:00
new g_hostname [ 64 ] ;
new Float : g_amx_freq_imessage ;
new Float : g_amx_imessage_x_pos ;
new Float : g_amx_imessage_y_pos ;
new Float : g_amx_imessage_holdtime ;
new g_amx_imessage_only_dead ;
2007-04-24 18:18:45 +00:00
2005-09-12 21:06:24 +00:00
public plugin_init ( )
{
2022-07-11 13:22:45 +00:00
register_plugin ( " Info. Messages " , AMXX_VERSION_STR , " AMXX Dev Team " ) ;
register_srvcmd ( " amx_imessage " , " setMessage " , _ , " <message> <color in RRRGGGBBB format> " ) ;
register_dictionary ( " imessage.txt " ) ;
register_dictionary ( " common.txt " ) ;
g_messages = ArrayCreate ( MessageInfo ) ;
g_hudObject = CreateHudSyncObj ( ) ;
bind_pcvar_num ( create_cvar ( " amx_imessage_only_dead " , " 0 " , _ , " Set to 1 to show info messages only to dead clients " , true , 0.0 , true , 1.0 ) , g_amx_imessage_only_dead ) ;
bind_pcvar_float ( create_cvar ( " amx_freq_imessage " , " 180 " , _ , " Frequency in seconds of info messages " , true , 0.0 ) , g_amx_freq_imessage ) ;
bind_pcvar_float ( create_cvar ( " amx_imessage_x_pos " , " -1.0 " , _ , " X position for info messages " , true , - 1.0 , true , 1.0 ) , g_amx_imessage_x_pos ) ;
bind_pcvar_float ( create_cvar ( " amx_imessage_y_pos " , " 0.2 " , _ , " Y position for info messages " , true , - 1.0 , true , 1.0 ) , g_amx_imessage_y_pos ) ;
bind_pcvar_float ( create_cvar ( " amx_imessage_holdtime " , " 12.0 " , _ , " Hold time for info messages " , true , 0.0 ) , g_amx_imessage_holdtime ) ;
bind_pcvar_string ( get_cvar_pointer ( " hostname " ) , g_hostname , charsmax ( g_hostname ) ) ;
new lastinfo [ 8 ] ;
get_localinfo ( " lastinfomsg " , lastinfo , charsmax ( lastinfo ) ) ;
g_current = str_to_num ( lastinfo ) ;
set_localinfo ( " lastinfomsg " , " " ) ;
2004-01-31 20:56:22 +00:00
}
2005-09-12 21:06:24 +00:00
public infoMessage ( )
{
2007-04-24 18:18:45 +00:00
// No messages, just get out of here
2022-07-11 13:22:45 +00:00
if ( ! g_messagesNum )
2007-04-24 18:18:45 +00:00
{
return ;
}
2022-07-11 13:22:45 +00:00
// If the last message is reached, go back to the first one
if ( g_current > = g_messagesNum )
{
g_current = 0 ;
}
2007-04-24 18:18:45 +00:00
2022-07-11 13:22:45 +00:00
static message [ MessageInfo ] ;
ArrayGetArray ( g_messages , g_current , message ) ;
replace_stringex ( message [ Message ] , charsmax ( message [ Message ] ) , " %hostname% " , g_hostname ) ;
2007-04-24 18:18:45 +00:00
2022-07-11 13:22:45 +00:00
set_hudmessage ( message [ R ] , message [ G ] , message [ B ] , g_amx_imessage_x_pos , g_amx_imessage_y_pos , 0 , 0.5 , g_amx_imessage_holdtime , 2.0 , 2.0 , - 1 ) ;
if ( g_amx_imessage_only_dead )
{
new players [ MAX_PLAYERS ] , pnum ;
get_players_ex ( players , pnum , GetPlayers_ExcludeAlive ) ;
for ( new player , i ; i < pnum ; i + + )
{
player = players [ i ] ;
ShowSyncHudMsg ( player , g_hudObject , message [ Message ] ) ;
console_print ( player , message [ Message ] ) ;
}
}
else
{
ShowSyncHudMsg ( 0 , g_hudObject , message [ Message ] ) ;
console_print ( 0 , message [ Message ] ) ;
}
2007-04-24 18:18:45 +00:00
2022-07-11 13:22:45 +00:00
g_current + + ;
2005-09-12 21:06:24 +00:00
2022-07-11 13:22:45 +00:00
if ( g_amx_freq_imessage > 0.0 )
{
set_task ( g_amx_freq_imessage , " infoMessage " , TASK_MSG ) ;
}
2004-01-31 20:56:22 +00:00
}
2005-09-12 21:06:24 +00:00
public setMessage ( )
{
2022-07-11 13:22:45 +00:00
remove_task ( TASK_MSG ) ;
2005-09-12 21:06:24 +00:00
2022-07-11 13:22:45 +00:00
static message [ MessageInfo ] ;
read_argv ( 1 , message [ Message ] , charsmax ( message [ Message ] ) ) ;
replace_string ( message [ Message ] , charsmax ( message [ Message ] ) , " \n " , " ^n " ) ;
new fullcolor [ 10 ] ;
read_argv ( 2 , fullcolor , charsmax ( fullcolor ) ) ;
message [ B ] = str_to_num ( fullcolor [ 6 ] ) ;
fullcolor [ 6 ] = 0 ;
message [ G ] = str_to_num ( fullcolor [ 3 ] ) ;
fullcolor [ 3 ] = 0 ;
message [ R ] = str_to_num ( fullcolor [ 0 ] ) ;
fullcolor [ 0 ] = 0 ;
g_messagesNum + + ;
ArrayPushArray ( g_messages , message ) ;
2005-09-12 21:06:24 +00:00
2022-07-11 13:22:45 +00:00
if ( g_amx_freq_imessage > 0.0 )
{
set_task ( g_amx_freq_imessage , " infoMessage " , TASK_MSG ) ;
}
2005-09-12 21:06:24 +00:00
2022-07-11 13:22:45 +00:00
return PLUGIN_HANDLED ;
2004-01-31 20:56:22 +00:00
}
2005-09-12 21:06:24 +00:00
public plugin_end ( )
{
2022-07-11 13:22:45 +00:00
ArrayDestroy ( g_messages ) ;
set_localinfo ( " lastinfomsg " , fmt ( " %i " , g_current ) ) ;
}