HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Changelog:
  3. 3.2 - code optimization
  4. 3.1 - added a cvar to help you handle the holdtime of the hud message
  5. 3.0 - major improvements in the code; from now on, the nvault module is a requirement; - the restriction system is now using steam ids to ban users from participating to the event.
  6. 2.3 - added a cvar for a random amount of money
  7. 2.2 - added a restriction system
  8. 2.1 - temporary solution for % and ;
  9. 2.0 - new random system
  10. - code optimization
  11.  
  12. 1.0 - first release
  13.  
  14. Credits:
  15. ConnorMcLeod - code improvement
  16. YamiKaitou - code improvement
  17.  
  18. */
  19.  
  20. #include < amxmodx >
  21. #include < amxmisc >
  22. #include < cstrike >
  23. #include < nvault >
  24.  
  25. #define PLUGIN_NAME "Fast typing event"
  26. #define PLUGIN_AUTHOR "floatman" // Fordította: Traops (CoopCola)
  27. #define PLUGIN_VERSION "3.2"
  28.  
  29. #define FLAGS 9
  30.  
  31. const TASK_CLEAR = 258;
  32.  
  33. new g_Codename[ 20 ];
  34. new g_On = 0;
  35. new g_Time, g_Prize, g_RepTime;
  36. new g_Random, g_Min, g_Max, g_HoldTime;
  37.  
  38. new g_Restriction[ 33 ] = 0;
  39.  
  40. new g_SyncHudMsg;
  41.  
  42. public plugin_init()
  43. {
  44. register_plugin( PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR );
  45.  
  46. register_clcmd( "say", "cmdentered" );
  47. register_clcmd( "say_team", "cmdentered" );
  48.  
  49. register_concmd( "amx_restrict", "cmdRestrict", ADMIN_BAN, " < name > - restricts a player from taking part of the event." );
  50. register_concmd( "amx_delrestrict", "cmdUnRestrict", ADMIN_BAN, " < name > - deleting the restriction of a player." );
  51.  
  52. register_dictionary( "fastevent.txt" );
  53.  
  54. register_cvar( "fevent_version", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY );
  55. set_cvar_string( "fevent_version", PLUGIN_VERSION );
  56.  
  57. g_Time = register_cvar( "fastev_responsetime", "20.0" );
  58. g_Prize = register_cvar( "fastev_moneyprize", "5000" );
  59. g_RepTime = register_cvar( "fastev_repeattime", "120.0" );
  60. g_Random = register_cvar( "fastev_randomamount", "1" );
  61. g_Min = register_cvar( "fastev_randommin", "500" );
  62. g_Max = register_cvar( "fastev_randommax", "5000" );
  63. g_HoldTime = register_cvar( "fastev_hudtime", "25.0" );
  64.  
  65. g_SyncHudMsg = CreateHudSyncObj();
  66. }
  67.  
  68. public plugin_cfg()
  69. {
  70. set_task( get_pcvar_float( g_RepTime ), "create", _, _, _, "b" );
  71. }
  72.  
  73. public client_putinserver( i_Index )
  74. {
  75. LoadRestriction( i_Index );
  76. }
  77.  
  78. public cmdRestrict( i_Index, iLevel, iCid )
  79. {
  80. if( !cmd_access( i_Index, iLevel, iCid, 2 ) )
  81. return PLUGIN_HANDLED;
  82.  
  83. new szArg[ 32 ];
  84. read_argv( 1, szArg, charsmax( szArg ) )
  85.  
  86. new iPlayer = cmd_target( i_Index, szArg, FLAGS );
  87.  
  88. if( !iPlayer )
  89. return PLUGIN_HANDLED;
  90.  
  91. new szName[ 32 ];
  92. get_user_name( iPlayer, szName, charsmax( szName ) );
  93.  
  94. if( !g_Restriction[ iPlayer ] )
  95. {
  96. g_Restriction[ iPlayer ] = 1;
  97. SaveRestriction( iPlayer );
  98.  
  99. client_print( i_Index, print_chat, "{FEVENT] %L", LANG_PLAYER, "RESTRICTION_ADDED", szName );
  100. }
  101.  
  102. else
  103. {
  104. client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "HAS_RESTRICTION", szName );
  105. }
  106.  
  107. return PLUGIN_HANDLED;
  108. }
  109.  
  110. public cmdUnRestrict( i_Index, iLevel, iCid )
  111. {
  112. if( !cmd_access( i_Index, iLevel, iCid, 2 ) )
  113. return PLUGIN_HANDLED;
  114.  
  115. new szArg[ 32 ];
  116. read_argv( 1, szArg, charsmax( szArg ) )
  117.  
  118. new iPlayer = cmd_target( i_Index, szArg, FLAGS );
  119.  
  120. if( !iPlayer )
  121. return PLUGIN_HANDLED;
  122.  
  123. new szName[ 32 ];
  124. get_user_name( iPlayer, szName, charsmax( szName ) );
  125.  
  126. if( g_Restriction[ iPlayer ] )
  127. {
  128. g_Restriction[ iPlayer ] = 0;
  129. SaveRestriction( iPlayer );
  130.  
  131. client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "RESTRICTION_DELETED", szName );
  132. }
  133.  
  134. return PLUGIN_HANDLED;
  135. }
  136.  
  137. public create()
  138. {
  139. g_On = 1;
  140.  
  141. for( new j = 0; j < sizeof g_Codename - 1; j++ )
  142. {
  143. g_Codename[ j ] = random_num( '!', '~' );
  144.  
  145. if( g_Codename[ j ] == ';' )
  146. g_Codename[ j ] = ',';
  147.  
  148. }
  149.  
  150. new Float:holdtime = get_pcvar_float( g_HoldTime );
  151. new Float:repeattime = get_pcvar_float( g_RepTime );
  152.  
  153. if( holdtime > repeattime )
  154. {
  155. holdtime = repeattime - 5.0;
  156. }
  157.  
  158. new Float:cleartime = get_pcvar_float( g_Time );
  159. set_task( cleartime, "clear_vars", TASK_CLEAR );
  160.  
  161. set_hudmessage( 0, 255, 0, 0.07, 0.21, 0, 6.0, holdtime, _, _, -1 );
  162. ShowSyncHudMsg( 0, g_SyncHudMsg, "[FEVENT] %L", LANG_PLAYER, "NEW_CODE", g_Codename );
  163. }
  164.  
  165. public clear_vars()
  166. {
  167. if( task_exists( TASK_CLEAR ) )
  168. remove_task( TASK_CLEAR );
  169.  
  170. g_Codename[ 0 ] = EOS;
  171. g_On = 0;
  172. }
  173.  
  174. public cmdentered( i_Index )
  175. {
  176. if( g_On == 1 )
  177. {
  178. new szSaid[ 192 ];
  179. read_args( szSaid, charsmax( szSaid ) );
  180. remove_quotes( szSaid );
  181. trim( szSaid );
  182.  
  183. if( equal( szSaid, g_Codename ) )
  184. {
  185. new szName[ 32 ];
  186. get_user_name( i_Index, szName, charsmax( szName ) );
  187.  
  188. if( g_Restriction[ i_Index ] )
  189. {
  190. client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "CODE_NOTACCESS" );
  191. return PLUGIN_HANDLED;
  192. }
  193.  
  194. if( get_pcvar_num( g_Random ) && ( get_pcvar_num( g_Min ) < get_pcvar_num( g_Max ) ) && ( get_pcvar_num( g_Max ) > 0 ) )
  195. {
  196. new iAmmount = random_num( get_pcvar_num( g_Min ), get_pcvar_num( g_Max ) );
  197. cs_set_user_money( i_Index, (cs_get_user_money(i_Index) + iAmmount) );
  198. client_print( 0, print_chat, "[FEVENT] %L", LANG_PLAYER, "ANNOUNCE_WINNER", szName, iAmmount );
  199. }
  200.  
  201. else
  202. {
  203. cs_set_user_money( i_Index, (cs_get_user_money(i_Index) + get_pcvar_num(g_Prize)) );
  204. client_print( 0, print_chat, "[FEVENT] %L", LANG_PLAYER, "ANNOUNCE_WINNER", szName, get_pcvar_num(g_Prize) );
  205.  
  206. }
  207.  
  208. g_On = 0;
  209. }
  210.  
  211. if( equali( szSaid, "" ) )
  212. return PLUGIN_HANDLED;
  213. }
  214.  
  215. return PLUGIN_CONTINUE;
  216. }
  217.  
  218. public SaveRestriction( i_Index )
  219. {
  220. new vault = nvault_open( "fevent_restrictions" );
  221.  
  222. new iKey[ 64 ], iValue[ 64 ], szAuth[ 32 ];
  223. get_user_authid( i_Index, szAuth, charsmax( szAuth ) );
  224.  
  225. formatex( iKey, charsmax( iKey ), "%s", szAuth );
  226. formatex( iValue, charsmax( iValue ), "%d", g_Restriction[ i_Index ] );
  227.  
  228. nvault_set( vault, iKey, iValue );
  229. nvault_close( vault );
  230. }
  231.  
  232. public LoadRestriction( i_Index )
  233. {
  234. new vault = nvault_open( "fevent_restrictions" );
  235.  
  236. new iKey[ 64 ], iValue[ 64 ], szAuth[ 32 ];
  237. get_user_authid( i_Index, szAuth, charsmax( szAuth ) );
  238.  
  239. formatex( iKey, charsmax( iKey ), "%s", szAuth );
  240.  
  241. nvault_get( vault, iKey, iValue, charsmax( iValue ) );
  242. nvault_close( vault );
  243.  
  244. g_Restriction[ i_Index ] = str_to_num( iValue );
  245. }