Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.79 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.  
  46.  
  47. register_clcmd( "say /speclist", "toggle_list", _, "Toggle spectator list." );
  48. register_clcmd( "say /speckeys", "toggle_keys", _, "Toggle spectator keys." );
  49. register_clcmd( "say /showkeys", "toggle_ownkeys", _, "Toggle viewing own keys." );
  50. register_clcmd( "say /spechide", "toggle_hide", IMMUNE_FLAG, "Admins toggle being hidden from list." );
  51.  
  52. set_task( 1.0, "list_update", _, _, _, "b" );
  53. set_task( 0.1, "keys_update", _, _, _, "b" );
  54.  
  55. register_dictionary( "specinfo.txt" );
  56. }
  57.  
  58. public fwPlayerPreThink( id )
  59. {
  60. if( is_user_connected( id ) )
  61. {
  62. tGameTime[ id ] = get_gametime( );
  63. if( tFramesPer[ id ] > tGameTime[ id ] )
  64. {
  65. tFps[ id ] += 1;
  66. }
  67. else
  68. {
  69. tFramesPer[ id ] += 1;
  70. tCurFps[ id ] = tFps[ id ];
  71. tFps[ id ] = 0;
  72. }
  73. }
  74. }
  75.  
  76. public client_connect( id )
  77. {
  78. cl_prefs[id] = 0;
  79. if( !is_user_bot( id ) )
  80. {
  81. if( get_pcvar_num( p_list_default ) ) cl_prefs[id] |= FL_LIST;
  82. if( get_pcvar_num( p_keys_default ) ) cl_prefs[id] |= FL_KEYS;
  83. }
  84. get_user_name( id, cl_names[id], 20 );
  85. return PLUGIN_CONTINUE;
  86. }
  87.  
  88. public client_infochanged( id )
  89. {
  90. get_user_name( id, cl_names[id], 20 );
  91. return PLUGIN_CONTINUE;
  92. }
  93.  
  94. public list_update( )
  95. {
  96. if( get_pcvar_num( p_enabled ) && get_pcvar_num ( p_list_enabled ) )
  97. {
  98. new players[32], num, id, id2, i, j;
  99. for( i = 1; i < 33; i++ ) spec_ids[i][0] = 0;
  100.  
  101. get_players( players, num, "bch" );
  102. for( i = 0; i < num; i++ )
  103. {
  104. id = players[i];
  105. if( !( get_user_flags( id ) & IMMUNE_FLAG && get_pcvar_num( p_immunity ) && cl_prefs[id] & FL_HIDE ) )
  106. {
  107. id2 = pev( id, pev_iuser2 );
  108. if( id2 )
  109. {
  110. spec_ids[ id2 ][ 0 ]++;
  111. spec_ids[ id2 ][ spec_ids[ id2 ][ 0 ] ] = id;
  112. }
  113. }
  114. }
  115. new tmplist[ LIST_STR_LEN + 1 ], tmpstr[41];
  116. new count, namelen, tmpname[21];
  117. for( i=1; i<33; i++ )
  118. {
  119. count = spec_ids[i][0];
  120. if( count )
  121. {
  122. namelen = ( LIST_STR_LEN - 10 ) / count;
  123. clamp( namelen, 10, 20 );
  124. format( tmpname, namelen, cl_names[i] );
  125. 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);
  126. for( j=1; j<=count; j++ )
  127. {
  128. format( tmpname, namelen, cl_names[spec_ids[i][j]]);
  129. 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 );
  130. if( strlen( tmplist ) + strlen( tmpstr ) + ( 11 - j ) < ( LIST_STR_LEN - 1 ) )
  131. format( tmplist, LIST_STR_LEN - 10, "%s%s^n", tmplist, tmpstr );
  132. else
  133. {
  134. format( tmplist, LIST_STR_LEN, "%s...^n", tmplist );
  135. break;
  136. }
  137. }
  138. if( count < 10 )
  139. format( tmplist, LIST_STR_LEN,
  140. "%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",
  141. tmplist, VERSION
  142. );
  143. for( j+=0; j<10; j++ )
  144. format( tmplist, LIST_STR_LEN, "%s%s", tmplist, "^n" );
  145. list_string[i] = tmplist;
  146. }
  147. }
  148. get_players( players, num, "ch" );
  149. for( i=0; i<num; i++ ) clmsg( players[i] );
  150. }
  151. return PLUGIN_HANDLED;
  152. }
  153.  
  154. public keys_update( )
  155. {
  156. if( !get_pcvar_num( p_enabled ) && !get_pcvar_num( p_keys_enabled ) ) return;
  157.  
  158. new players[32], num, id, i;
  159. get_players( players, num, "a" );
  160. for( i = 0; i < num; i++ )
  161. {
  162. id = players[i];
  163. 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",
  164. cl_keys[id] & IN_FORWARD ? "W" : " .",
  165. "%L",
  166. cl_keys[id] & IN_MOVELEFT ? "A" : ".",
  167. cl_keys[id] & IN_BACK ? "S" : ".",
  168. cl_keys[id] & IN_MOVERIGHT ? "D" : ".",
  169. "%L"
  170. , tCurFps[ id ]);
  171.  
  172. //Flags stored in string to fill translation char in clmsg function
  173. keys_string[id][0] = 0;
  174. if( cl_keys[id] & IN_JUMP ) keys_string[id][0] |= IN_JUMP;
  175. if( cl_keys[id] & IN_DUCK ) keys_string[id][0] |= IN_DUCK;
  176.  
  177. cl_keys[id] = 0;
  178. }
  179.  
  180. new id2;
  181. get_players( players, num, "ch" );
  182. for( i=0; i<num; i++ )
  183. {
  184. id = players[i];
  185. if( is_user_alive( id ) )
  186. {
  187. if( cl_prefs[id] & FL_OWNKEYS ) clmsg( id );
  188. }
  189. else
  190. {
  191. id2 = pev( id, pev_iuser2 );
  192. if( cl_prefs[id] & FL_KEYS && id2 && id2 != id ) clmsg( id );
  193. }
  194. }
  195.  
  196. }
  197.  
  198. public server_frame( )
  199. {
  200. if( get_pcvar_num( p_enabled ) && get_pcvar_num( p_keys_enabled ) )
  201. {
  202. new players[32], num, id;
  203. get_players( players, num, "a" );
  204. for( new i = 0; i < num; i++ )
  205. {
  206. id = players[i];
  207. if( get_user_button( id ) & IN_FORWARD )
  208. cl_keys[id] |= IN_FORWARD;
  209. if( get_user_button( id ) & IN_BACK )
  210. cl_keys[id] |= IN_BACK;
  211. if( get_user_button( id ) & IN_MOVELEFT )
  212. cl_keys[id] |= IN_MOVELEFT;
  213. if( get_user_button( id ) & IN_MOVERIGHT )
  214. cl_keys[id] |= IN_MOVERIGHT;
  215. if( get_user_button( id ) & IN_DUCK )
  216. cl_keys[id] |= IN_DUCK;
  217. if( get_user_button( id ) & IN_JUMP )
  218. cl_keys[id] |= IN_JUMP;
  219. }
  220. }
  221. return PLUGIN_CONTINUE
  222. }
  223.  
  224. public clmsg( id )
  225. {
  226. if( !id ) return;
  227.  
  228. new prefs = cl_prefs[id];
  229.  
  230. new bool:show_own = false;
  231. if( is_user_alive( id ) && prefs & FL_OWNKEYS ) show_own = true;
  232.  
  233. if( is_user_alive( id ) && !show_own )
  234. {
  235. if( prefs & FL_LIST && spec_ids[id][0] && get_pcvar_num( p_list_enabled ) )
  236. {
  237. set_hudmessage(42, 212, 255, 0.0, 0.17, 0, 6.0, 12.0
  238. );
  239. show_hudmessage( id, list_string[id], id, "SPECTATING" );
  240. }
  241. }
  242. else
  243. {
  244. new id2;
  245. if( show_own ) id2 = id;
  246. else id2 = pev( id, pev_iuser2 );
  247. if( !id2 ) return;
  248.  
  249. if( prefs & FL_LIST || prefs & FL_KEYS || show_own )
  250. {
  251. set_hudmessage(0, 0, 255, 0.05, 0.62, 0, 6.0, 12.0
  252. );
  253. new msg[BOTH_STR_LEN + 1];
  254. if( prefs & FL_LIST && get_pcvar_num( p_list_enabled ) && spec_ids[id2][0] )
  255. formatex(msg,BOTH_STR_LEN,list_string[id2],id,"SPECTATING");
  256. else msg ="^n^n^n^n^n^n^n^n^n^n^n^n";
  257. if( get_pcvar_num( p_keys_enabled ) && ( prefs & FL_KEYS || show_own ) )
  258. {
  259. format( msg, BOTH_STR_LEN, "%s%s", msg, keys_string[id2][1] );
  260. format( msg, BOTH_STR_LEN, msg,
  261. id, keys_string[id2][0] & IN_JUMP ? "JUMP" : "LAME",
  262. id, keys_string[id2][0] & IN_DUCK ? "DUCK" : "LAME"
  263. );
  264. }
  265. show_hudmessage( id, msg );
  266. }
  267. }
  268. }
  269.  
  270. public set_hudmsg_flg_notify( )
  271. {
  272. set_hudmessage(0, 0, 255, 0.05, 0.62, 0, 6.0, 12.0
  273.  
  274. );
  275. }
  276.  
  277. public toggle_list( id )
  278. {
  279. set_hudmsg_flg_notify( );
  280. cl_prefs[id] ^= FL_LIST;
  281. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_LIST ? "SPEC_LIST_ENABLED" : "SPEC_LIST_DISABLED" );
  282. return PLUGIN_HANDLED;
  283. }
  284.  
  285. public toggle_keys( id )
  286. {
  287. set_hudmsg_flg_notify( );
  288. cl_prefs[id] ^= FL_KEYS;
  289. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_KEYS ? "SPEC_KEYS_ENABLED" : "SPEC_KEYS_DISABLED" );
  290. return PLUGIN_HANDLED;
  291. }
  292.  
  293. public toggle_ownkeys( id )
  294. {
  295. set_hudmsg_flg_notify( );
  296. cl_prefs[id] ^= FL_OWNKEYS;
  297. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_OWNKEYS ? "SPEC_OWNKEYS_ENABLED" : "SPEC_OWNKEYS_DISABLED" );
  298. return PLUGIN_HANDLED;
  299. }
  300.  
  301. public toggle_hide( id, level, cid )
  302. {
  303. if( cmd_access( id, level, cid, 0 ) )
  304. {
  305. set_hudmsg_flg_notify( );
  306. cl_prefs[id] ^= FL_HIDE;
  307. show_hudmessage( id, "%L", id, cl_prefs[id] & FL_HIDE ? "SPEC_HIDE_ENABLED" : "SPEC_HIDE_DISABLED" );
  308. }
  309. return PLUGIN_HANDLED;
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement