[CSGO] Get current map?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
xozzo
Junior Member
Posts: 2
Joined: Fri Sep 16, 2016 6:04 am

[CSGO] Get current map?

Postby xozzo » Fri Sep 16, 2016 6:17 am

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.
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Re: [CSGO] Get current map?

Postby Predz » Fri Sep 16, 2016 7:01 am

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
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO] Get current map?

Postby L'In20Cible » Fri Sep 16, 2016 8:27 am

Syntax: Select all

from engines.server import global_vars

print(global_vars.map_name)
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Get current map?

Postby Ayuto » Fri Sep 16, 2016 9:07 am

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.
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Re: [CSGO] Get current map?

Postby Predz » Fri Sep 16, 2016 2:07 pm

Thanks Ayuto :)

Yeh my reasoning behind this was due to this .py file not importing "server" anywhere and only being defined as "None".
User avatar
xozzo
Junior Member
Posts: 2
Joined: Fri Sep 16, 2016 6:04 am

Re: [CSGO] Get current map?

Postby xozzo » Fri Sep 16, 2016 2:33 pm

Thank you all!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: [CSGO] Get current map?

Postby decompile » Tue Sep 20, 2016 1:46 pm

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>
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: [CSGO] Get current map?

Postby iPlayer » Tue Sep 20, 2016 2:01 pm

How do you call it?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CSGO] Get current map?

Postby satoon101 » Tue Sep 20, 2016 2:07 pm

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)
Image
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: [CSGO] Get current map?

Postby decompile » Tue Sep 20, 2016 2:16 pm

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 21 guests