Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4. #include <fakemeta>
  5.  
  6. new const VERSION[ ] = "1.3.1"
  7. new const TRKCVAR[ ] = "specinfo_version"
  8. #define IMMUNE_FLAG ADMIN_IMMUNITY
  9.  
  10. #define KEYS_STR_LEN 31
  11. #define LIST_STR_LEN 610
  12. #define BOTH_STR_LEN KEYS_STR_LEN + LIST_STR_LEN
  13.  
  14. //cl_prefs constants
  15. #define FL_LIST ( 1 << 0 )
  16. #define FL_KEYS ( 1 << 1 )
  17. #define FL_OWNKEYS ( 1 << 2 )
  18. #define FL_HIDE ( 1 << 3 )
  19.  
  20. //cvar pointers
  21. new p_enabled, p_list_enabled, p_keys_enabled, p_list_default, p_keys_default;
  22. new p_red, p_grn, p_blu, p_immunity;
  23.  
  24. //data arrays
  25. new cl_keys[33], cl_prefs[33];
  26. new keys_string[33][KEYS_STR_LEN + 1], list_string[33][LIST_STR_LEN + 1]
  27. new cl_names[33][21], spec_ids[33][33];
  28.  
  29. new tFramesPer[ 33 ], tFps[ 33 ], Float:tGameTime[ 33 ], tCurFps[ 33 ];
  30.  
  31. public plugin_init( )
  32. {
  33. register_plugin( "SpecInfo", VERSION, "Ian Cammarata" );
  34. register_cvar( TRKCVAR, VERSION, FCVAR_SERVER );
  35. set_cvar_string( TRKCVAR, VERSION );
  36.  
  37. register_forward( FM_PlayerPreThink, "fwPlayerPreThink" );
  38.  
  39. p_enabled = register_cvar( "si_enabled", "1" );
  40. p_list_enabled = register_cvar( "si_list_enabled", "0" );
  41. p_keys_enabled = register_cvar( "si_keys_enabled", "1" );
  42. p_list_default = register_cvar( "si_list_default", "0" );
  43. p_keys_default = register_cvar( "si_keys_default", "1" );
  44. p_immunity = register_cvar( "si_immunity", "1" );
  45. p_red = register_cvar( "si_msg_r", "3" );
  46. p_grn = register_cvar( "si_msg_g", "147" );
  47. p_blu = register_cvar( "si_msg_b", "230" );
  48.  
  49. register_clcmd( "say /speclist", "toggle_list", _, "Toggle spectator list." );
  50. register_clcmd( "say /speckeys", "toggle_keys", _, "Toggle spectator keys." );
  51. register_clcmd( "say /showkeys", "toggle_ownkeys", _, "Toggle viewing own keys." );
  52. register_clcmd( "say /spechide", "toggle_hide", IMMUNE_FLAG, "Admins toggle being hidden from list." );
  53.  
  54. set_task( 1.0, "list_update", _, _, _, "b" );
  55. set_task( 0.1, "keys_update", _, _, _, "b" );
  56.  
  57. register_dictionary( "specinfo.txt" );
  58. }
  59.  
  60. public fwPlayerPreThink( id )
  61. {
  62. if( is_user_connected( id ) )
  63. {
  64. tGameTime[ id ] = get_gametime( );
  65. if( tFramesPer[ id ] > tGameTime[ id ] )
  66. {
  67. tFps[ id ] += 1;
  68. }
  69. else
  70. {
  71. tFramesPer[ id ] += 1;
  72. tCurFps[ id ] = tFps[ id ];
  73. tFps[ id ] = 0;
  74. }
  75. }
  76. }
  77.  
  78. public client_connect( id )
  79. {
  80. cl_prefs[id] = 0;
  81. if( !is_user_bot( id ) )
  82. {
  83. if( get_pcvar_num( p_list_default ) ) cl_prefs[id] |= FL_LIST;
  84. if( get_pcvar_num( p_keys_default ) ) cl_prefs[id] |= FL_KEYS;
  85. }
  86. get_user_name( id, cl_names[id], 20 );
  87. return PLUGIN_CONTINUE;
  88. }
  89.  
  90. public client_infochanged( id )
  91. {
  92. get_user_name( id, cl_names[id], 20 );
  93. return PLUGIN_CONTINUE;
  94. }
  95.  
  96. public list_update( )
  97. {
  98. if( get_pcvar_num( p_enabled ) && get_pcvar_num ( p_list_enabled ) )
  99. {
  100. new players[32], num, id, id2, i, j;
  101. for( i = 1; i < 33; i++ ) spec_ids[i][0] = 0;
  102.  
  103. get_players( players, num, "bch" );
  104. for( i = 0; i < num; i++ )
  105. {
  106. id = players[i];
  107. if( !( get_user_flags( id ) & IMMUNE_FLAG && get_pcvar_num( p_immunity ) && cl_prefs[id] & FL_HIDE ) )
  108. {
  109. id2 = pev( id, pev_iuser2 );
  110. if( id2 )
  111. {
  112. spec_ids[ id2 ][ 0 ]++;
  113. spec_ids[ id2 ][ spec_ids[ id2 ][ 0 ] ] = id;
  114. }
  115. }
  116. }
  117. new tmplist[ LIST_STR_LEN + 1 ], tmpstr[41];
  118. new count, namelen, tmpname[21];
  119. for( i=1; i<33; i++ )
  120. {
  121. count = spec_ids[i][0];
  122. if( count )
  123. {
  124. namelen = ( LIST_STR_LEN - 10 ) / count;
  125. clamp( namelen, 10, 20 );
  126. format( tmpname, namelen, cl_names[i] );
  127. 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);
  128. for( j=1; j<=count; j++ )
  129. {
  130. format( tmpname, namelen, cl_names[spec_ids[i][j]]);
  131. 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 );
  132. if( strlen( tmplist ) + strlen( tmpstr ) + ( 11 - j ) < ( LIST_STR_LEN - 1 ) )
  133. format( tmplist, LIST_STR_LEN - 10, "%s%s^n", tmplist, tmpstr );
  134. else
  135. {
  136. format( tmplist, LIST_STR_LEN, "%s...^n", tmplist );
  137. break;
  138. }
  139. }
  140. if( count < 10 )
  141. format( tmplist, LIST_STR_LEN,
  142. "%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^t^n",
  143. tmplist, VERSION
  144. );
  145. for( j+=0; j<10; j++ )
  146. format( tmplist, LIST_STR_LEN, "%s%s", tmplist, "^n" );
  147. list_string[i] = tmplist;
  148. }
  149. }
  150. get_players( players, num, "ch" );
  151. for( i=0; i<num; i++ ) clmsg( players[i] );
  152. }
  153. return PLUGIN_HANDLED;
  154. }
  155.  
  156. public keys_update( )
  157. {
  158. if( !get_pcvar_num( p_enabled ) && !get_pcvar_num( p_keys_enabled ) ) return;
  159.  
  160. new players[32], num, id, i;
  161. get_players( players, num, "a" );
  162. for( i = 0; i < num; i++ )
  163. {
  164. id = players[i];
  165. formatex( keys_string[id], KEYS_STR_LEN, " ^n^n^t^t%s^t^t^t%s^n^t%s %s %s^t%s^nFPS: %d",
  166. cl_keys[id] & IN_FORWARD ? "W" : " .",
  167. "%L",
  168. cl_keys[id] & IN_MOVELEFT ? "A" : ".",
  169. cl_keys[id] & IN_BACK ? "S" : ".",
  170. cl_keys[id] & IN_MOVERIGHT ? "D" : ".",
  171. "%L"
  172. , tCurFps[ id ]);
  173.  
  174. //Flags stored in string to fill translation char in clmsg function
  175. keys_string[id][0] = 0;
  176. if( cl_keys[id] & IN_JUMP ) keys_string[id][0] |= IN_JUMP;
  177. if( cl_keys[id] & IN_DUCK ) keys_string[id][0] |= IN_DUCK;
  178.  
  179. cl_keys[id] = 0;
  180. }
  181.  
  182. new id2;
  183. get_players( players, num, "ch" );
  184. for( i=0; i<num; i++ )
  185. {
  186. id = players[i];
  187. if( is_user_alive( id ) )
  188. {
  189. if( cl_prefs[id] & FL_OWNKEYS ) clmsg( id );
  190. }
  191. else
  192. {
  193. id2 = pev( id, pev_iuser2 );
  194. if( cl_prefs[id] & FL_KEYS && id2 && id2 != id ) clmsg( id );
  195. }
  196. }
  197.  
  198. }
  199.  
  200. public server_frame( )
  201. {
  202. if( get_pcvar_num( p_enabled ) && get_pcvar_num( p_keys_enabled ) )
  203. {
  204. new players[32], num, id;
  205. get_players( players, num, "a" );
  206. for( new i = 0; i < num; i++ )
  207. {
  208. id = players[i];
  209. if( get_user_button( id ) & IN_FORWARD )
  210. cl_keys[id] |= IN_FORWARD;
  211. if( get_user_button( id ) & IN_BACK )
  212. cl_keys[id] |= IN_BACK;
  213. if( get_user_button( id ) & IN_MOVELEFT )
  214. cl_keys[id] |= IN_MOVELEFT;
  215. if( get_user_button( id ) & IN_MOVERIGHT )
  216. cl_keys[id] |= IN_MOVERIGHT;
  217. if( get_user_button( id ) & IN_DUCK )
  218. cl_keys[id] |= IN_DUCK;
  219. if( get_user_button( id ) & IN_JUMP )
  220. cl_keys[id] |= IN_JUMP;
  221. }
  222. }
  223. return PLUGIN_CONTINUE
  224. }
  225.  
  226. public clmsg( id )
  227. {
  228. if( !id ) return;
  229.  
  230. new prefs = cl_prefs[id];
  231.  
  232. new bool:show_own = false;
  233. if( is_user_alive( id ) && prefs & FL_OWNKEYS ) show_own = true;
  234.  
  235. if( is_user_alive( id ) && !show_own )
  236. {
  237. if( prefs & FL_LIST && spec_ids[id][0] && get_pcvar_num( p_list_enabled ) )
  238. {
  239. set_hudmessage(
  240. get_pcvar_num( p_red ),
  241. get_pcvar_num( p_grn ),
  242. get_pcvar_num( p_blu ),
  243. 0.7, /*x*/
  244. 0.1, /*y*/
  245. 0, /*fx*/
  246. 0.0, /*fx time*/
  247. 1.1, /*hold time*/
  248. 0.1, /*fade in*/
  249. 0.1, /*fade out*/
  250. 4 /*chan - 3*/
  251. );
  252. show_hudmessage( id, list_string[id], id, "SPECTATING" );
  253. }
  254. }
  255. else
  256. {
  257. new id2;
  258. if( show_own ) id2 = id;
  259. else id2 = pev( id, pev_iuser2 );
  260. if( !id2 ) return;
  261.  
  262. if( prefs & FL_LIST || prefs & FL_KEYS || show_own )
  263. {
  264. set_hudmessage(
  265. get_pcvar_num( p_red ),
  266. get_pcvar_num( p_grn ),
  267. get_pcvar_num( p_blu ),
  268. 85,
  269. 127,
  270. 255,
  271. 0.02,
  272. 0.53,
  273. 0,
  274. 6.0,
  275. 12.0
  276. );
  277. new msg[BOTH_STR_LEN + 1];
  278. if( prefs & FL_LIST && get_pcvar_num( p_list_enabled ) && spec_ids[id2][0] )
  279. formatex(msg,BOTH_STR_LEN,list_string[id2],id,"SPECTATING");
  280. else msg ="^n^n^n^n^n^n^n^n^n^n^n^n";
  281. if( get_pcvar_num( p_keys_enabled ) && ( prefs & FL_KEYS || show_own ) )
  282. {
  283. format( msg, BOTH_STR_LEN, "%s%s", msg, keys_string[id2][1] );
  284. format( msg, BOTH_STR_LEN, msg,
  285. id, keys_string[id2][0] & IN_JUMP ? "JUMP" : "LAME",
  286. id, keys_string[id2][0] & IN_DUCK ? "DUCK" : "LAME"
  287. );
  288. }
  289. show_hudmessage( id, msg );
  290. }
  291. }
  292. }
  293.  
  294. public set_hudmsg_flg_notify( )
  295. {
  296. set_hudmessage(
  297. get_pcvar_num( p_red ),
  298. get_pcvar_num( p_grn ),
  299. get_pcvar_num( p_blu ),
  300. 42,
  301. 127,
  302. 255,
  303. 0.0,
  304. 0.17,
  305. 0,
  306. 6.0,
  307. 12.0
  308. );
  309. }
  310.  
  311. public toggle_list( id )
  312. {
  313. set_hudmsg_flg_notify( );
  314. cl_prefs[id] ^= FL_LIST;
  315. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_LIST ? "SPEC_LIST_ENABLED" : "SPEC_LIST_DISABLED" );
  316. return PLUGIN_HANDLED;
  317. }
  318.  
  319. public toggle_keys( id )
  320. {
  321. set_hudmsg_flg_notify( );
  322. cl_prefs[id] ^= FL_KEYS;
  323. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_KEYS ? "SPEC_KEYS_ENABLED" : "SPEC_KEYS_DISABLED" );
  324. return PLUGIN_HANDLED;
  325. }
  326.  
  327. public toggle_ownkeys( id )
  328. {
  329. set_hudmsg_flg_notify( );
  330. cl_prefs[id] ^= FL_OWNKEYS;
  331. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_OWNKEYS ? "SPEC_OWNKEYS_ENABLED" : "SPEC_OWNKEYS_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] ^= FL_HIDE;
  341. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_HIDE ? "SPEC_HIDE_ENABLED" : "SPEC_HIDE_DISABLED" );
  342. }
  343. return PLUGIN_HANDLED;
  344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement