Advertisement
ColdWar-Pawn

Voteban

May 4th, 2013
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.60 KB | None | 0 0
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include < amxmodx >
  4.  
  5. enum _:Cvars
  6. {
  7.     Toggle,
  8.     Percent,
  9.     Delay,
  10.     BanTime,
  11.     BanReason,
  12.     BanType,
  13.     MinPlayers
  14. }
  15.  
  16. new const szCvarNames[ Cvars ][ ] = {
  17.     "amx_voteban_toggle",
  18.     "amx_voteban_percent",
  19.     "amx_voteban_delay",
  20.     "amx_voteban_bantime",
  21.     "amx_voteban_banreason",
  22.     "amx_voteban_bantype",
  23.     "amx_voteban_minplayers"
  24. }
  25.  
  26. new const szCvarDefaultValues[ Cvars ][ ] = {
  27.     "1",
  28.     "60",
  29.     "120.0",
  30.     "30",
  31.     "You have been vote to be banned",
  32.     "0", // 0 = IP | Else = Auth
  33.     "2"
  34. }
  35.  
  36. new g_pCvars[ Cvars ];
  37.  
  38. new Float: g_flLastVote[ 33 ];
  39.  
  40. new g_bVoting, g_iVoteTarget, g_iVotes[ 2 ];
  41.  
  42. new g_iMaxPlayers;
  43.  
  44. public plugin_init()
  45. {
  46.     register_plugin( "Voteban", "v1.0", "+ColdWar" )
  47.    
  48.     for( new i = 0 ; i < Cvars ; i ++ )
  49.         g_pCvars[ i ] = register_cvar( szCvarNames[ i ], szCvarDefaultValues[ i ] );
  50.    
  51.     register_saycmd( "voteban", "Cmd_VoteBan" );
  52.    
  53.     g_iMaxPlayers = get_maxplayers( );
  54. }
  55.  
  56. public Cmd_VoteBan( client )
  57. {
  58.     if( !get_pcvar_num( g_pCvars[ Toggle ] ) )
  59.         return ColorChat( client, "You cannot use ^3voteban^1 because it's disabled" );
  60.     else if( g_flLastVote[ client ] > 0.0 && get_gametime( ) - g_flLastVote[ client ] < get_pcvar_float( g_pCvars[ Delay ] ) )
  61.         return ColorChat( client, "You cannot use ^3voteban^1 yet, you must wait ^4%i^1 seconds.", floatround( get_pcvar_float( g_pCvars[ Delay ] ) + g_flLastVote[ client ] - get_gametime( ) ) );
  62.     else if( g_bVoting )
  63.         return ColorChat( client, "You cannot use ^3voteban^1 because there is already a ^3voteban^1 activated." );
  64.     else if( get_playersnum( ) < get_pcvar_num( g_pCvars[ MinPlayers ] ) )
  65.         return ColorChat( client, "You cannot use ^3voteban^1 because minimum players is ^4%i^1.", get_pcvar_num( g_pCvars[ MinPlayers ] ) );
  66.    
  67.    
  68.     new iMenu = menu_create( "\r[AMXX]\w Voteban menu^nChoose your voteban target:", "sub_votetarget" );
  69.     new szName[ 32 ], szNumber[ 4 ];
  70.    
  71.     for( new i = 1 ; i <= g_iMaxPlayers ; i ++ )
  72.     {
  73.         if( !is_user_connected( i ) || get_user_flags( i ) & ADMIN_IMMUNITY || client == i )
  74.             continue;
  75.        
  76.         get_user_name( i, szName, charsmax( szName ) );
  77.         num_to_str( i, szNumber, charsmax( szNumber ) );
  78.        
  79.         menu_additem( iMenu, szName, szNumber );
  80.     }
  81.    
  82.     if( !menu_items( iMenu ) )
  83.     {
  84.         menu_destroy( iMenu )
  85.         return ColorChat( client, "No targets to ^3voteban^1 detected." );
  86.     }
  87.    
  88.     menu_display( client, iMenu );
  89.     return 1;
  90. }
  91.  
  92. public sub_votetarget( client, iMenu, item )
  93. {
  94.     if( item == MENU_EXIT )
  95.         return menu_destroy( iMenu );
  96.     else if( g_bVoting )
  97.     {
  98.         menu_destroy( iMenu );
  99.         return ColorChat( client, "Another ^3voteban^1 has been started, wait for it's end." );
  100.     }
  101.    
  102.     new szData[ 4 ], iAccess, iCallback;
  103.    
  104.     menu_item_getinfo( iMenu, item, iAccess, szData, sizeof szData - 1, _, _, iCallback );
  105.    
  106.     g_iVoteTarget = str_to_num( szData );
  107.    
  108.     if( !is_user_connected( g_iVoteTarget ) )
  109.         return ColorChat( client, "Your target to ^3voteban^1 is no longer connected." );
  110.    
  111.     g_flLastVote[ client ] = get_gametime( );
  112.     CmdStartVote( g_iVoteTarget );
  113.     return 1;
  114. }
  115.  
  116. public CmdStartVote( target )
  117. {
  118.     new szSubject[ 82 ], iMenu;
  119.     get_user_name( g_iVoteTarget, szSubject, charsmax( szSubject ) );
  120.     format( szSubject, charsmax( szSubject ), "\r[AMXX]\w Voteban menu^nWould you like to ban \y%s\w?", szSubject );      
  121.    
  122.     iMenu = menu_create( szSubject, "sub_vote" );
  123.    
  124.     menu_additem( iMenu, "Yes" );
  125.     menu_additem( iMenu, "No" );
  126.    
  127.     g_iVotes[0]=0;
  128.     g_iVotes[1]=0;
  129.    
  130.     g_bVoting = true;
  131.    
  132.     for( new i = 1 ; i <= g_iMaxPlayers ; i ++ )
  133.     {
  134.         if( !is_user_connected( i ) || target == i )
  135.             continue;
  136.        
  137.         menu_display( i, iMenu );
  138.     }
  139.    
  140.     set_task( 10.0, "Cmd_VoteEnd", 818 );
  141. }
  142.  
  143. public sub_vote( client, iMenu, item )
  144. {
  145.     menu_destroy( iMenu );
  146.    
  147.     if( item == MENU_EXIT || !g_bVoting )
  148.         return 1;
  149.    
  150.     g_iVotes[item] ++;
  151.     new szName[ 32 ];
  152.     get_user_name( client, szName, charsmax( szName ) );
  153.    
  154.     return ColorChat( 0, "^3%s^1 has chosen ^4#%i^1.", szName, item );
  155. }
  156.  
  157. public Cmd_VoteEnd( )
  158. {
  159.     g_bVoting = false;
  160.     if( !is_user_connected( g_iVoteTarget ) )
  161.         return ColorChat( 0, "The ^3voteban^1 failed, target disconnected" );
  162.    
  163.     new totalvotes = g_iVotes[ 0 ] + g_iVotes[ 1 ], szName[ 32 ];
  164.    
  165.     get_user_name( g_iVoteTarget, szName, charsmax( szName ) );
  166.    
  167.     if( check_percent( totalvotes, g_iVotes[ 0 ], get_pcvar_num( g_pCvars[ Percent ] ) ) )
  168.     {
  169.         new szBanReason[ 64 ], szCommand[ 11 ], szSrvCmd[ 75 ];
  170.         get_pcvar_string( g_pCvars[ BanReason ], szBanReason, charsmax( szBanReason ) );
  171.         if( get_pcvar_num( g_pCvars[ BanType ] ) )
  172.             formatex( szCommand, charsmax( szCommand ), "amx_ban" );
  173.         else
  174.             formatex( szCommand, charsmax( szCommand ), "amx_banip" );
  175.            
  176.         formatex( szSrvCmd, charsmax( szSrvCmd ), "%s #%i %i ^"%s^"", szCommand, get_user_userid( g_iVoteTarget ), get_pcvar_num( g_pCvars[ BanTime ] ), szBanReason );
  177.        
  178.         server_cmd( szSrvCmd );
  179.         return ColorChat( 0, "The ^3voteban^1 has succeded, ^4%s^1 has been banned.", szName );
  180.     }
  181.     else
  182.         return ColorChat( 0, "The ^3voteban^1 has failed, ^4%s^1 hasn't been banned.", szName );
  183.    
  184.     return 0;
  185. }
  186.  
  187. stock bool: check_percent( total, yes, percent )
  188. {
  189.     if( !yes || !total )
  190.         return false;
  191.    
  192.     new Float: g_flPercent = float( yes ) / float( total );
  193.     g_flPercent *= 100.0;
  194.    
  195.     if( floatround( g_flPercent ) > percent )
  196.         return true;
  197.    
  198.     return false;
  199. }
  200.  
  201. stock register_saycmd( const cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1 )
  202. {
  203.     new i, j;
  204.     new szString[ 64 ];
  205.     new const szSayTypes[ ][ ] = { "say", "say_team" };
  206.     new const szTypes[ ][ ] = { "/", "!", "." };
  207.     for( i = 0 ; i < sizeof szSayTypes ; i ++ )
  208.     {
  209.         for( j = 0 ; j < sizeof szTypes ; j ++ )
  210.         {
  211.             formatex( szString, sizeof szString - 1, "%s %s%s", szSayTypes[ i ], szTypes[ j ], cmd );
  212.             register_clcmd( szString, function, flags, info, FlagManager );
  213.         }
  214.     }
  215. }
  216.  
  217. stock ColorChat( index, message[], any:... )
  218. {
  219.     if( index && !is_user_connected( index ) )
  220.         return 0;
  221.    
  222.     static szMessage[ 242 ], len;
  223.    
  224.     len = formatex( szMessage, charsmax( szMessage ), "^4[AMXX]^1 " );
  225.     len += vformat( szMessage[ len ], charsmax( szMessage ) - len, message, 3 );
  226.    
  227.     static st_msgid;
  228.     if( !st_msgid )
  229.         st_msgid = get_user_msgid( "SayText" );
  230.    
  231.     if( index )
  232.     {
  233.         message_begin( MSG_ONE_UNRELIABLE, st_msgid, _, index );
  234.         write_byte( index );
  235.         write_string( szMessage );
  236.         message_end( );
  237.     }
  238.     else
  239.     {
  240.         for( index = 1 ; index <= g_iMaxPlayers ; index ++ )
  241.         {
  242.             if( !is_user_connected( index ) )
  243.                 continue;
  244.            
  245.             message_begin( MSG_ONE_UNRELIABLE, st_msgid, _, index );
  246.             write_byte( index );
  247.             write_string( szMessage );
  248.             message_end( );
  249.         }
  250.     }
  251.     return 1;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement