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

Annotation of /specinfo.sma

Parent Directory Parent Directory | Revision Log Revision Log


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

Contact
ViewVC Help
Powered by ViewVC 1.0.4