[Half-Life AMXX] / specinfo.sma Repository:
ViewVC logotype

Annotation of /specinfo.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (view) (download)

1 : ian 1 /*
2 : ian 36 SpecInfo v1.3.1
3 :     Copyright (C) 2007-2008 Ian (Juan) Cammarata
4 : ian 1
5 : ian 25 This program is free software: you can redistribute it and/or modify
6 :     it under the terms of the GNU Affero General Public License as
7 :     published by the Free Software Foundation, either version 3 of the
8 :     License, or (at your option) any later version.
9 : ian 1
10 : ian 25 This program is distributed in the hope that it will be useful,
11 :     but WITHOUT ANY WARRANTY; without even the implied warranty of
12 :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :     GNU Affero General Public License for more details.
14 : ian 1
15 : ian 25 You should have received a copy of the GNU Affero General Public License
16 :     along with this program. If not, see <http://www.gnu.org/licenses/>.
17 : ian 1 --------------------------------------------------------------------------------
18 :     http://ian.cammarata.us
19 : ian 36 Jan 05 17:39
20 : ian 1
21 :    
22 :     Description:
23 :     This plugin displays a list of spectators currently viewing the live player.
24 :     This list is visible to the living player as well as other players currently
25 :     spectating that player. Also spectators can see which movement commands the
26 :     the live player is using.
27 :    
28 :    
29 :     Commands:
30 :     say /speclist : Toggle viewing list of spectators.
31 :     say /speckeys : Toggle viewing keys of player you are spectating.
32 :     say /spechide : Immune admins toggle whether or not they're hidden from list.
33 : ian 29 say /showkeys : View your own keys on screen while alive.
34 : ian 1
35 :    
36 :     Cvars (First value is default):
37 :     si_enabled <1|0> : Enables all plugin functionality.
38 :    
39 :     si_list_enabled <1|0> : Enables spectator list.
40 :     si_keys_enabled <1|0> : Enables spectator key view.
41 :     si_list_default <1|0> : Default on/off state for spec list when a client joins.
42 :     si_keys_default <1|0> : Default on/off state for key view when a client joins.
43 :    
44 :     si_immunity <0|1> : Enables admin immunity; Admins won't show on spec list.
45 :    
46 :     si_msg_r <45|...> : HUD message red value.
47 :     si_msg_g <89|...> : HUD message green value.
48 :     si_msg_b <116|...> : HUD message blue value.
49 :    
50 :    
51 :     Notes:
52 :     Make sure you place the specinfo.txt file in addons\amxmodx\data\lang
53 :    
54 :    
55 :     Supported Languages:
56 :     English (100%)
57 : ian 46 Spanish (100%) - Thanks to Mely for checking these.
58 : ian 21 German (63%) - Thanks to [S]killer for this translation.
59 : ian 46 Czech (100%) - Thanks to FuGi for this translation.
60 : ian 1
61 :    
62 :     Change Log:
63 :     Key (+ added | - removed | c changed | f fixed)
64 :    
65 : ian 36 v1.3.1 (Jan 5, 2008)
66 :     f: Eliminated a bug introduced in 1.3 as well as the occasional index out of bounds error it caused.
67 :    
68 : ian 29 v1.3 (Nov 21, 2007)
69 : ian 21 +: Command "/showkeys" to view your own keys.
70 :     c: Minor code optimizations.
71 :    
72 : ian 1 v1.2 (Jul 14, 2007)
73 :     +: Command "say /spechide" for immune to toggle hidden state.
74 :     c: Lots of code optimizations.
75 :     f: Always showing keys even when disabled.
76 :     f: Hud messaged getting messed up when too many names are on the list. (No seriously, for real this time.)
77 :    
78 :     v1.1 (Jul 06, 2007)
79 :     +: Show number of people spectating.
80 :     c: Names truncated shorter than 20 chars when lots of players on the list.
81 :     c: Spectator list moved further right. (Even further when you're alive.)
82 :     f: Hud messaged getting messed up when too many names are on the list. (Same as last time, but it's fixed for good.)
83 :    
84 :     v1.0.1 (June 07, 2007)
85 :     f: Hud messaged getting messed up when too many names are on the list.
86 :    
87 :     v1.0 (June 02, 2007)
88 :     !Initial Release
89 :     */
90 :     #include <amxmodx>
91 :     #include <amxmisc>
92 :     #include <engine>
93 :     #include <fakemeta>
94 :    
95 : ian 36 new const VERSION[ ] = "1.3.1"
96 : ian 30 new const TRKCVAR[ ] = "specinfo_version"
97 : ian 1 #define IMMUNE_FLAG ADMIN_IMMUNITY
98 :    
99 :     #define KEYS_STR_LEN 31
100 :     #define LIST_STR_LEN 610
101 : ian 36 #define BOTH_STR_LEN KEYS_STR_LEN + LIST_STR_LEN
102 : ian 1
103 : ian 36 //cl_prefs constants
104 :     #define FL_LIST ( 1 << 0 )
105 :     #define FL_KEYS ( 1 << 1 )
106 :     #define FL_OWNKEYS ( 1 << 2 )
107 :     #define FL_HIDE ( 1 << 3 )
108 :    
109 : ian 1 //cvar pointers
110 : ian 36 new p_enabled, p_list_enabled, p_keys_enabled, p_list_default, p_keys_default;
111 :     new p_red, p_grn, p_blu, p_immunity;
112 : ian 1
113 :     //data arrays
114 : ian 36 new cl_keys[33], cl_prefs[33];
115 :     new keys_string[33][KEYS_STR_LEN + 1], list_string[33][LIST_STR_LEN + 1]
116 :     new cl_names[33][21], spec_ids[33][33];
117 : ian 1
118 : ian 21 public plugin_init( )
119 :     {
120 : ian 36 register_plugin( "SpecInfo", VERSION, "Ian Cammarata" );
121 :     register_cvar( TRKCVAR, VERSION, FCVAR_SERVER );
122 :     set_cvar_string( TRKCVAR, VERSION );
123 : ian 21
124 : ian 36 p_enabled = register_cvar( "si_enabled", "1" );
125 :     p_list_enabled = register_cvar( "si_list_enabled", "1" );
126 :     p_keys_enabled = register_cvar( "si_keys_enabled", "1" );
127 :     p_list_default = register_cvar( "si_list_default", "1" );
128 :     p_keys_default = register_cvar( "si_keys_default", "1" );
129 :     p_immunity = register_cvar( "si_immunity", "1" );
130 :     p_red = register_cvar( "si_msg_r", "45" );
131 :     p_grn = register_cvar( "si_msg_g", "89" );
132 :     p_blu = register_cvar( "si_msg_b", "116" );
133 : ian 21
134 : ian 36 register_clcmd( "say /speclist", "toggle_list", _, "Toggle spectator list." );
135 :     register_clcmd( "say /speckeys", "toggle_keys", _, "Toggle spectator keys." );
136 :     register_clcmd( "say /showkeys", "toggle_ownkeys", _, "Toggle viewing own keys." );
137 :     register_clcmd( "say /spechide", "toggle_hide", IMMUNE_FLAG, "Admins toggle being hidden from list." );
138 : ian 21
139 : ian 36 set_task( 1.0, "list_update", _, _, _, "b" );
140 :     set_task( 0.1, "keys_update", _, _, _, "b" );
141 : ian 21
142 : ian 36 register_dictionary( "specinfo.txt" );
143 : ian 21 }
144 :    
145 : ian 1 public client_connect( id )
146 :     {
147 : ian 36 cl_prefs[id] = 0;
148 : ian 1 if( !is_user_bot( id ) )
149 :     {
150 : ian 36 if( get_pcvar_num( p_list_default ) ) cl_prefs[id] |= FL_LIST;
151 :     if( get_pcvar_num( p_keys_default ) ) cl_prefs[id] |= FL_KEYS;
152 : ian 1 }
153 : ian 36 get_user_name( id, cl_names[id], 20 );
154 :     return PLUGIN_CONTINUE;
155 : ian 1 }
156 :    
157 :     public client_infochanged( id )
158 :     {
159 : ian 36 get_user_name( id, cl_names[id], 20 );
160 :     return PLUGIN_CONTINUE;
161 : ian 1 }
162 :    
163 :     public list_update( )
164 :     {
165 :     if( get_pcvar_num( p_enabled ) && get_pcvar_num ( p_list_enabled ) )
166 :     {
167 : ian 36 new players[32], num, id, id2, i, j;
168 :     for( i = 1; i < 33; i++ ) spec_ids[i][0] = 0;
169 :    
170 :     get_players( players, num, "bch" );
171 :     for( i = 0; i < num; i++ )
172 : ian 1 {
173 : ian 36 id = players[i];
174 : ian 21 if( !( get_user_flags( id ) & IMMUNE_FLAG && get_pcvar_num( p_immunity ) && cl_prefs[id] & FL_HIDE ) )
175 : ian 1 {
176 : ian 36 id2 = pev( id, pev_iuser2 );
177 : ian 1 if( id2 )
178 :     {
179 : ian 36 spec_ids[ id2 ][ 0 ]++;
180 :     spec_ids[ id2 ][ spec_ids[ id2 ][ 0 ] ] = id;
181 : ian 1 }
182 :     }
183 :     }
184 : ian 36 new tmplist[ LIST_STR_LEN + 1 ], tmpstr[41];
185 :     new count, namelen, tmpname[21];
186 : ian 1 for( i=1; i<33; i++ )
187 :     {
188 : ian 36 count = spec_ids[i][0];
189 : ian 1 if( count )
190 :     {
191 : ian 36 namelen = ( LIST_STR_LEN - 10 ) / count;
192 :     clamp( namelen, 10, 20 );
193 :     format( tmpname, namelen, cl_names[i] );
194 :     formatex( tmplist, LIST_STR_LEN - 1, "^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t(%d) %s %s:^n", count, "%L", tmpname);
195 : ian 1 for( j=1; j<=count; j++ )
196 :     {
197 : ian 36 format( tmpname, namelen, cl_names[spec_ids[i][j]]);
198 :     formatex( tmpstr, 40, "^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t%s", tmpname );
199 : ian 1 if( strlen( tmplist ) + strlen( tmpstr ) + ( 11 - j ) < ( LIST_STR_LEN - 1 ) )
200 : ian 36 format( tmplist, LIST_STR_LEN - 10, "%s%s^n", tmplist, tmpstr );
201 : ian 1 else
202 :     {
203 : ian 36 format( tmplist, LIST_STR_LEN, "%s...^n", tmplist );
204 :     break;
205 : ian 1 }
206 :     }
207 :     if( count < 10 )
208 : ian 21 format( tmplist, LIST_STR_LEN,
209 :     "%s^n^n^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^t^tSpecInfo v%s^n",
210 :     tmplist, VERSION
211 : ian 36 );
212 : ian 1 for( j+=0; j<10; j++ )
213 : ian 36 format( tmplist, LIST_STR_LEN, "%s%s", tmplist, "^n" );
214 :     list_string[i] = tmplist;
215 : ian 1 }
216 :     }
217 : ian 36 get_players( players, num, "ch" );
218 :     for( i=0; i<num; i++ ) clmsg( players[i] );
219 : ian 1 }
220 : ian 36 return PLUGIN_HANDLED;
221 : ian 1 }
222 :    
223 :     public keys_update( )
224 :     {
225 : ian 36 if( !get_pcvar_num( p_enabled ) && !get_pcvar_num( p_keys_enabled ) ) return;
226 : ian 21
227 : ian 36 new players[32], num, id, i;
228 :     get_players( players, num, "a" );
229 : ian 21 for( i = 0; i < num; i++ )
230 :     {
231 : ian 36 id = players[i];
232 : ian 21 formatex( keys_string[id], KEYS_STR_LEN, " ^n^t^t%s^t^t^t%s^n^t%s %s %s^t^t%s",
233 :     cl_keys[id] & IN_FORWARD ? "W" : " .",
234 :     "%L",
235 :     cl_keys[id] & IN_MOVELEFT ? "A" : ".",
236 :     cl_keys[id] & IN_BACK ? "S" : ".",
237 :     cl_keys[id] & IN_MOVERIGHT ? "D" : ".",
238 :     "%L"
239 : ian 36 );
240 : ian 1
241 : ian 21 //Flags stored in string to fill translation char in clmsg function
242 : ian 36 keys_string[id][0] = 0;
243 :     if( cl_keys[id] & IN_JUMP ) keys_string[id][0] |= IN_JUMP;
244 :     if( cl_keys[id] & IN_DUCK ) keys_string[id][0] |= IN_DUCK;
245 : ian 21
246 : ian 36 cl_keys[id] = 0;
247 : ian 21 }
248 :    
249 : ian 36 new id2;
250 :     get_players( players, num, "ch" );
251 : ian 21 for( i=0; i<num; i++ )
252 :     {
253 : ian 36 id = players[i];
254 : ian 21 if( is_user_alive( id ) )
255 :     {
256 : ian 36 if( cl_prefs[id] & FL_OWNKEYS ) clmsg( id );
257 : ian 1 }
258 : ian 21 else
259 :     {
260 : ian 36 id2 = pev( id, pev_iuser2 );
261 :     if( cl_prefs[id] & FL_KEYS && id2 && id2 != id ) clmsg( id );
262 : ian 21 }
263 : ian 1 }
264 : ian 21
265 : ian 1 }
266 :    
267 :     public server_frame( )
268 :     {
269 :     if( get_pcvar_num( p_enabled ) && get_pcvar_num( p_keys_enabled ) )
270 :     {
271 : ian 36 new players[32], num, id;
272 :     get_players( players, num, "a" );
273 : ian 21 for( new i = 0; i < num; i++ )
274 : ian 1 {
275 : ian 36 id = players[i];
276 : ian 21 if( get_user_button( id ) & IN_FORWARD )
277 : ian 36 cl_keys[id] |= IN_FORWARD;
278 : ian 21 if( get_user_button( id ) & IN_BACK )
279 : ian 36 cl_keys[id] |= IN_BACK;
280 : ian 21 if( get_user_button( id ) & IN_MOVELEFT )
281 : ian 36 cl_keys[id] |= IN_MOVELEFT;
282 : ian 21 if( get_user_button( id ) & IN_MOVERIGHT )
283 : ian 36 cl_keys[id] |= IN_MOVERIGHT;
284 : ian 21 if( get_user_button( id ) & IN_DUCK )
285 : ian 36 cl_keys[id] |= IN_DUCK;
286 : ian 21 if( get_user_button( id ) & IN_JUMP )
287 : ian 36 cl_keys[id] |= IN_JUMP;
288 : ian 1 }
289 :     }
290 :     return PLUGIN_CONTINUE
291 :     }
292 :    
293 :     public clmsg( id )
294 :     {
295 : ian 36 if( !id ) return;
296 : ian 21
297 : ian 36 new prefs = cl_prefs[id];
298 : ian 21
299 : ian 36 new bool:show_own = false;
300 :     if( is_user_alive( id ) && prefs & FL_OWNKEYS ) show_own = true;
301 : ian 21
302 :     if( is_user_alive( id ) && !show_own )
303 : ian 1 {
304 : ian 21 if( prefs & FL_LIST && spec_ids[id][0] && get_pcvar_num( p_list_enabled ) )
305 :     {
306 :     set_hudmessage(
307 :     get_pcvar_num( p_red ),
308 :     get_pcvar_num( p_grn ),
309 :     get_pcvar_num( p_blu ),
310 :     0.7, /*x*/
311 :     0.1, /*y*/
312 :     0, /*fx*/
313 :     0.0, /*fx time*/
314 :     1.1, /*hold time*/
315 :     0.1, /*fade in*/
316 :     0.1, /*fade out*/
317 :     3 /*chan*/
318 : ian 36 );
319 :     show_hudmessage( id, list_string[id], id, "SPECTATING" );
320 : ian 1 }
321 : ian 21 }
322 :     else
323 :     {
324 : ian 36 new id2;
325 :     if( show_own ) id2 = id;
326 :     else id2 = pev( id, pev_iuser2 );
327 :     if( !id2 ) return;
328 : ian 21
329 :     if( prefs & FL_LIST || prefs & FL_KEYS || show_own )
330 : ian 1 {
331 : ian 21 set_hudmessage(
332 :     get_pcvar_num( p_red ),
333 :     get_pcvar_num( p_grn ),
334 :     get_pcvar_num( p_blu ),
335 :     0.48, /*x*/
336 :     0.14, /*y*/
337 :     0, /*fx*/
338 :     0.0, /*fx time*/
339 :     prefs & FL_KEYS || show_own ? 0.1 : 1.1, /*hold time*/
340 :     0.1, /*fade in*/
341 :     0.1, /*fade out*/
342 :     3 /*chan*/
343 : ian 36 );
344 :     new msg[BOTH_STR_LEN + 1];
345 : ian 21 if( prefs & FL_LIST && get_pcvar_num( p_list_enabled ) && spec_ids[id2][0] )
346 : ian 36 formatex(msg,BOTH_STR_LEN,list_string[id2],id,"SPECTATING");
347 :     else msg ="^n^n^n^n^n^n^n^n^n^n^n^n";
348 : ian 21 if( get_pcvar_num( p_keys_enabled ) && ( prefs & FL_KEYS || show_own ) )
349 : ian 1 {
350 : ian 36 format( msg, BOTH_STR_LEN, "%s%s", msg, keys_string[id2][1] );
351 : ian 21 format( msg, BOTH_STR_LEN, msg,
352 :     id, keys_string[id2][0] & IN_JUMP ? "JUMP" : "LAME",
353 :     id, keys_string[id2][0] & IN_DUCK ? "DUCK" : "LAME"
354 : ian 36 );
355 : ian 21 }
356 : ian 36 show_hudmessage( id, msg );
357 : ian 1 }
358 :     }
359 :     }
360 :    
361 :     public set_hudmsg_flg_notify( )
362 :     {
363 : ian 21 set_hudmessage(
364 :     get_pcvar_num( p_red ),
365 :     get_pcvar_num( p_grn ),
366 :     get_pcvar_num( p_blu ),
367 :     -1.0, /*x*/
368 :     0.8, /*y*/
369 :     0, /*fx*/
370 :     0.0, /*fx time*/
371 :     3.0, /*hold time*/
372 :     0.0, /*fade in*/
373 :     0.0, /*fade out*/
374 :     -1 /*chan*/
375 : ian 36 );
376 : ian 1 }
377 :    
378 :     public toggle_list( id )
379 :     {
380 : ian 36 set_hudmsg_flg_notify( );
381 :     cl_prefs[id] ^= FL_LIST;
382 :     show_hudmessage( id, "%L", id, cl_prefs[id] & FL_LIST ? "SPEC_LIST_ENABLED" : "SPEC_LIST_DISABLED" );
383 :     return PLUGIN_HANDLED;
384 : ian 1 }
385 :    
386 :     public toggle_keys( id )
387 :     {
388 : ian 36 set_hudmsg_flg_notify( );
389 :     cl_prefs[id] ^= FL_KEYS;
390 :     show_hudmessage( id, "%L", id, cl_prefs[id] & FL_KEYS ? "SPEC_KEYS_ENABLED" : "SPEC_KEYS_DISABLED" );
391 :     return PLUGIN_HANDLED;
392 : ian 1 }
393 :    
394 : ian 21 public toggle_ownkeys( id )
395 :     {
396 : ian 36 set_hudmsg_flg_notify( );
397 :     cl_prefs[id] ^= FL_OWNKEYS;
398 :     show_hudmessage( id, "%L", id, cl_prefs[id] & FL_OWNKEYS ? "SPEC_OWNKEYS_ENABLED" : "SPEC_OWNKEYS_DISABLED" );
399 :     return PLUGIN_HANDLED;
400 : ian 21 }
401 :    
402 : ian 1 public toggle_hide( id, level, cid )
403 :     {
404 :     if( cmd_access( id, level, cid, 0 ) )
405 :     {
406 : ian 36 set_hudmsg_flg_notify( );
407 :     cl_prefs[id] ^= FL_HIDE;
408 :     show_hudmessage( id, "%L", id, cl_prefs[id] & FL_HIDE ? "SPEC_HIDE_ENABLED" : "SPEC_HIDE_DISABLED" );
409 : ian 1 }
410 : ian 36 return PLUGIN_HANDLED;
411 : ian 1 }

Contact
ViewVC Help
Powered by ViewVC 1.0.4