Advertisement
iXdoctor

CT Rounds Left && GetMenu

May 28th, 2014
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.98 KB | None | 0 0
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include < amxmodx >
  4. #include < amxmisc >
  5. #include < cstrike >
  6. #include < hamsandwich >
  7.  
  8. #define MAX_ROUNDS  15
  9.  
  10. new iRounds[ 33 ], szText[ 128 ];
  11.  
  12. new const GetCommands[ ] [ ] = { "say /getmenu", "say_team /getmenu", "say /get", "say_team /get" }
  13.  
  14. public plugin_init()
  15. {
  16.     register_plugin( "CT Rounds", "1.0", "Xdoctor" );
  17.    
  18.     register_clcmd( "say", "CmdHandleSay" );
  19.    
  20.     register_clcmd( "say_team", "CmdHandleSay" );
  21.    
  22.     RegisterHam( Ham_Spawn, "player", "fwClientSpawn" );
  23.    
  24.     for( new i = 0; i < sizeof( GetCommands ); i++ )
  25.         register_clcmd( GetCommands[ i ], "GetMenu" );
  26.        
  27. }
  28.  
  29. public client_disconnect( client )
  30.     iRounds[ client ] = 0;
  31.    
  32. public fwClientSpawn( client )
  33. {
  34.     if( !is_user_alive( client ) )
  35.         return 1;
  36.        
  37.     iRounds[ client ] += 1;
  38.    
  39.     if( cs_get_user_team( client ) != CS_TEAM_T && GetUserRounds( client ) <= MAX_ROUNDS )
  40.         return ColorChat( 0, "You are on your ^4%i^1/^4%i^1 Round ^1( ^4%s Rounds left^1 )", GetUserRounds( client ), MAX_ROUNDS, GetUserLeftRounds( client ) );
  41.        
  42.     if( GetUserRounds( client ) >= MAX_ROUNDS && cs_get_user_team( client ) == CS_TEAM_CT )
  43.     {
  44.         cs_set_user_team( client, CS_TEAM_T )
  45.        
  46.         ExecuteHamB( Ham_CS_RoundRespawn, client );
  47.        
  48.         iRounds[ client ] = 0;
  49.        
  50.         ColorChat( client, "Your time has a CT is up!" )
  51.     }
  52.    
  53.     return 1;
  54. }
  55.  
  56. public GetMenu( client )
  57. {
  58.     if( cs_get_user_team( client ) != CS_TEAM_CT )
  59.         return ColorChat( client, "Only guards can use this command" );
  60.        
  61.     formatex( szText, charsmax( szText ), "\d[ \yAMXX\d ]\y GetMenu\w:" )
  62.    
  63.     new Menu = menu_create( szText, "CmdGetMenuHandler" );
  64.    
  65.     new players[ 32 ], pnum;
  66.    
  67.     get_players( players, pnum );
  68.    
  69.     for( new i = 0; i < pnum; i++ )
  70.     {
  71.         if( !is_user_connected( i ) || cs_get_user_team( i ) != CS_TEAM_T )
  72.             continue;
  73.        
  74.         formatex( szText, charsmax( szText ), "\rPlayer\w:\y %s\d.", GetUserName( i ) );
  75.        
  76.         menu_additem( Menu, szText );
  77.            
  78.     }
  79.    
  80.     menu_display( client, Menu, 0 );
  81.    
  82.     return 1;
  83. }
  84.  
  85. public CmdGetMenuHandler( client, Menu, Item )
  86. {
  87.     if( Item >= MENU_EXIT )
  88.     {
  89.         menu_destroy( Menu );
  90.        
  91.         return 1;
  92.     }
  93.    
  94.     new szName [ 33 ], iAccess, Data[ 8 ], iCallback;
  95.    
  96.     menu_item_getinfo( Menu, Item, iAccess, Data, 6, szName, charsmax( szName ), iCallback );
  97.    
  98.     new cPlayer = str_to_num( Data );
  99.    
  100.     SendGetRequest( client, cPlayer );
  101.    
  102.     return 1;
  103. }
  104.  
  105.  
  106. public SendGetRequest( cPlayer, client )
  107. {
  108.     formatex( szText, charsmax( szText ), "\yWould you like to switch teams with %s \w?", GetUserName( client ) );
  109.    
  110.     new Menu = menu_create( szText, "CmdGetAnswer" );
  111.    
  112.     menu_additem( Menu, "\wYes I Want", "0" );
  113.    
  114.     menu_additem( Menu, "\wNah Im good", "1" );
  115.    
  116.     menu_display( client, Menu, 0 );
  117.    
  118.     return 1;
  119. }
  120.    
  121. public CmdGetAnswer( cPlayer, Menu, Item )
  122. {
  123.     if( Item >= MENU_EXIT )
  124.     {
  125.         menu_destroy( Menu );
  126.        
  127.         return 1;
  128.     }
  129.    
  130.     new Data[ 6 ], szName2[ 32 ], szKey[ 10 ], iClient[ 10 ], Access, iCallback;
  131.                        
  132.         menu_item_getinfo( Menu, Item, Access, Data, charsmax( Data ), szName2, charsmax( szName2 ), iCallback );
  133.        
  134.         parse( Data, szKey, charsmax( szKey ), iClient, charsmax( iClient ) );
  135.    
  136.     new iKey = str_to_num( szKey );
  137.    
  138.     new client = str_to_num( iClient );
  139.    
  140.     switch( iKey )
  141.     {
  142.         case 0:
  143.         {
  144.             cs_set_user_team( cPlayer, CS_TEAM_CT );
  145.            
  146.             cs_set_user_team( client, CS_TEAM_T );
  147.            
  148.             ExecuteHamB( Ham_CS_RoundRespawn, cPlayer );
  149.            
  150.             ExecuteHamB( Ham_CS_RoundRespawn, cPlayer );
  151.            
  152.             iRounds[ cPlayer ] = GetUserRounds( client );
  153.            
  154.             iRounds[ client ] = 0;
  155.            
  156.             ColorChat( 0, "The Guard: ^4%s^1 switched teams with the Prisoner:^4 %s", GetUserName( cPlayer ), GetUserName( client ) );
  157.            
  158.             ColorChat( cPlayer, "The Player^4 %s^1. rounds has been Transfor for You", GetUserName( client ) );
  159.         }
  160.        
  161.         case 1: return ColorChat( client, "The Player:^4 %s^1 denied your Request to switch Teams!!", GetUserName( cPlayer ) );
  162.  
  163.     }
  164.    
  165.     return 1;
  166. }
  167.            
  168.            
  169. public CmdHandleSay( client )
  170. {
  171.     new szMsg[ 128 ], iPlayer[ 33 ], szPlayer, Amount;
  172.    
  173.     read_argv( 1, szMsg, charsmax( szMsg ) );
  174.    
  175.     if( equali( szMsg, "/rounds" ) )
  176.     {
  177.         for( new i = 1; i < get_maxplayers(); i++ )
  178.         {
  179.             if( !is_user_connected( i ) )
  180.                 continue;
  181.                
  182.             szPlayer = cmd_target( client, iPlayer, CMDTARGET_NO_BOTS )
  183.            
  184.         }
  185.        
  186.         if( cs_get_user_team( szPlayer ) != CS_TEAM_CT )
  187.             return ColorChat( client, "This player isn't a guard" );
  188.            
  189.         if( !szPlayer )
  190.             return ColorChat( client, "Target not found!" )
  191.        
  192.         if( szPlayer )
  193.             return ColorChat( client, "The Guard :^4 %s^1 In is ^4%i^1/^4%i^1 Round ( ^4He has %i Rounds left^1 )", GetUserRounds( szPlayer ), MAX_ROUNDS, GetUserLeftRounds( szPlayer) );
  194.            
  195.         }
  196.        
  197.     Amount = str_to_num( szMsg );
  198.    
  199.     if( equali( szMsg, "/addrounds" ) )
  200.     {
  201.         if( !is_user_admin( client ) )
  202.             return ColorChat( client, "This command can be used only by an admin!" );
  203.            
  204.         if( !szPlayer )
  205.             return ColorChat( client, "Target not found!" )
  206.        
  207.         if( GetUserRounds( szPlayer )  > MAX_ROUNDS - 1 )
  208.             return ColorChat( client, "Play must have less then One Round left to use this command on am." )
  209.            
  210.         iRounds[ szPlayer ] += Amount;
  211.     }
  212.    
  213.        
  214.     return 1;
  215. }
  216.  
  217. stock GetUserLeftRounds( const Index )
  218.     return MAX_ROUNDS - iRounds[ Index ];
  219.    
  220. stock GetUserRounds( const Index )
  221.     return iRounds[ Index ];
  222.  
  223. stock GetUserName( const Index )
  224. {
  225.     static szName[ 32 ];
  226.    
  227.     get_user_name( Index, szName, charsmax( szName ) );
  228.    
  229.     return szName;
  230. }
  231.  
  232. stock ColorChat( const id, const string[], any:... )
  233. {
  234.     new msg[191], players[32], count = 1;
  235.    
  236.     static len; len = formatex(msg, charsmax(msg), "^1[ ^4AMXX^1 ] " );
  237.     vformat(msg[len], charsmax(msg) - len, string, 3);
  238.    
  239.     if(id)  players[0] = id;
  240.     else    get_players(players,count,"ch");
  241.    
  242.     for (new i = 0; i < count; i++)
  243.     {
  244.         if(is_user_connected(players[i]))
  245.         {
  246.             message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, players[i]);
  247.             write_byte(players[i]);
  248.             write_string(msg);
  249.             message_end();
  250.         }
  251.     }
  252.    
  253.     return 1;
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement