[Cs:s] Automatic mapcycle.txt creator
-
- Senior Member
- Posts: 315
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
[Cs:s] Automatic mapcycle.txt creator
Hi, can some one make a plugin that automatically create mapcycle.txt from maps that server have.
Re: [Cs:s] Automatic mapcycle.txt creator
Hey, you can try this:
Use the command "mapcycle_create" to create or overwrite the mapcycle file with every map name you currently have in your maps folder.
Everytime you use this, it will overwrite all content in the mapcycle.txt. This means maps you don't have in your maps folder anymore will be replaced once you use mapcycle_create.
Syntax: Select all
from commands.server import ServerCommand
from os import listdir
from paths import GAME_PATH
MAP_PATH = GAME_PATH+"\maps"
CFG_PATH = GAME_PATH+"\cfg"
@ServerCommand('mapcycle_create')
def _mapcycle_create(command):
mapcycle_file = open(CFG_PATH+"\mapcycle.txt", "w")
for map in listdir(MAP_PATH):
if ".bsp" in map:
map = map.replace(".bsp","")
mapcycle_file.write(map+"\n")
mapcycle_file.close()
Use the command "mapcycle_create" to create or overwrite the mapcycle file with every map name you currently have in your maps folder.
Everytime you use this, it will overwrite all content in the mapcycle.txt. This means maps you don't have in your maps folder anymore will be replaced once you use mapcycle_create.
Re: [Cs:s] Automatic mapcycle.txt creator
I have a few tips when it comes to using the 'path' package included with SP.
Put them all together, and that plugin could look like:
- Using the __div__ method to automatically add directory using proper os.sep:
Syntax: Select all
MAP_PATH = GAME_PATH / 'maps'
- Open a file with the .open method along with the 'with' statement (which automatically closes the file on __exit__):
Syntax: Select all
MAPCYCLE_FILE = CFG_PATH / 'mapcycle.txt'
with MAPCYCLE_FILE.open('w') as open_file:
open_file.write() - Loop through files using a wildcard (along with using f-strings):
Syntax: Select all
for bsp_file in MAP_PATH.files('*.bsp'):
mapcycle_file.write(f'{bsp_file.namebase}\n')
Put them all together, and that plugin could look like:
Syntax: Select all
from commands.server import ServerCommand
from paths import GAME_PATH
MAP_PATH = GAME_PATH / 'maps'
MAPCYCLE_FILE = GAME_PATH / 'cfg' / 'mapcycle.txt'
@ServerCommand('mapcycle_create')
def _mapcycle_create(command):
with MAPCYCLE_FILE.open('w') as open_file:
for bsp_file in MAP_PATH.files('*.bsp'):
open_file.write(f'{bsp_file.namebase}\n')
-
- Senior Member
- Posts: 315
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: [Cs:s] Automatic mapcycle.txt creator
Hi, the plugin works perfectly, thank you guys
Who is online
Users browsing this forum: No registered users and 87 guests