Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Plugin generated by AMXX-Studio */
- #include < amxmodx >
- enum _:Cvars
- {
- Toggle,
- Percent,
- Delay,
- BanTime,
- BanReason,
- BanType,
- MinPlayers
- }
- new const szCvarNames[ Cvars ][ ] = {
- "amx_voteban_toggle",
- "amx_voteban_percent",
- "amx_voteban_delay",
- "amx_voteban_bantime",
- "amx_voteban_banreason",
- "amx_voteban_bantype",
- "amx_voteban_minplayers"
- }
- new const szCvarDefaultValues[ Cvars ][ ] = {
- "1",
- "60",
- "120.0",
- "30",
- "You have been vote to be banned",
- "0", // 0 = IP | Else = Auth
- "2"
- }
- new g_pCvars[ Cvars ];
- new Float: g_flLastVote[ 33 ];
- new g_bVoting, g_iVoteTarget, g_iVotes[ 2 ];
- new g_iMaxPlayers;
- public plugin_init()
- {
- register_plugin( "Voteban", "v1.0", "+ColdWar" )
- for( new i = 0 ; i < Cvars ; i ++ )
- g_pCvars[ i ] = register_cvar( szCvarNames[ i ], szCvarDefaultValues[ i ] );
- register_saycmd( "voteban", "Cmd_VoteBan" );
- g_iMaxPlayers = get_maxplayers( );
- }
- public Cmd_VoteBan( client )
- {
- if( !get_pcvar_num( g_pCvars[ Toggle ] ) )
- return ColorChat( client, "You cannot use ^3voteban^1 because it's disabled" );
- else if( g_flLastVote[ client ] > 0.0 && get_gametime( ) - g_flLastVote[ client ] < get_pcvar_float( g_pCvars[ Delay ] ) )
- 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( ) ) );
- else if( g_bVoting )
- return ColorChat( client, "You cannot use ^3voteban^1 because there is already a ^3voteban^1 activated." );
- else if( get_playersnum( ) < get_pcvar_num( g_pCvars[ MinPlayers ] ) )
- return ColorChat( client, "You cannot use ^3voteban^1 because minimum players is ^4%i^1.", get_pcvar_num( g_pCvars[ MinPlayers ] ) );
- new iMenu = menu_create( "\r[AMXX]\w Voteban menu^nChoose your voteban target:", "sub_votetarget" );
- new szName[ 32 ], szNumber[ 4 ];
- for( new i = 1 ; i <= g_iMaxPlayers ; i ++ )
- {
- if( !is_user_connected( i ) || get_user_flags( i ) & ADMIN_IMMUNITY || client == i )
- continue;
- get_user_name( i, szName, charsmax( szName ) );
- num_to_str( i, szNumber, charsmax( szNumber ) );
- menu_additem( iMenu, szName, szNumber );
- }
- if( !menu_items( iMenu ) )
- {
- menu_destroy( iMenu )
- return ColorChat( client, "No targets to ^3voteban^1 detected." );
- }
- menu_display( client, iMenu );
- return 1;
- }
- public sub_votetarget( client, iMenu, item )
- {
- if( item == MENU_EXIT )
- return menu_destroy( iMenu );
- else if( g_bVoting )
- {
- menu_destroy( iMenu );
- return ColorChat( client, "Another ^3voteban^1 has been started, wait for it's end." );
- }
- new szData[ 4 ], iAccess, iCallback;
- menu_item_getinfo( iMenu, item, iAccess, szData, sizeof szData - 1, _, _, iCallback );
- g_iVoteTarget = str_to_num( szData );
- if( !is_user_connected( g_iVoteTarget ) )
- return ColorChat( client, "Your target to ^3voteban^1 is no longer connected." );
- g_flLastVote[ client ] = get_gametime( );
- CmdStartVote( g_iVoteTarget );
- return 1;
- }
- public CmdStartVote( target )
- {
- new szSubject[ 82 ], iMenu;
- get_user_name( g_iVoteTarget, szSubject, charsmax( szSubject ) );
- format( szSubject, charsmax( szSubject ), "\r[AMXX]\w Voteban menu^nWould you like to ban \y%s\w?", szSubject );
- iMenu = menu_create( szSubject, "sub_vote" );
- menu_additem( iMenu, "Yes" );
- menu_additem( iMenu, "No" );
- g_iVotes[0]=0;
- g_iVotes[1]=0;
- g_bVoting = true;
- for( new i = 1 ; i <= g_iMaxPlayers ; i ++ )
- {
- if( !is_user_connected( i ) || target == i )
- continue;
- menu_display( i, iMenu );
- }
- set_task( 10.0, "Cmd_VoteEnd", 818 );
- }
- public sub_vote( client, iMenu, item )
- {
- menu_destroy( iMenu );
- if( item == MENU_EXIT || !g_bVoting )
- return 1;
- g_iVotes[item] ++;
- new szName[ 32 ];
- get_user_name( client, szName, charsmax( szName ) );
- return ColorChat( 0, "^3%s^1 has chosen ^4#%i^1.", szName, item );
- }
- public Cmd_VoteEnd( )
- {
- g_bVoting = false;
- if( !is_user_connected( g_iVoteTarget ) )
- return ColorChat( 0, "The ^3voteban^1 failed, target disconnected" );
- new totalvotes = g_iVotes[ 0 ] + g_iVotes[ 1 ], szName[ 32 ];
- get_user_name( g_iVoteTarget, szName, charsmax( szName ) );
- if( check_percent( totalvotes, g_iVotes[ 0 ], get_pcvar_num( g_pCvars[ Percent ] ) ) )
- {
- new szBanReason[ 64 ], szCommand[ 11 ], szSrvCmd[ 75 ];
- get_pcvar_string( g_pCvars[ BanReason ], szBanReason, charsmax( szBanReason ) );
- if( get_pcvar_num( g_pCvars[ BanType ] ) )
- formatex( szCommand, charsmax( szCommand ), "amx_ban" );
- else
- formatex( szCommand, charsmax( szCommand ), "amx_banip" );
- formatex( szSrvCmd, charsmax( szSrvCmd ), "%s #%i %i ^"%s^"", szCommand, get_user_userid( g_iVoteTarget ), get_pcvar_num( g_pCvars[ BanTime ] ), szBanReason );
- server_cmd( szSrvCmd );
- return ColorChat( 0, "The ^3voteban^1 has succeded, ^4%s^1 has been banned.", szName );
- }
- else
- return ColorChat( 0, "The ^3voteban^1 has failed, ^4%s^1 hasn't been banned.", szName );
- return 0;
- }
- stock bool: check_percent( total, yes, percent )
- {
- if( !yes || !total )
- return false;
- new Float: g_flPercent = float( yes ) / float( total );
- g_flPercent *= 100.0;
- if( floatround( g_flPercent ) > percent )
- return true;
- return false;
- }
- stock register_saycmd( const cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1 )
- {
- new i, j;
- new szString[ 64 ];
- new const szSayTypes[ ][ ] = { "say", "say_team" };
- new const szTypes[ ][ ] = { "/", "!", "." };
- for( i = 0 ; i < sizeof szSayTypes ; i ++ )
- {
- for( j = 0 ; j < sizeof szTypes ; j ++ )
- {
- formatex( szString, sizeof szString - 1, "%s %s%s", szSayTypes[ i ], szTypes[ j ], cmd );
- register_clcmd( szString, function, flags, info, FlagManager );
- }
- }
- }
- stock ColorChat( index, message[], any:... )
- {
- if( index && !is_user_connected( index ) )
- return 0;
- static szMessage[ 242 ], len;
- len = formatex( szMessage, charsmax( szMessage ), "^4[AMXX]^1 " );
- len += vformat( szMessage[ len ], charsmax( szMessage ) - len, message, 3 );
- static st_msgid;
- if( !st_msgid )
- st_msgid = get_user_msgid( "SayText" );
- if( index )
- {
- message_begin( MSG_ONE_UNRELIABLE, st_msgid, _, index );
- write_byte( index );
- write_string( szMessage );
- message_end( );
- }
- else
- {
- for( index = 1 ; index <= g_iMaxPlayers ; index ++ )
- {
- if( !is_user_connected( index ) )
- continue;
- message_begin( MSG_ONE_UNRELIABLE, st_msgid, _, index );
- write_byte( index );
- write_string( szMessage );
- message_end( );
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement