Page 1 of 1

how to get the current game state/match state

Posted: Wed May 02, 2018 11:09 am
by varunkishore
hi ...now i'm creating one command like '' game_state"
it shows current state of the game like if a player is in warm_up means it show player is in warm_up,if player is playing in game means it shows player playing the game ,if player is playing second half means it shows second half likethat ...
is their any way to get the current state of the match ??

Re: how to get the current game state/match state

Posted: Wed May 02, 2018 7:28 pm
by VinciT
You should be able to get all of that information from the GameRulesProxy entity.

This code should work, but for some reason I'm not getting the expected values.

Maybe someone else knows what the issue is?

In any case, here are all the properties for the entity as well:

Re: how to get the current game state/match state

Posted: Wed May 02, 2018 10:49 pm
by satoon101
I have not tested any of this, but I did see m_gamePhase and thought it might be helpful. A quick google search led me to this:
https://github.com/splewis/get5/blob/ma ... sp#L19-L25

I did print out that value locally with no players (including bots) on the server, and it returned 0:

Syntax: Select all

from filters.entities import EntityIter
def get_gamerules_entity():
for entity in EntityIter('gamerules', exact_match=False):
return entity
return None
entity = get_gamerules_entity()
print(entity.get_property_uchar('cs_gamerules_data.m_gamePhase'))


So, I imagine 0 is for match not even started, and 1 is likely for Warmup. But again, I have not tested that, so those are just assumptions.

Re: how to get the current game state/match state

Posted: Wed May 02, 2018 11:58 pm
by VinciT
Just tried m_gamePhase with me + bots for a full match (I set the mp_roundtime/mp_roundtime_defuse to 0.1 and turned off mp_freezetime to speed things up) and I kept getting 0.
Here's the SourceMod implementation/wrapper for GameRulesProxy: https://github.com/alliedmodders/source ... atives.cpp - maybe this can help?