Page 1 of 1
[CSGO] Get current map?
Posted: Fri Sep 16, 2016 6:17 am
by xozzo
Besides events/listeners like OnLevelInit, I was wondering if there was any other way to get the current map the server is on? I have a SayCommand that changes the map so I would like to access the current map on-demand to make sure the user isn't trying to switch to the map we're already on.
Re: [CSGO] Get current map?
Posted: Fri Sep 16, 2016 7:01 am
by Predz
engines.server.server.map_name I believe :)
Syntax: Select all
from engines.server import server
map_name = server.map_name
However I think you have to create your own Server instance. So instead import Server and create an instance first.
Syntax: Select all
from engines.server import Server
server = Server()
map_name = server.map_name
Either this or update a global variable :P
Syntax: Select all
from listeners import OnLevelInit
g_mapname = None
@OnLevelInit
def _levelinit(map):
global g_mapname
g_mapname = map
Re: [CSGO] Get current map?
Posted: Fri Sep 16, 2016 8:27 am
by L'In20Cible
Syntax: Select all
from engines.server import global_vars
print(global_vars.map_name)
Re: [CSGO] Get current map?
Posted: Fri Sep 16, 2016 9:07 am
by Ayuto
Predz wrote:However I think you have to create your own Server instance. So instead import Server and create an instance first.
Syntax: Select all
from engines.server import Server
server = Server()
map_name = server.map_name
No, you first approach was correct.
http://wiki.sourcepython.com/developing ... r.__init__But I would stick with L'In20Cible's solution, because the Server interface requires signatures/symbols (which could change and break) in some games while the global_vars instance doesn't.
Re: [CSGO] Get current map?
Posted: Fri Sep 16, 2016 2:07 pm
by Predz
Thanks Ayuto :)
Yeh my reasoning behind this was due to this
.py file not importing "server" anywhere and only being defined as "None".
Re: [CSGO] Get current map?
Posted: Fri Sep 16, 2016 2:10 pm
by satoon101
Re: [CSGO] Get current map?
Posted: Fri Sep 16, 2016 2:33 pm
by xozzo
Thank you all!
Re: [CSGO] Get current map?
Posted: Tue Sep 20, 2016 1:46 pm
by decompile
Im just wondering why:
Syntax: Select all
def getCurrentMap():
mapName = global_vars.map_name
return mapName
never works. It always returns <function getCurrentMap at 0x2549E8A0>
Re: [CSGO] Get current map?
Posted: Tue Sep 20, 2016 2:01 pm
by iPlayer
How do you call it?
Re: [CSGO] Get current map?
Posted: Tue Sep 20, 2016 2:07 pm
by satoon101
Looks to me like it's not being 'called' at all. Seems to me to be something like:
Syntax: Select all
def some_function():
current_map = getCurrentMap
print(current_map)
when it should be something more like:
Syntax: Select all
def some_function():
current_map = getCurrentMap()
print(current_map)
Re: [CSGO] Get current map?
Posted: Tue Sep 20, 2016 2:16 pm
by decompile
Im dumb.. Sorry.
I executed it with () but forgot to save the file, so it was as satoon said, without the ()'.
Damn notepad got me again