#gamerules_example.py
from cvars import ConVar
from filters.entities import EntityIter
def get_gamerules_entity():
# Go through all entities
for entity in EntityIter():
# Is this the GameRulesProxy entity?
# Each game has a different name for this entity.
# HL2DM - hl2dm_gamerules, CSGO - cs_gamerules, etc.
if 'gamerules' in entity.classname:
return entity
def get_game_state():
gamerules = get_gamerules_entity()
# Are we in a warmup?
warmup = gamerules.get_property_bool('cs_gamerules_data.m_bWarmupPeriod')
# Are we waiting for the round to start?
freezetime = gamerules.get_property_bool('cs_gamerules_data.m_bFreezePeriod')
# Total rounds played
rounds_played = gamerules.get_property_short('cs_gamerules_data.m_totalRoundsPlayed')
# Checking if we're in the second half of the game
maxrounds = ConVar('mp_maxrounds').get_int()
if rounds_played >= int(maxrounds / 2):
print('Playing in the second half..')