Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #gamerules_example.py
  2. from cvars import ConVar
  3. from filters.entities import EntityIter
  4.  
  5.  
  6. def get_gamerules_entity():
  7.     # Go through all entities
  8.     for entity in EntityIter():
  9.         # Is this the GameRulesProxy entity?
  10.         # Each game has a different name for this entity.
  11.         # HL2DM - hl2dm_gamerules, CSGO - cs_gamerules, etc.
  12.         if 'gamerules' in entity.classname:
  13.             return entity
  14.  
  15.  
  16. def get_game_state():
  17.     gamerules = get_gamerules_entity()
  18.  
  19.     # Are we in a warmup?
  20.     warmup = gamerules.get_property_bool('cs_gamerules_data.m_bWarmupPeriod')
  21.     # Are we waiting for the round to start?
  22.     freezetime = gamerules.get_property_bool('cs_gamerules_data.m_bFreezePeriod')
  23.    
  24.     # Total rounds played
  25.     rounds_played = gamerules.get_property_short('cs_gamerules_data.m_totalRoundsPlayed')
  26.  
  27.     # Checking if we're in the second half of the game
  28.     maxrounds = ConVar('mp_maxrounds').get_int()
  29.     if rounds_played >= int(maxrounds / 2):
  30.         print('Playing in the second half..')