1010#tryinclude <sourcecomms>
1111#define REQUIRE_PLUGIN
1212
13- #define PLUGIN_VERSION " 6.5.1"
13+ #define PLUGIN_VERSION " 6.5.2"
14+ #define PLUGIN_PREFIX " \x03 Chat Annotations\x01 "
15+ #define CMD_TOGGLE_DESC " Toggle Chat Annotations visibility for yourself."
1416
1517public Plugin myinfo =
1618{
3032 annotation_show_cmd ,
3133 annotation_interval ,
3234 annotation_life ,
35+ annotation_dynamic_life ,
3336 annotation_limit ,
3437 annotation_max_len ,
3538 annotation_remove ,
4144ConVar g_ConVars [MAX_CONVARS ];
4245
4346Handle g_hTimerAnn = null ;
44- char g_cLastMsg [MAXPLAYERS +1 ][256 ];
45- int g_iAnnID [MAXPLAYERS +1 ];
46- int g_iAnnIDMeow = 1 ;
47- int g_iBaseComm = 0 ;
48- int g_iSourceComms = 0 ;
47+ char g_szLastMsg [MAXPLAYERS +1 ][256 ];
48+ int g_iAnnPlayerID [MAXPLAYERS +1 ];
49+ int g_iAnnID = 1 ;
50+ bool g_bBaseComm , g_bSourceComms ;
4951bool g_bAnnIsTeam [MAXPLAYERS +1 ];
5052bool g_bViewerSee [MAXPLAYERS +1 ][MAXPLAYERS +1 ];
5153bool g_bPlayerMoved [MAXPLAYERS +1 ];
54+ bool g_bAnnEnabled [MAXPLAYERS +1 ] = {true , ...};
5255float g_flAnnN [MAXPLAYERS +1 ];
5356float g_flLastPos [MAXPLAYERS +1 ][3 ];
5457float g_flLastAng [MAXPLAYERS +1 ][3 ];
@@ -58,22 +61,31 @@ public void OnPluginStart()
5861{
5962 CreateConVar (" sm_cvann_version" , PLUGIN_VERSION , " Version of TF2Chat Annotations." , FCVAR_NOTIFY | FCVAR_DONTRECORD );
6063
61- g_ConVars [plugin_enabled ] = CreateConVar (" sm_cvann_enable" , " 1" , " TF2Chat Annotations. (1 = Enable, 0 = Disable)" , FCVAR_NONE , true , 0.0 , true , 1.0 );
62- g_ConVars [annotation_range ] = CreateConVar (" sm_cvann_range" , " 25" , " Distance to See Annotations." , FCVAR_NONE , true , 0.0 );
63- g_ConVars [annotation_show_range ] = CreateConVar (" sm_cvann_show_range" , " 0" , " Show Distance to speaker in Annotations. (1 = Enable, 0 = Disable)" , FCVAR_NONE , true , 0.0 , true , 1.0 );
64- g_ConVars [annotation_show_msg ] = CreateConVar (" sm_cvann_show_msg" , " 1" , " Allow Players to See their own Chat Annotation. (1 = Enable, 0 = Disable)" , FCVAR_NONE , true , 0.0 , true , 1.0 );
65- g_ConVars [annotation_show_cmd ] = CreateConVar (" sm_cvann_show_cmd" , " 1" , " Command Visibility. (0 = Hide ! and /, 1 = Show !, 2 = Show /, 3 = Show ! and /)" , FCVAR_NONE , true , 0.0 , true , 3.0 );
66- g_ConVars [annotation_interval ] = CreateConVar (" sm_cvann_interval" , " 0.5" , " Update interval for checking Annotation Visibility." , FCVAR_NONE , true , 0.5 );
67- g_ConVars [annotation_life ] = CreateConVar (" sm_cvann_lifetime" , " 10.0" , " How long Message stays visible (Seconds)." , FCVAR_NONE , true , 0.0 );
68- g_ConVars [annotation_limit ] = CreateConVar (" sm_cvann_limit" , " 5" , " Maximum Number of Annotations shown at same time. (0 = Unlimited)" , FCVAR_NONE , true , 0.0 );
69- g_ConVars [annotation_max_len ] = CreateConVar (" sm_cvann_maxlen" , " 64" , " Maximum Length of Chat Message shown in Annotations." , FCVAR_NONE , true , 0.0 , true , 128.0 );
70- g_ConVars [annotation_remove ] = CreateConVar (" sm_cvann_entity_remove" , " 1900" , " Remove All Annotations if Entity count reaches this." , FCVAR_NONE , true , 0.0 , true , 2048.0 );
71- g_ConVars [annotation_block ] = CreateConVar (" sm_cvann_entity_block" , " 2000" , " Block New Annotations if Entity count reaches this." , FCVAR_NONE , true , 0.0 , true , 2048.0 );
64+ g_ConVars [plugin_enabled ] = CreateConVar (" sm_cvann_enable" , " 1" , " TF2Chat Annotations. (1 = Enable, 0 = Disable)" , _ , true , 0.0 , true , 1.0 );
65+ g_ConVars [annotation_range ] = CreateConVar (" sm_cvann_range" , " 25" , " Distance to See Annotations." , _ , true , 0.0 );
66+ g_ConVars [annotation_show_range ] = CreateConVar (" sm_cvann_show_range" , " 0" , " Show Distance to speaker in Annotations. (1 = Enable, 0 = Disable)" , _ , true , 0.0 , true , 1.0 );
67+ g_ConVars [annotation_show_msg ] = CreateConVar (" sm_cvann_show_msg" , " 1" , " Allow Players to See their own Chat Annotation. (1 = Enable, 0 = Disable)" , _ , true , 0.0 , true , 1.0 );
68+ g_ConVars [annotation_show_cmd ] = CreateConVar (" sm_cvann_show_cmd" , " 1" , " Command Visibility. (0 = Hide ! and /, 1 = Show !, 2 = Show /, 3 = Show ! and /)" , _ , true , 0.0 , true , 3.0 );
69+ g_ConVars [annotation_interval ] = CreateConVar (" sm_cvann_interval" , " 0.5" , " Update interval for checking Annotation Visibility." , _ , true , 0.5 );
70+ g_ConVars [annotation_life ] = CreateConVar (" sm_cvann_lifetime" , " 10.0" , " How long Message stays visible (Seconds). If 'sm_cvann_dynamic_lifetime' is set, it becomes the minimum lifetime." , _ , true , 0.0 );
71+ g_ConVars [annotation_dynamic_life ] = CreateConVar (" sm_cvann_dynamic_lifetime" , " 0.0" , " Whether the Chat Message should last based on its length. (0.0 = Disable, above 0.0 = Time Factor)" , _ , true , 0.0 );
72+ g_ConVars [annotation_limit ] = CreateConVar (" sm_cvann_limit" , " 5" , " Maximum Number of Annotations shown at same time. (0 = Unlimited)" , _ , true , 0.0 );
73+ g_ConVars [annotation_max_len ] = CreateConVar (" sm_cvann_maxlen" , " 64" , " Maximum Length of Chat Message shown in Annotations." , _ , true , 0.0 , true , 128.0 );
74+ g_ConVars [annotation_remove ] = CreateConVar (" sm_cvann_entity_remove" , " 1900" , " Remove All Annotations if Entity count reaches this." , _ , true , 0.0 , true , 2048.0 );
75+ g_ConVars [annotation_block ] = CreateConVar (" sm_cvann_entity_block" , " 2000" , " Block New Annotations if Entity count reaches this." , _ , true , 0.0 , true , 2048.0 );
76+
77+ RegConsoleCmd (" sm_annotation" , Command_ToggleAnnotations , CMD_TOGGLE_DESC );
78+ RegConsoleCmd (" sm_annotations" , Command_ToggleAnnotations , CMD_TOGGLE_DESC );
79+ RegConsoleCmd (" sm_annotate" , Command_ToggleAnnotations , CMD_TOGGLE_DESC );
80+ RegConsoleCmd (" sm_ann" , Command_ToggleAnnotations , CMD_TOGGLE_DESC );
7281
7382 HookEvent (" player_spawn" , Event_PlayerSpawn_Death );
7483 HookEvent (" player_death" , Event_PlayerSpawn_Death );
7584
85+ LoadTranslations (" common.phrases" );
86+
7687 AutoExecConfig (true , " tf_chat_annotations" );
88+
7789 StartAnnotation ();
7890}
7991
@@ -92,6 +104,26 @@ public void OnMapEnd()
92104 StopAnnotation ();
93105}
94106
107+ public Action Command_ToggleAnnotations (int client , int args )
108+ {
109+ if (client <= 0 || ! IsClientInGame (client ))
110+ {
111+ return Plugin_Handled ;
112+ }
113+
114+ g_bAnnEnabled [client ] = ! g_bAnnEnabled [client ];
115+ if (g_bAnnEnabled [client ])
116+ {
117+ PrintToChat (client , " \x01 [%s ]\x01 \x05 %t " , PLUGIN_PREFIX , " On" );
118+ }
119+ else
120+ {
121+ PrintToChat (client , " \x01 [%s ]\x01 \x05 %t " , PLUGIN_PREFIX , " Off" );
122+ HideAnnotation (client );
123+ }
124+ return Plugin_Handled ;
125+ }
126+
95127public void OnClientPutInServer (int client )
96128{
97129 HideAnnotation (client );
@@ -116,8 +148,8 @@ public void TF2_OnConditionAdded(int client, TFCond condition)
116148
117149void StartAnnotation ()
118150{
119- g_iBaseComm = LibraryExists (" basecomm" ) ? 1 : 0 ;
120- g_iSourceComms = LibraryExists (" sourcecomms" ) ? 1 : 0 ;
151+ g_bBaseComm = LibraryExists (" basecomm" );
152+ g_bSourceComms = LibraryExists (" sourcecomms" );
121153
122154 float interval = g_ConVars [annotation_interval ].FloatValue ;
123155 if (g_hTimerAnn == null )
@@ -128,8 +160,8 @@ void StopAnnotation()
128160{
129161 RemoveAnnotationAll ();
130162
131- g_iBaseComm = 0 ;
132- g_iSourceComms = 0 ;
163+ g_bBaseComm = false ;
164+ g_bSourceComms = false ;
133165
134166 if (g_hTimerAnn != null )
135167 {
@@ -174,15 +206,15 @@ bool ShowAnnotationPossible(int client)
174206bool ShowAnnotationAllowed (int client )
175207{
176208 #if defined _basecomm_included
177- if (g_iBaseComm == 1 )
209+ if (g_bBaseComm )
178210 {
179211 if (BaseComm_IsClientGagged (client ))
180212 return false ;
181213 }
182214 #endif
183215
184216 #if defined _sourcecomms_included
185- if (g_iSourceComms == 1 )
217+ if (g_bSourceComms )
186218 {
187219 int NOPE = view_as <int >(SourceComms_GetClientGagType (client ));
188220 if (NOPE == 1 || NOPE == 3 )
@@ -198,13 +230,14 @@ public void OnClientSayCommand_Post(int client, const char[] command, const char
198230 bool enable = g_ConVars [plugin_enabled ].BoolValue ;
199231 float range = g_ConVars [annotation_range ].FloatValue ;
200232 float life = g_ConVars [annotation_life ].FloatValue ;
233+ float dynamicLife = g_ConVars [annotation_dynamic_life ].FloatValue ;
201234 int cmd = g_ConVars [annotation_show_cmd ].IntValue ;
202235 int maxlen = g_ConVars [annotation_max_len ].IntValue ;
203236
204237 if (! enable || ! IsServerCrashImminent ())
205238 return ;
206239
207- if (range <= 0.0 || life <= 0.0 || maxlen <= 0 )
240+ if (range <= 0.0 || maxlen <= 0 )
208241 return ;
209242
210243 if (! ShowAnnotationPossible (client ) || ! ShowAnnotationAllowed (client ) || ! IsPlayerAlive (client ))
@@ -237,6 +270,25 @@ public void OnClientSayCommand_Post(int client, const char[] command, const char
237270 if (strlen (buffer ) > maxlen )
238271 buffer [maxlen ] = ' \0 ' ;
239272
273+ if (dynamicLife > 0.0 )
274+ {
275+ int len = strlen (buffer );
276+ float dynamic = (len * dynamicLife ) + dynamicLife ;
277+
278+ if (dynamic < life )
279+ life = life ;
280+ else
281+ life = dynamic ;
282+
283+ if (life <= 0.0 )
284+ return ;
285+ }
286+ else
287+ {
288+ if (life <= 0.0 )
289+ return ;
290+ }
291+
240292 bool isTeam = StrEqual (command , " say_team" );
241293 DisplayAnnotation (client , isTeam , buffer , life );
242294}
@@ -246,10 +298,10 @@ void DisplayAnnotation(int client, bool isTeam, const char[] sArgs, float life)
246298 HideAnnotation (client );
247299
248300 g_bAnnIsTeam [client ] = isTeam ;
249- g_iAnnIDMeow = (g_iAnnIDMeow % 0x7FFFFFFF ) + 1 ;
250- g_iAnnID [client ] = g_iAnnIDMeow ;
301+ g_iAnnID = (g_iAnnID % 0x7FFFFFFF ) + 1 ;
302+ g_iAnnPlayerID [client ] = g_iAnnID ;
251303
252- strcopy (g_cLastMsg [client ], sizeof (g_cLastMsg []), sArgs );
304+ strcopy (g_szLastMsg [client ], sizeof (g_szLastMsg []), sArgs );
253305 g_flAnnN [client ] = GetGameTime () + life ;
254306}
255307
@@ -273,7 +325,7 @@ public Action UpdateAnnotation(Handle timer)
273325 g_bPlayerMoved [i ] = IsClientInMotion (i );
274326 GetClientEyePosition (i , g_flCachePos [i ]);
275327
276- if (g_iAnnID [i ] != 0 )
328+ if (g_iAnnPlayerID [i ] != 0 )
277329 {
278330 if (! ShowAnnotationPossible (i ) || g_flAnnN [i ] <= now )
279331 HideAnnotation (i );
@@ -327,6 +379,9 @@ void YouSeeAnnotation(int viewer, int talker, bool talkerMoved, bool viewerMoved
327379 if (! IsClientInGame (viewer ) || IsFakeClient (viewer ))
328380 return ;
329381
382+ if (! g_bAnnEnabled [viewer ])
383+ return ;
384+
330385 bool seesArgs = g_ConVars [annotation_show_msg ].BoolValue ;
331386 if (viewer == talker && ! seesArgs )
332387 return ;
@@ -393,6 +448,9 @@ public bool TraceRayIgnoreClients(int entity, int mask, any data)
393448
394449bool MaxAnnotation (int viewer )
395450{
451+ if (! g_bAnnEnabled [viewer ])
452+ return true ;
453+
396454 int count = 0 ;
397455 int oldestTalker = - 1 ;
398456 int limit = g_ConVars [annotation_limit ].IntValue ;
@@ -442,8 +500,8 @@ void ShowAnnotation(int client, int viewer, float life)
442500 if (event )
443501 {
444502 event .SetInt (" follow_entindex" , client );
445- event .SetInt (" id" , g_iAnnID [client ]);
446- event .SetString (" text" , g_cLastMsg [client ]);
503+ event .SetInt (" id" , g_iAnnPlayerID [client ]);
504+ event .SetString (" text" , g_szLastMsg [client ]);
447505 event .SetFloat (" lifetime" , life );
448506 event .SetBool (" show_distance" , show );
449507 event .FireToClient (viewer );
@@ -452,10 +510,10 @@ void ShowAnnotation(int client, int viewer, float life)
452510
453511void HideAnnotation (int client )
454512{
455- if (g_iAnnID [client ] != 0 )
513+ if (g_iAnnPlayerID [client ] != 0 )
456514 HideAnnotationReal (client , 0 );
457515
458- g_iAnnID [client ] = 0 ;
516+ g_iAnnPlayerID [client ] = 0 ;
459517 g_flAnnN [client ] = 0.0 ;
460518 g_bAnnIsTeam [client ] = false ;
461519
@@ -469,7 +527,7 @@ void HideAnnotationReal(int client, int viewer)
469527 if (! event ) return ;
470528
471529 event .SetInt (" follow_entindex" , client );
472- event .SetInt (" id" , g_iAnnID [client ]);
530+ event .SetInt (" id" , g_iAnnPlayerID [client ]);
473531
474532 if (viewer > 0 && IsClientInGame (viewer ))
475533 event .FireToClient (viewer );
0 commit comments