HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.   Fordította: BBk - Death of Legend
  3. */
  4.  
  5. /*
  6.  *
  7.  * WillyumYum - Sniper Control
  8.  * (c) 2004-2005
  9.  *
  10.  * Sniper Rifle Restriction
  11.  * Based off of JustinHoMi's Awp Limit
  12.  * and OLO's Awp Control.
  13.  *
  14.  * Special thanks to BAILOPAN
  15.  * for some helpful 'flag' tips.
  16.  *
  17.  * Special thanks to AssKicR for
  18.  * pointing out hardcoding issues
  19.  *
  20.  *
  21.  */
  22.  
  23. #include <amxmodx>
  24. #include <amxmisc>
  25. #include <engine>
  26.  
  27. #pragma semicolon 1 // force ; usage, just 'cause
  28.  
  29. #define INCLUDE_SCOUT 1 // Include scouts in sniper rifle
  30.  
  31. new g_szTitle[] = "Sniper Rifle Control";
  32. new g_szVersion[] = "1.2";
  33. new g_szAuthor[] = "WillyumYum";
  34.  
  35. new g_iSniperNum[3]; // number of sniper rifles per team
  36.  
  37. new bool:g_bHasSniper[33]; // bool - true if player has a sniper rifle
  38.  
  39. new g_szWarn[] = "A csapatod elerte a sniper-korlat hatarat!";
  40.  
  41. new const SNIPERMODELS[4][] =
  42. {
  43. #if ( INCLUDE_SCOUT )
  44. "models/w_scout.mdl", // CSW_SCOUT
  45. #else
  46. "",
  47. #endif
  48. "models/w_sg550.mdl", // CSW_SG550
  49. "models/w_awp.mdl", // CSW_AWP
  50. "models/w_g3sg1.mdl" // CSW_G3SG1
  51. };
  52.  
  53. // Map disabled - original code by Ryan
  54.  
  55. public bool:Map_Disabled() {
  56.  
  57. new szDisabledFile[64];
  58. get_configsdir( szDisabledFile, 63 );
  59. format( szDisabledFile, 63, "%s/sc_disabled_maps.cfg", szDisabledFile );
  60.  
  61. if ( file_exists( szDisabledFile ) )
  62. {
  63. new iLineNum, szData[64], iTextLen;
  64.  
  65. while ( read_file( szDisabledFile, iLineNum, szData, 63, iTextLen ) )
  66. {
  67. new szMapName[64], szDisabledName[64];
  68.  
  69. get_mapname( szMapName, 63 );
  70. new iLen = copyc( szDisabledName, 63, szData, '*' );
  71.  
  72. if ( equali( szMapName, szDisabledName, iLen ) )
  73. return true;
  74.  
  75. iLineNum++;
  76. }
  77. }
  78.  
  79. return false;
  80. }
  81.  
  82. public menuSniper( id, key ) {
  83.  
  84. if ( !get_cvar_num( "mp_sniper_control" ) )
  85. return PLUGIN_CONTINUE;
  86.  
  87. new iTeam = get_user_team( id );
  88.  
  89. if ( iTeam == 1 && ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_t" ) || g_bHasSniper[id] ) ) // TERRORIST
  90. return PLUGIN_CONTINUE;
  91. else
  92. if ( iTeam == 2 && ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_ct" ) || g_bHasSniper[id] ) ) // COUNTER-TERRORIST
  93. return PLUGIN_CONTINUE;
  94.  
  95. if( iTeam == 1 && key == 1 ) // Allows T's tp buy ak-47, but blocks CT's from buying scout
  96. return PLUGIN_CONTINUE;
  97. else
  98. if( iTeam == 2 && key == 2 ) // Allows CT's to buy m4, but blocks T's from buying scout
  99. return PLUGIN_CONTINUE;
  100.  
  101. engclient_cmd( id, "menuselect" ,"10");
  102. client_print( id, print_center , g_szWarn );
  103.  
  104. return PLUGIN_HANDLED;
  105. }
  106.  
  107. public bool:check_primary( id ) {
  108.  
  109. new iWeapons[32];
  110. new iTotalWeapons = 0;
  111. get_user_weapons( id, iWeapons, iTotalWeapons );
  112.  
  113. for ( new i = 0; i < iTotalWeapons; i++ )
  114. {
  115. switch ( iWeapons[i] )
  116. {
  117. case CSW_M3: return true;
  118. case CSW_XM1014: return true;
  119. case CSW_MP5NAVY: return true;
  120. case CSW_TMP: return true;
  121. case CSW_P90: return true;
  122. case CSW_MAC10: return true;
  123. case CSW_UMP45: return true;
  124. case CSW_AK47: return true;
  125. case CSW_SG552: return true;
  126. case CSW_GALI: return true;
  127. case CSW_FAMAS: return true;
  128. case CSW_M4A1: return true;
  129. case CSW_AUG: return true;
  130. case CSW_SCOUT: return true;
  131. case CSW_AWP: return true;
  132. case CSW_G3SG1: return true;
  133. case CSW_SG550: return true;
  134. case CSW_M249: return true;
  135. }
  136. }
  137. return false;
  138. }
  139.  
  140. public bool:check_sniper( id ) {
  141.  
  142. new iWeapons[32];
  143. new iTotalWeapons = 0;
  144. get_user_weapons( id, iWeapons, iTotalWeapons );
  145.  
  146. for ( new i = 0; i < iTotalWeapons; i++ )
  147. {
  148. switch ( iWeapons[i] )
  149. {
  150. #if ( INCLUDE_SCOUT )
  151. case CSW_SCOUT: return true;
  152. #else
  153. case CSW_SCOUT: return false;
  154. #endif
  155.  
  156. case CSW_AWP: return true;
  157. case CSW_G3SG1: return true;
  158. case CSW_SG550: return true;
  159. }
  160. }
  161. return false;
  162. }
  163.  
  164. public vexd_pfntouch(pToucher, pTouched) {
  165.  
  166. if ( !get_cvar_num( "mp_sniper_control" ) )
  167. return PLUGIN_CONTINUE;
  168.  
  169. new iTouchId = pToucher;
  170. new iPlayerId = pTouched;
  171.  
  172. if ( iPlayerId < 0 || iPlayerId > 32 || !is_user_alive( iPlayerId ) )
  173. return PLUGIN_CONTINUE;
  174.  
  175. new szClassName[32];
  176. entity_get_string( iTouchId, EV_SZ_classname, szClassName, 31 );
  177.  
  178. if ( equal( szClassName, "weaponbox" ) ) // a dropped or already 'fired' weapon
  179. {
  180. new szGunModel[32];
  181. entity_get_string( iTouchId, EV_SZ_model, szGunModel, 31 );
  182.  
  183. new bool:bHasPrimaryWeapon = check_primary( iPlayerId );
  184.  
  185. for ( new i = 0; i < 4; i++ )
  186. {
  187. if ( get_entity_flags( iTouchId ) & FL_ONGROUND && !bHasPrimaryWeapon && equal( szGunModel, SNIPERMODELS[i] ) )
  188. {
  189. set_entity_flags( iTouchId, FL_ONGROUND, 0 );
  190.  
  191. new iTeam = get_user_team( iPlayerId );
  192.  
  193. if ( iTeam == 1 ) // TERRORIST
  194. {
  195. if ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_t" ) )
  196. {
  197. set_entity_flags( iTouchId, FL_ONGROUND, 1 );
  198. }
  199. else
  200. {
  201. client_print( iPlayerId, print_center , g_szWarn );
  202. }
  203. }
  204. else
  205. if ( iTeam == 2 ) // COUNTER-TERRORIST
  206. {
  207. if ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_ct" ) )
  208. {
  209. set_entity_flags( iTouchId, FL_ONGROUND, 1 );
  210. }
  211. else
  212. {
  213. client_print( iPlayerId, print_center , g_szWarn );
  214. }
  215. }
  216. break;
  217. }
  218. }
  219. }
  220. return PLUGIN_CONTINUE;
  221. }
  222.  
  223. public cmdDrop( id ) {
  224.  
  225. if ( !get_cvar_num( "mp_sniper_control" ) )
  226. return PLUGIN_CONTINUE;
  227.  
  228. new iTeam = get_user_team( id );
  229.  
  230. new iAmmo, iClip;
  231. new iWeap = get_user_weapon( id, iAmmo, iClip );
  232.  
  233. if ( check_sniper( id ) && ( iWeap == CSW_AWP || iWeap == CSW_G3SG1 || iWeap == CSW_SG550 ) )
  234. {
  235. g_bHasSniper[id] = false;
  236. --g_iSniperNum[iTeam];
  237.  
  238. }
  239. #if ( INCLUDE_SCOUT )
  240.  
  241. else
  242. if( check_sniper( id ) && iWeap == CSW_SCOUT )
  243. {
  244. g_bHasSniper[id] = false;
  245. --g_iSniperNum[iTeam];
  246. }
  247.  
  248. #endif
  249.  
  250. return PLUGIN_CONTINUE;
  251. }
  252.  
  253. public evPickUp( id ) {
  254.  
  255. if ( !get_cvar_num( "mp_sniper_control" ) )
  256. return PLUGIN_CONTINUE;
  257.  
  258. new iTeam = get_user_team( id );
  259.  
  260. if( check_sniper( id ) && !g_bHasSniper[id] )
  261. {
  262. g_bHasSniper[id] = true;
  263. ++g_iSniperNum[iTeam];
  264. }
  265.  
  266. if ( g_bHasSniper[id] && !check_sniper( id ) )
  267. {
  268. // Has a primary weapon and HAD sniper, but bought new non-sniper rifle weapon ( no drop event )
  269.  
  270. g_bHasSniper[id] = false;
  271. --g_iSniperNum[iTeam];
  272. }
  273.  
  274. return PLUGIN_CONTINUE;
  275. }
  276.  
  277. public evRestartRound() {
  278.  
  279. if ( !get_cvar_num( "mp_sniper_control" ) )
  280. return PLUGIN_CONTINUE;
  281.  
  282. g_iSniperNum[0] = g_iSniperNum[1] = g_iSniperNum[2] = 0;
  283.  
  284. for(new a = 1; a < 33; ++a)
  285. g_bHasSniper[a] = false;
  286.  
  287. return PLUGIN_CONTINUE;
  288. }
  289.  
  290. public sc_remove_data( id ) {
  291.  
  292. new iTeam = get_user_team( id );
  293.  
  294. if ( g_bHasSniper[id] )
  295. {
  296. g_bHasSniper[id] = false;
  297. --g_iSniperNum[iTeam];
  298. }
  299.  
  300. return PLUGIN_CONTINUE;
  301. }
  302.  
  303. public client_disconnect( id ) {
  304.  
  305. if ( !get_cvar_num( "mp_sniper_control" ) )
  306. return PLUGIN_CONTINUE;
  307.  
  308. sc_remove_data( id );
  309.  
  310. return PLUGIN_CONTINUE;
  311. }
  312.  
  313. public evDeath() {
  314.  
  315. new id = read_data(2);
  316. sc_remove_data( id );
  317.  
  318. return PLUGIN_CONTINUE;
  319. }
  320.  
  321. public plugin_init() {
  322.  
  323. register_plugin( g_szTitle, g_szVersion, g_szAuthor );
  324.  
  325. // set defaults ( for non 'sniper_control.cfg' users )
  326.  
  327. register_cvar( "mp_sniper_control", "1" );
  328. register_cvar( "sc_max_snipers_t", "2" );
  329. register_cvar( "sc_max_snipers_ct", "2" );
  330.  
  331. // Standard Menus
  332.  
  333. register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<4), "menuSniper" ); // T: AWP, CT: Sig SG-550 Sniper
  334. register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<5), "menuSniper" ); // CT: AWP, T: H&K G3/SG-1 Sniper Rifle
  335.  
  336.  
  337. // Block Aliases and Vgui menus - because steam sucks and uses aliases to buy rifles ?!?!?
  338.  
  339. register_clcmd("awp", "menuSniper");
  340. register_clcmd("magnum", "menuSniper");
  341. register_clcmd("g3sg1", "menuSniper");
  342. register_clcmd("d3au1", "menuSniper");
  343. register_clcmd("sg550", "menuSniper");
  344. register_clcmd("krieg550", "menuSniper");
  345.  
  346. register_menucmd( -31 ,(1<<4), "menuSniper" ); // T: AWP, CT: Sig SG-550 Sniper - VGUI
  347. register_menucmd( -31 ,(1<<5), "menuSniper" ); // CT: AWP, T: H&K G3/SG-1 Sniper Rifle - VGUI
  348.  
  349. #if ( INCLUDE_SCOUT )
  350.  
  351. register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<1), "menuSniper" ); // CT: Scout - Standard
  352. register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<2), "menuSniper" ); // T: Scout - Standard
  353.  
  354. register_clcmd("scout", "menuSniper");
  355.  
  356. register_menucmd( -31 ,(1<<1), "menuSniper" ); // CT: Scout - VGUI
  357. register_menucmd( -31 ,(1<<2), "menuSniper" ); // T: Scout - VGUI
  358.  
  359. #endif
  360.  
  361. register_event( "WeapPickup", "evPickUp", "b" ); // 3 = Scout, 13 = SG-550, 18 = AWP, G3/SG-1
  362. register_clcmd( "drop", "cmdDrop" );
  363. register_event( "DeathMsg", "evDeath", "a" );
  364. register_event( "TextMsg", "evRestartRound", "a", "2&Game_C", "2&Game_w" );
  365.  
  366. if ( !Map_Disabled() )
  367. {
  368. new szConfigFile[64];
  369. get_configsdir( szConfigFile, 63 );
  370. format( szConfigFile, 63, "%s/sniper_control.cfg", szConfigFile );
  371. server_cmd( "exec %s", szConfigFile ); // load configuration settings
  372. }
  373. else
  374. {
  375. set_cvar_num( "mp_sniper_control", 0 );
  376. }
  377.  
  378. return PLUGIN_CONTINUE;
  379. }