Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < amxmodx >
- #include < amxmisc >
- #define MAX_ACCESS 5
- #define OWNER_ACCESS ADMIN_IMMUNITY
- #define STR_LEN 64
- new const g_Access[ MAX_ACCESS ][] =
- {
- "Owner",
- "Manager",
- "Super-Admin",
- "Admin",
- "VIP"
- };
- new const g_AccessFlags[ MAX_ACCESS ][] =
- {
- "abcdefghijklmnopqrstu",
- "bcdefijmnopqrstu",
- "cdefijmnopqrst",
- "cefijmnopqrst",
- "eij"
- };
- new const g_AccessMainFlag[ MAX_ACCESS ] =
- {
- ADMIN_IMMUNITY, ADMIN_RESERVATION, ADMIN_BAN, ADMIN_KICK, ADMIN_SLAY
- };
- new const g_AccessType[ 2 ][ ] =
- {
- "Steam ID", "IP Address"
- };
- new const g_AccessTypeID[ 2 ][ ] = { "steamid", "ip" };
- new g_Variable[ 33 ], g_AccessID[ 33 ];
- new gConfigsDir[STR_LEN];
- new gAdminsFile[STR_LEN];
- public plugin_init()
- {
- register_plugin( "Access Menu", "v0.3b", "Rejack" );
- register_clcmd( "say /access", "CmdAccess" );
- register_clcmd( "say /manage", "CmdAccess" );
- get_configsdir(gConfigsDir, sizeof gConfigsDir - 1);
- formatex(gAdminsFile, sizeof gAdminsFile - 1, "%s/users.ini", gConfigsDir);
- if(!file_exists(gAdminsFile))
- set_fail_state("Non-existent file.");
- }
- public CmdAccess( client )
- {
- if ( !( get_user_flags( client ) & ADMIN_IMMUNITY ) )
- return ColorPrint( client, "You have no access to this command." );
- new Menu = menu_create( "Add Admins Menu", "SubAccess" );
- menu_additem( Menu, "Add Admins", "0" );
- menu_additem( Menu, "Remove Admins", "1" );
- return menu_display( client, Menu );
- }
- public SubAccess( client, Menu, Item )
- {
- if ( Item == MENU_EXIT ) return menu_destroy( Menu );
- if ( Item == 0 ) return CmdAdd( client );
- return CmdRemove( client );
- }
- public CmdAdd( client )
- {
- if ( !( get_user_flags( client ) & ADMIN_IMMUNITY ) )
- return ColorPrint( client, "You have no access to this command." );
- new Menu = menu_create( "Add Admins Menu", "SubAdd" );
- new szItem[ 128 ];
- formatex( szItem, charsmax( szItem ), "\yAdd a:\r %s", g_Access[ g_Variable[ client ] ] );
- menu_additem( Menu, szItem, "0" );
- formatex( szItem, charsmax( szItem ), "\yAccess Type:\r %s", g_AccessType[ g_AccessID[ client ] ] );
- menu_additem( Menu, szItem, "1" );
- menu_additem( Menu, "Choose a player!", "2" );
- return menu_display( client, Menu );
- }
- public SubAdd( client, Menu, Item )
- {
- if ( Item == MENU_EXIT ) return menu_destroy( Menu );
- switch ( Item )
- {
- case 0:
- {
- if ( g_Variable[ client ] == MAX_ACCESS - 1 )
- {
- g_Variable[ client ] = 0;
- return CmdAdd( client );
- }
- g_Variable[ client ] += 1;
- }
- case 1:
- {
- if ( g_AccessID[ client ] == 1 )
- {
- g_AccessID[ client ] = 0;
- return CmdAdd( client );
- }
- g_AccessID[ client ] += 1;
- }
- case 2: return CmdPlayers( client );
- }
- CmdAdd( client );
- return menu_destroy( Menu );
- }
- public CmdPlayers( client )
- {
- new szItem[ 128 ];
- formatex( szItem, charsmax( szItem ), "Add a\r %s\y Account!", g_Access[ g_Variable[ client ] ] );
- new Menu = menu_create( szItem, "SubPlayers" );
- new Players[ 32 ], PNum, szTempid[ 10 ];
- static szName[ 32 ];
- get_players( Players, PNum, "ch" );
- for ( new i; i<PNum; i++ )
- {
- new iPlayer = Players[ i ];
- get_user_name( iPlayer, szName, charsmax( szName ) );
- num_to_str( iPlayer, szTempid, charsmax( szTempid ) );
- if ( get_user_flags( iPlayer ) & g_AccessMainFlag[ g_Variable[ client ] ] ) continue;
- menu_additem( Menu, szName, szTempid );
- }
- return menu_display( client, Menu );
- }
- public SubPlayers( client, Menu, Item )
- {
- if ( Item == MENU_EXIT ) return menu_destroy( Menu );
- new Data[ 6 ], Name[ 64 ], Access, Callback;
- menu_item_getinfo( Menu, Item, Access, Data, charsmax( Data ), Name, charsmax( Name ), Callback );
- new iPlayer = str_to_num( Data );
- static szName[ 32 ];get_user_name( client, szName, charsmax( szName ) );
- static szName2[ 32 ];get_user_name( iPlayer, szName2, charsmax( szName2 ) );
- static szAuth[ 32 ]
- switch ( g_AccessID[ client ] )
- {
- case 0: get_user_authid( iPlayer, szAuth, charsmax( szAuth ) );
- case 1: get_user_ip( iPlayer, szAuth, charsmax( szAuth ) );
- }
- server_cmd( "amx_addadmin ^"%s^" ^"%s^" ^"^" ^"%s^"", szAuth, g_AccessFlags[ g_Variable[ client ] ], g_AccessTypeID[ g_AccessID[ client ] ] );
- server_cmd( "amx_reloadadmins" );
- ColorPrint( client, "You gave a^4 %s Access^3 to^4 %s", g_Access[ g_Variable[ client ] ], szName2 );
- ColorPrint( iPlayer, "^3Owner:^4 %s^3 gave you an^4 %s Access^3.", szName, g_Access[ g_Variable[ client ] ] );
- return menu_destroy( Menu );
- }
- public CmdRemove(id)
- {
- static iMenu;
- iMenu = menu_create("Remove Admins Menu", "SubRemove");
- static sBuffer[128], sTempItem[128];
- static sTemp[5][STR_LEN];
- static iFileP;
- iFileP = fopen(gAdminsFile, "rt");
- while(!feof(iFileP))
- {
- fgets(iFileP, sBuffer, sizeof sBuffer - 1);
- if((strlen(sBuffer) < 3) || sBuffer[0] == ';')
- continue;
- parse(sBuffer, sTemp[0], sizeof sTemp[] - 1, sTemp[1], sizeof sTemp[] - 1, sTemp[2], sizeof sTemp[] - 1, sTemp[3], sizeof sTemp[] - 1, sTemp[4] ,sizeof sTemp[] - 1 );
- for(new j = 0 ; j < sizeof sTemp ; j++)
- {
- remove_quotes(sTemp[j]);
- }
- formatex(sTempItem, sizeof sTempItem - 1, "\w %s \r|\w %s \r|\w %s \r|\w %s \r", sTemp[0], sTemp[1], sTemp[2], sTemp[3], sTemp[4]);
- menu_additem(iMenu, sTempItem, "", 0, -1);
- }
- fclose(iFileP);
- menu_addblank(iMenu, 0);
- menu_display(id, iMenu, 0);
- return PLUGIN_HANDLED;
- }
- public SubRemove( client, Menu, Item )
- {
- if ( Item == MENU_EXIT )
- {
- CmdAccess( client );
- return menu_destroy( Menu );
- }
- static iAccess, iCallback;
- static sBuffer[128], sTemp[STR_LEN];
- menu_item_getinfo( Menu, Item, iAccess, "", 0, sBuffer, sizeof sBuffer - 1, iCallback );
- strtok(sBuffer, sTemp, sizeof sTemp - 1, sBuffer, sizeof sBuffer - 1, '|');
- replace(sTemp, sizeof sTemp - 1, "\w", "");
- replace(sTemp, sizeof sTemp - 1, "\r", "");
- trim(sTemp);
- static iFileP;
- iFileP = fopen( gAdminsFile, "rt" );
- static sTempAccount[STR_LEN];
- new i;
- while(!feof(iFileP))
- {
- fgets(iFileP, sBuffer, sizeof sBuffer - 1);
- i++;
- if((strlen(sBuffer) < 3) || sBuffer[0] == ';')
- continue;
- parse(sBuffer, sTempAccount, sizeof sTempAccount - 1);
- remove_quotes(sTempAccount);
- if(equali(sTempAccount, sTemp))
- {
- format(sBuffer, sizeof sBuffer - 1, ";%s", sBuffer);
- write_file(gAdminsFile, sBuffer, i - 1);
- break;
- }
- }
- fclose( iFileP );
- ColorPrint( client, "You removed^4 %s^1 from the admins list.", sTemp );
- server_cmd( "amx_reloadadmins" );
- return 1;
- }
- stock ColorPrint( const client, const string[], any:... )
- {
- new msg[ 191 ], players[ 32 ], count = 1;
- static len; len = formatex( msg, charsmax( msg ), "^3[^4 HitAndRun ^3] " );
- vformat( msg[ len ], charsmax( msg ) - len, string, 3 );
- if( client ) players[ 0 ] = client;
- else get_players( players,count,"ch" );
- for ( new i = 0; i < count; i++ )
- {
- if( is_user_connected( players[ i ] ) )
- {
- message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] );
- write_byte( players[ i ] );
- write_string( msg );
- message_end( );
- }
- }
- return PLUGIN_HANDLED;
- }
Advertisement
Add Comment
Please, Sign In to add comment