"""
cahnges the respawn time based on number of players
thepolm3
"""

def apply_script(protocol, connection, config):
    
    class InteliSpawnConnection(connection):

        #ok so i condenced this. So sue me
        def get_respawn_time(self):
            respawn_time=connection.get_respawn_time(self)
            blue,green=self.protocol.blue_team,self.protocol.green_team
            blues=greens=0.0
            for player in self.protocol.players.values():
                if player.team==blue: blues+=1.0
                elif player.team==green: greens+=1.0
            if blues!=0 and greens>blues and self.team==green: return int(greens/blues)*respawn_time
            if greens!=0 and blues>greens and self.team==blue: return int(greens/blues)*respawn_time
            return respawn_time
        
    return protocol, InteliSpawnConnection
