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