Pushok

dropc4

Jun 2nd, 2012
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.92 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5. #include <cstrike>
  6.  
  7. #define PLUGIN_VERSION "1.0"
  8. #define MSG "%t"
  9.  
  10. new vote_counter;
  11. new bool:voted_clients[MAXPLAYERS];
  12.  
  13. new Handle:g_hPlugin =          INVALID_HANDLE;
  14. new Handle:g_hPlayersToVote =   INVALID_HANDLE;
  15. new Handle:g_hAllowToClients =  INVALID_HANDLE;
  16.  
  17. public Plugin:myinfo =
  18. {
  19.     name = "С4 Drop",
  20.     author = "Push",
  21.     description = "Teleport C4 to Terrorists' Spawn Point",
  22.     version = PLUGIN_VERSION,
  23.     url = "http://css-quad.ru"
  24. };
  25.  
  26. public OnPluginStart()
  27. {
  28.     RegAdminCmd( "sm_drc4", CommandHandler, ADMFLAG_BAN);
  29.     RegConsoleCmd( "sm_votec4", ClientsCommandHandler );
  30.    
  31.     g_hPlugin =         CreateConVar( "dropc4_enabled", "1", "Enable plugin?" );
  32.     g_hPlayersToVote =  CreateConVar( "dropc4_pct_to_vote", "40", "How many clients' votes for doing something?" );
  33.     g_hAllowToClients = CreateConVar( "dropc4_allow_to_clients", "1", "Allow clients to use votec4 command?" );
  34.    
  35.     LoadTranslations( "return_c4.phrases" );
  36. }
  37.  
  38. public OnMapStart()
  39. {
  40.     vote_counter = 0;
  41.    
  42.     for( new i = 0; i < sizeof( voted_clients ); i++ ) voted_clients[i] = false;
  43. }
  44.  
  45.  
  46. public Action:CommandHandler( client, args )
  47. {
  48.     if( GetConVarBool( g_hPlugin ) )
  49.     {
  50.         if ( args != 0 )
  51.         {
  52.             return Plugin_Handled;
  53.         }
  54.        
  55.         DropC4();
  56.        
  57.         return Plugin_Handled;
  58.     }
  59.    
  60.     return Plugin_Continue;
  61. }
  62.  
  63. public OnClientDisconnect( client )
  64. {
  65.     if( GetConVarBool( g_hPlugin ) )
  66.     {
  67.         if( voted_clients[ client ] )
  68.         {
  69.             voted_clients[ client ] = false;
  70.  
  71.             counter--;
  72.         }
  73.     }
  74. }
  75.  
  76. public Action:ClientsCommandHandler( client, args )
  77. {
  78.     if( GetConVarBool( g_hPlugin ) && GetConVarBool( g_hAllowToClients ) )
  79.     {
  80.         if( IsClientInGame( client ) && !voted_clients[ client ] )
  81.         {
  82.             voted_clients[ client ] = true;
  83.             counter ++;
  84.            
  85.             PrintToChat( client, MSG, "Player voted", counter,  );
  86.         }
  87.         else
  88.         {
  89.             PrintToChat( client, MSG, "Already voted" );
  90.         }
  91.        
  92.         if( float(counter) >= float(MaxClients) / 100 * GetConVarInt(g_hPlayersToVote) )
  93.         {
  94.             PrintToChatAll( MSG, "Taken away" );
  95.            
  96.             counter = 0;
  97.             DropC4();
  98.         }
  99.        
  100.         return Plugin_Handled;
  101.     }
  102.    
  103.     return Plugin_Continue;
  104. }
  105.  
  106. stock void:DropC4()
  107. {
  108.     for( new i = 1; i < MaxClients; i++ )
  109.     {
  110.         if( IsClientInGame(i) && GetPlayerWeaponSlot(i, 4) != -1 && GetClientTeam(i) == CS_TEAM_T )
  111.         {
  112.             CreateTimer( 0.050, TimerProc, GetPlayerWeaponSlot(i, 4) );
  113.             CS_DropWeapon( i, 4, false, true );
  114.         }
  115.     }
  116. }
  117.  
  118. public Action:TimerProc( Handle:hTimer, any:weapon )
  119. {
  120.     new spawn_point = -1, counter;
  121.     new iEntityArray[ 64 ];
  122.    
  123.     while ((spawn_point = FindEntityByClassname(spawn_point, "info_player_terrorist")) != INVALID_ENT_REFERENCE)
  124.     {
  125.         iEntityArray[counter++] = spawn_point;
  126.     }
  127.    
  128.     new Float:fSpawnPos[3];
  129.     GetEntPropVector(iEntityArray[GetRandomInt(0, counter - 1)]), Prop_Send, "m_vecOrigin", fSpawnPos);
  130.    
  131.     TeleportEntity( weapon, fSpawnPos, NULL_VECTOR, NULL_VECTOR );
  132.    
  133.     return Plugin_Continue;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment