Parent Directory | Revision Log
Revision 36 - (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 : | Spanish (100%) - Thanks to <3 Mely <3 for checking these. | ||
58 : | ian | 21 | German (63%) - Thanks to [S]killer for this translation. |
59 : | ian | 1 | |
60 : | |||
61 : | Change Log: | ||
62 : | Key (+ added | - removed | c changed | f fixed) | ||
63 : | |||
64 : | ian | 36 | v1.3.1 (Jan 5, 2008) |
65 : | f: Eliminated a bug introduced in 1.3 as well as the occasional index out of bounds error it caused. | ||
66 : | |||
67 : | ian | 29 | v1.3 (Nov 21, 2007) |
68 : | ian | 21 | +: Command "/showkeys" to view your own keys. |
69 : | c: Minor code optimizations. | ||
70 : | |||
71 : | ian | 1 | v1.2 (Jul 14, 2007) |
72 : | +: Command "say /spechide" for immune to toggle hidden state. | ||
73 : | c: Lots of code optimizations. | ||
74 : | f: Always showing keys even when disabled. | ||
75 : | f: Hud messaged getting messed up when too many names are on the list. (No seriously, for real this time.) | ||
76 : | |||
77 : | v1.1 (Jul 06, 2007) | ||
78 : | +: Show number of people spectating. | ||
79 : | c: Names truncated shorter than 20 chars when lots of players on the list. | ||
80 : | c: Spectator list moved further right. (Even further when you're alive.) | ||
81 : | f: Hud messaged getting messed up when too many names are on the list. (Same as last time, but it's fixed for good.) | ||
82 : | |||
83 : | v1.0.1 (June 07, 2007) | ||
84 : | f: Hud messaged getting messed up when too many names are on the list. | ||
85 : | |||
86 : | v1.0 (June 02, 2007) | ||
87 : | !Initial Release | ||
88 : | */ | ||
89 : | #include <amxmodx> | ||
90 : | #include <amxmisc> | ||
91 : | #include <engine> | ||
92 : | #include <fakemeta> | ||
93 : | |||
94 : | ian | 36 | new const VERSION[ ] = "1.3.1" |
95 : | ian | 30 | new const TRKCVAR[ ] = "specinfo_version" |
96 : | ian | 1 | #define IMMUNE_FLAG ADMIN_IMMUNITY |
97 : | |||
98 : | #define KEYS_STR_LEN 31 | ||
99 : | #define LIST_STR_LEN 610 | ||
100 : | ian | 36 | #define BOTH_STR_LEN KEYS_STR_LEN + LIST_STR_LEN |
101 : | ian | 1 | |
102 : | ian | 36 | //cl_prefs constants |
103 : | #define FL_LIST ( 1 << 0 ) | ||
104 : | #define FL_KEYS ( 1 << 1 ) | ||
105 : | #define FL_OWNKEYS ( 1 << 2 ) | ||
106 : | #define FL_HIDE ( 1 << 3 ) | ||
107 : | |||
108 : | ian | 1 | //cvar pointers |
109 : | ian | 36 | new p_enabled, p_list_enabled, p_keys_enabled, p_list_default, p_keys_default; |
110 : | new p_red, p_grn, p_blu, p_immunity; | ||
111 : | ian | 1 | |
112 : | //data arrays | ||
113 : | ian | 36 | new cl_keys[33], cl_prefs[33]; |
114 : | new keys_string[33][KEYS_STR_LEN + 1], list_string[33][LIST_STR_LEN + 1] | ||
115 : | new cl_names[33][21], spec_ids[33][33]; | ||
116 : | ian | 1 | |
117 : | ian | 21 | public plugin_init( ) |
118 : | { | ||
119 : | ian | 36 | register_plugin( "SpecInfo", VERSION, "Ian Cammarata" ); |
120 : | register_cvar( TRKCVAR, VERSION, FCVAR_SERVER ); | ||
121 : | set_cvar_string( TRKCVAR, VERSION ); | ||
122 : | ian | 21 | |
123 : | ian | 36 | p_enabled = register_cvar( "si_enabled", "1" ); |
124 : | p_list_enabled = register_cvar( "si_list_enabled", "1" ); | ||
125 : | p_keys_enabled = register_cvar( "si_keys_enabled", "1" ); | ||
126 : | p_list_default = register_cvar( "si_list_default", "1" ); | ||
127 : | p_keys_default = register_cvar( "si_keys_default", "1" ); | ||
128 : | p_immunity = register_cvar( "si_immunity", "1" ); | ||
129 : | p_red = register_cvar( "si_msg_r", "45" ); | ||
130 : | p_grn = register_cvar( "si_msg_g", "89" ); | ||
131 : | p_blu = register_cvar( "si_msg_b", "116" ); | ||
132 : | ian | 21 | |
133 : | ian | 36 | register_clcmd( "say /speclist", "toggle_list", _, "Toggle spectator list." ); |
134 : | register_clcmd( "say /speckeys", "toggle_keys", _, "Toggle spectator keys." ); | ||
135 : | register_clcmd( "say /showkeys", "toggle_ownkeys", _, "Toggle viewing own keys." ); | ||
136 : | register_clcmd( "say /spechide", "toggle_hide", IMMUNE_FLAG, "Admins toggle being hidden from list." ); | ||
137 : | ian | 21 | |
138 : | ian | 36 | set_task( 1.0, "list_update", _, _, _, "b" ); |
139 : | set_task( 0.1, "keys_update", _, _, _, "b" ); | ||
140 : | ian | 21 | |
141 : | ian | 36 | register_dictionary( "specinfo.txt" ); |
142 : | ian | 21 | } |
143 : | |||
144 : | ian | 1 | public client_connect( id ) |
145 : | { | ||
146 : | ian | 36 | cl_prefs[id] = 0; |
147 : | ian | 1 | if( !is_user_bot( id ) ) |
148 : | { | ||
149 : | ian | 36 | if( get_pcvar_num( p_list_default ) ) cl_prefs[id] |= FL_LIST; |
150 : | if( get_pcvar_num( p_keys_default ) ) cl_prefs[id] |= FL_KEYS; | ||
151 : | ian | 1 | } |
152 : | ian | 36 | get_user_name( id, cl_names[id], 20 ); |
153 : | return PLUGIN_CONTINUE; | ||
154 : | ian | 1 | } |
155 : | |||
156 : | public client_infochanged( id ) | ||
157 : | { | ||
158 : | ian | 36 | get_user_name( id, cl_names[id], 20 ); |
159 : | return PLUGIN_CONTINUE; | ||
160 : | ian | 1 | } |
161 : | |||
162 : | public list_update( ) | ||
163 : | { | ||
164 : | if( get_pcvar_num( p_enabled ) && get_pcvar_num ( p_list_enabled ) ) | ||
165 : | { | ||
166 : | ian | 36 | new players[32], num, id, id2, i, j; |
167 : | for( i = 1; i < 33; i++ ) spec_ids[i][0] = 0; | ||
168 : | |||
169 : | get_players( players, num, "bch" ); | ||
170 : | for( i = 0; i < num; i++ ) | ||
171 : | ian | 1 | { |
172 : | ian | 36 | id = players[i]; |
173 : | ian | 21 | if( !( get_user_flags( id ) & IMMUNE_FLAG && get_pcvar_num( p_immunity ) && cl_prefs[id] & FL_HIDE ) ) |
174 : | ian | 1 | { |
175 : | ian | 36 | id2 = pev( id, pev_iuser2 ); |
176 : | ian | 1 | if( id2 ) |
177 : | { | ||
178 : | ian | 36 | spec_ids[ id2 ][ 0 ]++; |
179 : | spec_ids[ id2 ][ spec_ids[ id2 ][ 0 ] ] = id; | ||
180 : | ian | 1 | } |
181 : | } | ||
182 : | } | ||
183 : | ian | 36 | new tmplist[ LIST_STR_LEN + 1 ], tmpstr[41]; |
184 : | new count, namelen, tmpname[21]; | ||
185 : | ian | 1 | for( i=1; i<33; i++ ) |
186 : | { | ||
187 : | ian | 36 | count = spec_ids[i][0]; |
188 : | ian | 1 | if( count ) |
189 : | { | ||
190 : | ian | 36 | namelen = ( LIST_STR_LEN - 10 ) / count; |
191 : | clamp( namelen, 10, 20 ); | ||
192 : | format( tmpname, namelen, cl_names[i] ); | ||
193 : | 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); | ||
194 : | ian | 1 | for( j=1; j<=count; j++ ) |
195 : | { | ||
196 : | ian | 36 | format( tmpname, namelen, cl_names[spec_ids[i][j]]); |
197 : | 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 ); | ||
198 : | ian | 1 | if( strlen( tmplist ) + strlen( tmpstr ) + ( 11 - j ) < ( LIST_STR_LEN - 1 ) ) |
199 : | ian | 36 | format( tmplist, LIST_STR_LEN - 10, "%s%s^n", tmplist, tmpstr ); |
200 : | ian | 1 | else |
201 : | { | ||
202 : | ian | 36 | format( tmplist, LIST_STR_LEN, "%s...^n", tmplist ); |
203 : | break; | ||
204 : | ian | 1 | } |
205 : | } | ||
206 : | if( count < 10 ) | ||
207 : | ian | 21 | format( tmplist, LIST_STR_LEN, |
208 : | "%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", | ||
209 : | tmplist, VERSION | ||
210 : | ian | 36 | ); |
211 : | ian | 1 | for( j+=0; j<10; j++ ) |
212 : | ian | 36 | format( tmplist, LIST_STR_LEN, "%s%s", tmplist, "^n" ); |
213 : | list_string[i] = tmplist; | ||
214 : | ian | 1 | } |
215 : | } | ||
216 : | ian | 36 | get_players( players, num, "ch" ); |
217 : | for( i=0; i<num; i++ ) clmsg( players[i] ); | ||
218 : | ian | 1 | } |
219 : | ian | 36 | return PLUGIN_HANDLED; |
220 : | ian | 1 | } |
221 : | |||
222 : | public keys_update( ) | ||
223 : | { | ||
224 : | ian | 36 | if( !get_pcvar_num( p_enabled ) && !get_pcvar_num( p_keys_enabled ) ) return; |
225 : | ian | 21 | |
226 : | ian | 36 | new players[32], num, id, i; |
227 : | get_players( players, num, "a" ); | ||
228 : | ian | 21 | for( i = 0; i < num; i++ ) |
229 : | { | ||
230 : | ian | 36 | id = players[i]; |
231 : | 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", |
232 : | cl_keys[id] & IN_FORWARD ? "W" : " .", | ||
233 : | "%L", | ||
234 : | cl_keys[id] & IN_MOVELEFT ? "A" : ".", | ||
235 : | cl_keys[id] & IN_BACK ? "S" : ".", | ||
236 : | cl_keys[id] & IN_MOVERIGHT ? "D" : ".", | ||
237 : | "%L" | ||
238 : | ian | 36 | ); |
239 : | ian | 1 | |
240 : | ian | 21 | //Flags stored in string to fill translation char in clmsg function |
241 : | ian | 36 | keys_string[id][0] = 0; |
242 : | if( cl_keys[id] & IN_JUMP ) keys_string[id][0] |= IN_JUMP; | ||
243 : | if( cl_keys[id] & IN_DUCK ) keys_string[id][0] |= IN_DUCK; | ||
244 : | ian | 21 | |
245 : | ian | 36 | cl_keys[id] = 0; |
246 : | ian | 21 | } |
247 : | |||
248 : | ian | 36 | new id2; |
249 : | get_players( players, num, "ch" ); | ||
250 : | ian | 21 | for( i=0; i<num; i++ ) |
251 : | { | ||
252 : | ian | 36 | id = players[i]; |
253 : | ian | 21 | if( is_user_alive( id ) ) |
254 : | { | ||
255 : | ian | 36 | if( cl_prefs[id] & FL_OWNKEYS ) clmsg( id ); |
256 : | ian | 1 | } |
257 : | ian | 21 | else |
258 : | { | ||
259 : | ian | 36 | id2 = pev( id, pev_iuser2 ); |
260 : | if( cl_prefs[id] & FL_KEYS && id2 && id2 != id ) clmsg( id ); | ||
261 : | ian | 21 | } |
262 : | ian | 1 | } |
263 : | ian | 21 | |
264 : | ian | 1 | } |
265 : | |||
266 : | public server_frame( ) | ||
267 : | { | ||
268 : | if( get_pcvar_num( p_enabled ) && get_pcvar_num( p_keys_enabled ) ) | ||
269 : | { | ||
270 : | ian | 36 | new players[32], num, id; |
271 : | get_players( players, num, "a" ); | ||
272 : | ian | 21 | for( new i = 0; i < num; i++ ) |
273 : | ian | 1 | { |
274 : | ian | 36 | id = players[i]; |
275 : | ian | 21 | if( get_user_button( id ) & IN_FORWARD ) |
276 : | ian | 36 | cl_keys[id] |= IN_FORWARD; |
277 : | ian | 21 | if( get_user_button( id ) & IN_BACK ) |
278 : | ian | 36 | cl_keys[id] |= IN_BACK; |
279 : | ian | 21 | if( get_user_button( id ) & IN_MOVELEFT ) |
280 : | ian | 36 | cl_keys[id] |= IN_MOVELEFT; |
281 : | ian | 21 | if( get_user_button( id ) & IN_MOVERIGHT ) |
282 : | ian | 36 | cl_keys[id] |= IN_MOVERIGHT; |
283 : | ian | 21 | if( get_user_button( id ) & IN_DUCK ) |
284 : | ian | 36 | cl_keys[id] |= IN_DUCK; |
285 : | ian | 21 | if( get_user_button( id ) & IN_JUMP ) |
286 : | ian | 36 | cl_keys[id] |= IN_JUMP; |
287 : | ian | 1 | } |
288 : | } | ||
289 : | return PLUGIN_CONTINUE | ||
290 : | } | ||
291 : | |||
292 : | public clmsg( id ) | ||
293 : | { | ||
294 : | ian | 36 | if( !id ) return; |
295 : | ian | 21 | |
296 : | ian | 36 | new prefs = cl_prefs[id]; |
297 : | ian | 21 | |
298 : | ian | 36 | new bool:show_own = false; |
299 : | if( is_user_alive( id ) && prefs & FL_OWNKEYS ) show_own = true; | ||
300 : | ian | 21 | |
301 : | if( is_user_alive( id ) && !show_own ) | ||
302 : | ian | 1 | { |
303 : | ian | 21 | if( prefs & FL_LIST && spec_ids[id][0] && get_pcvar_num( p_list_enabled ) ) |
304 : | { | ||
305 : | set_hudmessage( | ||
306 : | get_pcvar_num( p_red ), | ||
307 : | get_pcvar_num( p_grn ), | ||
308 : | get_pcvar_num( p_blu ), | ||
309 : | 0.7, /*x*/ | ||
310 : | 0.1, /*y*/ | ||
311 : | 0, /*fx*/ | ||
312 : | 0.0, /*fx time*/ | ||
313 : | 1.1, /*hold time*/ | ||
314 : | 0.1, /*fade in*/ | ||
315 : | 0.1, /*fade out*/ | ||
316 : | 3 /*chan*/ | ||
317 : | ian | 36 | ); |
318 : | show_hudmessage( id, list_string[id], id, "SPECTATING" ); | ||
319 : | ian | 1 | } |
320 : | ian | 21 | } |
321 : | else | ||
322 : | { | ||
323 : | ian | 36 | new id2; |
324 : | if( show_own ) id2 = id; | ||
325 : | else id2 = pev( id, pev_iuser2 ); | ||
326 : | if( !id2 ) return; | ||
327 : | ian | 21 | |
328 : | if( prefs & FL_LIST || prefs & FL_KEYS || show_own ) | ||
329 : | ian | 1 | { |
330 : | ian | 21 | set_hudmessage( |
331 : | get_pcvar_num( p_red ), | ||
332 : | get_pcvar_num( p_grn ), | ||
333 : | get_pcvar_num( p_blu ), | ||
334 : | 0.48, /*x*/ | ||
335 : | 0.14, /*y*/ | ||
336 : | 0, /*fx*/ | ||
337 : | 0.0, /*fx time*/ | ||
338 : | prefs & FL_KEYS || show_own ? 0.1 : 1.1, /*hold time*/ | ||
339 : | 0.1, /*fade in*/ | ||
340 : | 0.1, /*fade out*/ | ||
341 : | 3 /*chan*/ | ||
342 : | ian | 36 | ); |
343 : | new msg[BOTH_STR_LEN + 1]; | ||
344 : | ian | 21 | if( prefs & FL_LIST && get_pcvar_num( p_list_enabled ) && spec_ids[id2][0] ) |
345 : | ian | 36 | formatex(msg,BOTH_STR_LEN,list_string[id2],id,"SPECTATING"); |
346 : | else msg ="^n^n^n^n^n^n^n^n^n^n^n^n"; | ||
347 : | ian | 21 | if( get_pcvar_num( p_keys_enabled ) && ( prefs & FL_KEYS || show_own ) ) |
348 : | ian | 1 | { |
349 : | ian | 36 | format( msg, BOTH_STR_LEN, "%s%s", msg, keys_string[id2][1] ); |
350 : | ian | 21 | format( msg, BOTH_STR_LEN, msg, |
351 : | id, keys_string[id2][0] & IN_JUMP ? "JUMP" : "LAME", | ||
352 : | id, keys_string[id2][0] & IN_DUCK ? "DUCK" : "LAME" | ||
353 : | ian | 36 | ); |
354 : | ian | 21 | } |
355 : | ian | 36 | show_hudmessage( id, msg ); |
356 : | ian | 1 | } |
357 : | } | ||
358 : | } | ||
359 : | |||
360 : | public set_hudmsg_flg_notify( ) | ||
361 : | { | ||
362 : | ian | 21 | set_hudmessage( |
363 : | get_pcvar_num( p_red ), | ||
364 : | get_pcvar_num( p_grn ), | ||
365 : | get_pcvar_num( p_blu ), | ||
366 : | -1.0, /*x*/ | ||
367 : | 0.8, /*y*/ | ||
368 : | 0, /*fx*/ | ||
369 : | 0.0, /*fx time*/ | ||
370 : | 3.0, /*hold time*/ | ||
371 : | 0.0, /*fade in*/ | ||
372 : | 0.0, /*fade out*/ | ||
373 : | -1 /*chan*/ | ||
374 : | ian | 36 | ); |
375 : | ian | 1 | } |
376 : | |||
377 : | public toggle_list( id ) | ||
378 : | { | ||
379 : | ian | 36 | set_hudmsg_flg_notify( ); |
380 : | cl_prefs[id] ^= FL_LIST; | ||
381 : | show_hudmessage( id, "%L", id, cl_prefs[id] & FL_LIST ? "SPEC_LIST_ENABLED" : "SPEC_LIST_DISABLED" ); | ||
382 : | return PLUGIN_HANDLED; | ||
383 : | ian | 1 | } |
384 : | |||
385 : | public toggle_keys( id ) | ||
386 : | { | ||
387 : | ian | 36 | set_hudmsg_flg_notify( ); |
388 : | cl_prefs[id] ^= FL_KEYS; | ||
389 : | show_hudmessage( id, "%L", id, cl_prefs[id] & FL_KEYS ? "SPEC_KEYS_ENABLED" : "SPEC_KEYS_DISABLED" ); | ||
390 : | return PLUGIN_HANDLED; | ||
391 : | ian | 1 | } |
392 : | |||
393 : | ian | 21 | public toggle_ownkeys( id ) |
394 : | { | ||
395 : | ian | 36 | set_hudmsg_flg_notify( ); |
396 : | cl_prefs[id] ^= FL_OWNKEYS; | ||
397 : | show_hudmessage( id, "%L", id, cl_prefs[id] & FL_OWNKEYS ? "SPEC_OWNKEYS_ENABLED" : "SPEC_OWNKEYS_DISABLED" ); | ||
398 : | return PLUGIN_HANDLED; | ||
399 : | ian | 21 | } |
400 : | |||
401 : | ian | 1 | public toggle_hide( id, level, cid ) |
402 : | { | ||
403 : | if( cmd_access( id, level, cid, 0 ) ) | ||
404 : | { | ||
405 : | ian | 36 | set_hudmsg_flg_notify( ); |
406 : | cl_prefs[id] ^= FL_HIDE; | ||
407 : | show_hudmessage( id, "%L", id, cl_prefs[id] & FL_HIDE ? "SPEC_HIDE_ENABLED" : "SPEC_HIDE_DISABLED" ); | ||
408 : | ian | 1 | } |
409 : | ian | 36 | return PLUGIN_HANDLED; |
410 : | ian | 1 | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |