[HL2:DM] Auto DJ

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Senior Member
Posts: 476
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany

[HL2:DM] Auto DJ

Postby Painkiller » Tue Jul 09, 2019 6:44 pm

Music will be played once at the beginning when the server is started and will never be played in the following maps again.

It used to be that every 180 seconds a song was played according to the config settings.
Maybe there is a renewal for this code.

Many thanks in advance

Syntax: Select all

from time import time
from os.path import isfile
from random import shuffle
from itertools import cycle

from paths import BASE_PATH

from listeners.tick import Repeat

from commands.say import SayCommand

from players.helpers import index_from_playerinfo
from players.helpers import userid_from_index
from players.entity import Player as PlayerEntity

from filters.players import PlayerIter

from menus import SimpleMenu, SimpleOption as Option, Text
import core

from supermod import functions
from supermod.supermod import settings
from supermod.modules import cfg
core.console_message("\n[Supermod] Music loaded!")

def get_music():
musicPath = BASE_PATH + '/plugins/supermod/cfg/music.txt'
if isfile(musicPath):
f = open(musicPath, 'r')
music_list = filter(None, (line.strip() for line in f.readlines()))
return music_list
return list()

music_list = list(get_music())
music = cycle(music_list)

last_played = 0

def play_music(index=None, title=None):
global last_played
if not len(music_list):
seconds = cfg.music_interval.get_int()
if seconds:
for song in music_list:
song = next(music)
if title: song = title
for player in PlayerIter('human'):
vol = cfg.music_volume.get_float()
steamid = player.steamid
if steamid in settings:
vol = settings[steamid]['volume']
if vol == 0.0:
functions.playsound(player.index, song, volume=vol)
last_played = time()
song_name = song.replace('exae/music/', '')
song_name = song_name.replace('.mp3', '')
song_name = song_name.title()
if not index:
functions.msg('\x0702d913Auto-DJ played song: \x07d91e02%s'%song_name)
name = PlayerEntity(index).name
functions.msg('\x0702d913DJ %s played song: \x07d91e02%s'%(name, song_name))

music_repeat = Repeat(play_music)
music_repeat.start(cfg.music_interval.get_int(), 0)

def unload():
for song in music_list:

@SayCommand(['music', '!music'])
def music_command(command, index, teamonly):

def music_cmd(index):
global last_played
now = time()
if now - last_played >= 60:
functions.tell(index, 'Please wait a bit...')

@SayCommand(['volume', '!volume'])
def volume_command(command, index, teamonly):

def volume_cmd(index):
m = SimpleMenu(title='Change music Volume')
m.append(Option('100%', 1.0))
m.append(Option('80%', 0.8))
m.append(Option('60%', 0.6))
m.append(Option('40%', 0.4))
m.append(Option('20%', 0.2))
m.append(Option('Off', 0.0))
m.select_callback = volume_callback

def volume_callback(menu, index, option):
steamid = PlayerEntity(index).steamid
if steamid not in settings:
settings[steamid] = {}
settings[steamid]['volume'] = cfg.music_volume.get_float()
settings[steamid]['overlays'] = 1
settings[steamid]['effects'] = 1
settings[steamid]['volume'] = option.value
functions.tell(index, 'You have set music volume to %s'%option.value)
User avatar
Senior Member
Posts: 476
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany

Re: [HL2:DM] Auto DJ

Postby Painkiller » Fri Jul 12, 2019 12:59 pm

Anyone have any idea why the music doesn't play automatically anymore?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: XaphoonF and 5 guests