Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include < amxmodx >
  2. #include < fakemeta >
  3.  
  4. #define PLUGIN  "Unlimited Team Changes"
  5. #define VERSION "1.3"
  6. #define AUTHOR  "HamletEagle"
  7.  
  8. #define BITS 1<<8
  9. #define ADMIN_ACCES ADMIN_KICK
  10.  
  11. const m_bHasChangeTeamThisRound = 125
  12. const XO_PLAYER = 5
  13.  
  14. enum _: eCvarsData
  15. {
  16.     cvar_OnlyAdmins,
  17.     cvar_Enable
  18. }
  19.  
  20. new g_iCvars[ eCvarsData ]
  21. new g_iCachedCvars[ eCvarsData ]
  22.  
  23. new _pfnClientCommand
  24.  
  25. public plugin_init( )
  26. {
  27.     register_plugin
  28.     (
  29.         .plugin_name  = PLUGIN,
  30.         .version      = VERSION,
  31.         .author       = AUTHOR
  32.     )
  33.    
  34.     g_iCvars[ cvar_OnlyAdmins ] = register_cvar( "only_admins_can_use", "0" )
  35.     /*
  36.     0 - all players
  37.     1 - only admins with specified flag
  38.     */
  39.  
  40.     g_iCvars[ cvar_Enable ] = register_cvar( "plugin_enabled", "1" )
  41.     /*
  42.     0 - plugin disabled
  43.     1 - plugin enabled
  44.     */
  45.    
  46.     _pfnClientCommand = register_forward( FM_ClientCommand, "pfnClientCommand", false )
  47.     register_event( "HLTV", "Event_NewRound", "a", "1=0", "2=0" )  
  48.    
  49.     register_clcmd( "chooseteam", "ClientCommand_ChTeam" )
  50.     register_clcmd( "jointeam"  , "ClientCommand_ChTeam" )
  51. }
  52.  
  53. public plugin_cfg( )
  54. {
  55.     UTIL_CacheCvars( )
  56. }
  57.  
  58. public pfnClientCommand( id )
  59. {
  60.     //We need to catch the exact moment, so the cached cvar is not reliable here
  61.     if( get_pcvar_num( g_iCvars[ cvar_Enable ] ) == 0 )
  62.     {
  63.         log_amx( "Plugin paused by cvar" )
  64.         unregister_forward( FM_ClientCommand, _pfnClientCommand, false )
  65.         pause( "a" )
  66.     }
  67. }
  68.  
  69. public Event_NewRound( )
  70. {
  71.     UTIL_CacheCvars( ) 
  72. }
  73.  
  74. public ClientCommand_ChTeam( id )
  75. {
  76.     switch( g_iCachedCvars[ cvar_OnlyAdmins ] )
  77.     {
  78.         case 0 :
  79.         {
  80.             set_pdata_int( id, m_bHasChangeTeamThisRound , get_pdata_int( id, m_bHasChangeTeamThisRound, XO_PLAYER ) &  ~BITS, XO_PLAYER ) 
  81.         }
  82.        
  83.         case 1 :
  84.         {
  85.             if( get_user_flags( id ) & ADMIN_ACCES )
  86.             {
  87.                 set_pdata_int( id, m_bHasChangeTeamThisRound , get_pdata_int( id, m_bHasChangeTeamThisRound, XO_PLAYER ) &  ~BITS, XO_PLAYER ) 
  88.             }
  89.         }
  90.         default:
  91.         {
  92.             return 0
  93.         }
  94.     }
  95.     return 0
  96. }
  97.  
  98. UTIL_CacheCvars( )
  99. {
  100.     for( new i; i < sizeof g_iCvars; i++ )
  101.     {
  102.         g_iCachedCvars[ i ] = get_pcvar_num( g_iCvars[ i ] )
  103.     }  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement