Pushok icon

DeathRun swap function (not tested)

Pushok | PRO | 05/28/11 01:15:07 PM UTC | 0 ⭐ | 515 👁️ | Never ⏰ | []
C++ |

3.16 KB

|

None

|

0 👍

/

0 👎

void CDeathRun::FireGameEvent( IGameEvent *event )
{
    srand(time(0));
    rand();
 
    if(!strcmp(event->GetName(), "round_end"))
    {
        try
        {
 
            if(GetClientCount( Player_Terrorist, true ) < 1 || GetClientCount( Player_CounterTerrorist, true ) < 1)
            {
                throw std::exception("There is no terrorists/counter-terrorists for swapping.\n");
            }
 
            if( FindEntityByClassName( "info_player_terrorist" ) < 1 )
            {
                throw std::exception( "There is a bit of terrorists spawn point.\n" );
            }
 
            PlayerStack g_OldTerroristsStack = GetClientStack( Player_Terrorist, false, false );
            PlayerStack g_NewTerroristsStack;
 
            int iTerroristsAmount = ((g_DeathRunTerrorists->GetInt() < GetClientCount( Player_InvalidTeam, true ) \
                && GetClientCount( Player_InvalidTeam, true ) >= g_DeathRunClients->GetInt() \
                && FindEntityByClassName( "info_player_terrorist" ) > 1) ? g_DeathRunTerrorists->GetInt() : 1);
 
            m_DeathRun_ServerEngine->ServerCommand("say Team swapping...\n");
 
            for(int i = 0; i < iTerroristsAmount; i++)
            {
                edict_t *client = nullptr;
                int iterationCount = 0;
 
                do 
                {
                    client = GetRandomPlayer( Player_CounterTerrorist, false );
 
                    META_CONPRINTF( (std::string("Testing: ") + this->m_DeathRun_PlayerInfo->GetPlayerInfo(client)->GetName() + "\n").c_str() );
 
                    if(client == nullptr)
                    {
                        throw std::exception("There is no clients to swap...\n");
                    }
 
                    if(!(GET_PLAYER_CLASS(client) - 4))
                    {
                        client = nullptr;
                    }
 
                    for(PlayerStack::iterator c = g_NewTerroristsStack.begin(); c < g_NewTerroristsStack.end(); c++)
                    {
                        if(*c == client)
                        {
                            client = nullptr;
                        }
                    }
                    
                    if(iterationCount++ > 256)
                    {
                        throw std::exception("Looping...\n");
                    }
 
                } while (!client);
 
                g_NewTerroristsStack.push_back(client);
            }
 
            if(!g_NewTerroristsStack.empty())
            {
                for(PlayerStack::iterator i = g_NewTerroristsStack.begin(); i < g_NewTerroristsStack.end(); i++)
                {
                    //SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_Terrorist);
                    SetEntityProperty(m_DeathRun_DLL, *i, "CCSPlayer", "m_iClass", GET_PLAYER_CLASS(*i) - 4);
                    SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_Terrorist);
                }
            }
 
            if(!g_OldTerroristsStack.empty())
            {
                for(PlayerStack::iterator i = g_OldTerroristsStack.begin(); i < g_OldTerroristsStack.end(); i++)
                {
                    //SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_CounterTerrorist);
                    SetEntityProperty(m_DeathRun_DLL, *i, "CCSPlayer", "m_iClass", GET_PLAYER_CLASS(*i) + 4);
                    SetEntityProperty(m_DeathRun_DLL, *i, "CBaseEntity", "m_iTeamNum", Player_CounterTerrorist);
                }
            }
 
            PlayerStack stck = GetClientStack( Player_InvalidTeam, false, true );
            
            for(PlayerStack::iterator i = stck.begin(); i < stck.end(); i++)
            {
                META_CONPRINTF("This is player class - %d, Team - %d\n", GET_PLAYER_CLASS(*i), this->m_DeathRun_PlayerInfo->GetPlayerInfo(*i)->GetTeamIndex());
            }
        }
        catch(std::exception exept)
        {
            META_CONPRINT( exept.what() );
            return;
        }
 
    }
 
    return;
}

Comments