Pushok

DeathRun swap function (not tested)

May 28th, 2011
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | None | 0 0
  1. void CDeathRun::FireGameEvent( IGameEvent *event )
  2. {
  3.     srand(time(0));
  4.     rand();
  5.  
  6.     if(!strcmp(event->GetName(), "round_end"))
  7.     {
  8.         try
  9.         {
  10.  
  11.             if(GetClientCount( Player_Terrorist, true ) < 1 || GetClientCount( Player_CounterTerrorist, true ) < 1)
  12.             {
  13.                 throw std::exception("There is no terrorists/counter-terrorists for swapping.\n");
  14.             }
  15.  
  16.             if( FindEntityByClassName( "info_player_terrorist" ) < 1 )
  17.             {
  18.                 throw std::exception( "There is a bit of terrorists spawn point.\n" );
  19.             }
  20.  
  21.             PlayerStack g_OldTerroristsStack = GetClientStack( Player_Terrorist, false, false );
  22.             PlayerStack g_NewTerroristsStack;
  23.  
  24.             int iTerroristsAmount = ((g_DeathRunTerrorists->GetInt() < GetClientCount( Player_InvalidTeam, true ) \
  25.                 && GetClientCount( Player_InvalidTeam, true ) >= g_DeathRunClients->GetInt() \
  26.                 && FindEntityByClassName( "info_player_terrorist" ) > 1) ? g_DeathRunTerrorists->GetInt() : 1);
  27.  
  28.             m_DeathRun_ServerEngine->ServerCommand("say Team swapping...\n");
  29.  
  30.             for(int i = 0; i < iTerroristsAmount; i++)
  31.             {
  32.                 edict_t *client = nullptr;
  33.                 int iterationCount = 0;
  34.  
  35.                 do
  36.                 {
  37.                     client = GetRandomPlayer( Player_CounterTerrorist, false );
  38.  
  39.                     META_CONPRINTF( (std::string("Testing: ") + this->m_DeathRun_PlayerInfo->GetPlayerInfo(client)->GetName() + "\n").c_str() );
  40.  
  41.                     if(client == nullptr)
  42.                     {
  43.                         throw std::exception("There is no clients to swap...\n");
  44.                     }
  45.  
  46.                     if(!(GET_PLAYER_CLASS(client) - 4))
  47.                     {
  48.                         client = nullptr;
  49.                     }
  50.  
  51.                     for(PlayerStack::iterator c = g_NewTerroristsStack.begin(); c < g_NewTerroristsStack.end(); c++)
  52.                     {
  53.                         if(*c == client)
  54.                         {
  55.                             client = nullptr;
  56.                         }
  57.                     }
  58.                    
  59.                     if(iterationCount++ > 256)
  60.                     {
  61.                         throw std::exception("Looping...\n");
  62.                     }
  63.  
  64.                 } while (!client);
  65.  
  66.                 g_NewTerroristsStack.push_back(client);
  67.             }
  68.  
  69.             if(!g_NewTerroristsStack.empty())
  70.             {
  71.                 for(PlayerStack::iterator i = g_NewTerroristsStack.begin(); i < g_NewTerroristsStack.end(); i++)
  72.                 {
  73.                     //SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_Terrorist);
  74.                     SetEntityProperty(m_DeathRun_DLL, *i, "CCSPlayer", "m_iClass", GET_PLAYER_CLASS(*i) - 4);
  75.                     SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_Terrorist);
  76.                 }
  77.             }
  78.  
  79.             if(!g_OldTerroristsStack.empty())
  80.             {
  81.                 for(PlayerStack::iterator i = g_OldTerroristsStack.begin(); i < g_OldTerroristsStack.end(); i++)
  82.                 {
  83.                     //SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_CounterTerrorist);
  84.                     SetEntityProperty(m_DeathRun_DLL, *i, "CCSPlayer", "m_iClass", GET_PLAYER_CLASS(*i) + 4);
  85.                     SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_CounterTerrorist);
  86.                 }
  87.             }
  88.  
  89.             PlayerStack stck = GetClientStack( Player_InvalidTeam, false, true );
  90.            
  91.             for(PlayerStack::iterator i = stck.begin(); i < stck.end(); i++)
  92.             {
  93.                 META_CONPRINTF("This is player class - %d, Team - %d\n", GET_PLAYER_CLASS(*i), this->m_DeathRun_PlayerInfo->GetPlayerInfo(*i)->GetTeamIndex());
  94.             }
  95.         }
  96.         catch(std::exception exept)
  97.         {
  98.             META_CONPRINT( exept.what() );
  99.             return;
  100.         }
  101.  
  102.     }
  103.  
  104.     return;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment