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