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

Annotation of /specinfo.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4