[HL2:DM] Auto DJ

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

[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()))
f.close()
return music_list
return list()

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

last_played = 0

def play_music(index=None, title=None):
global last_played
if not len(music_list):
return
seconds = cfg.music_interval.get_int()
if seconds:
for song in music_list:
functions.stopsound(song)
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:
continue
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)
else:
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:
functions.stopsound(song)
music_repeat.stop()

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

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

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

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
m.send(index)

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
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

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?
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Auto DJ

Postby Painkiller » Mon Sep 02, 2019 11:56 am

Is there a solution why the music does not play automatically after X time?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2:DM] Auto DJ

Postby L'In20Cible » Mon Sep 02, 2019 12:28 pm

Painkiller wrote:Is there a solution why the music does not play automatically after X time?

What is supermod? Are the messages printed but no sounds are played or is there no messages as well?
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Auto DJ

Postby Painkiller » Mon Sep 02, 2019 1:01 pm

Supermod is the entire plugin and music.py a part of it.

There are no bugs, it just doesn't play anymore.
It might be possible that the code is too old it was written about 5 years ago. the meantime a lot has changed in SP.

When I enter music in the chat it plays a title.
Unfortunately not all X time automatically anymore.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2:DM] Auto DJ

Postby L'In20Cible » Mon Sep 02, 2019 1:12 pm

Painkiller wrote:Supermod is the entire plugin and music.py a part of it.

Where can I find all the files?
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Auto DJ

Postby Painkiller » Mon Sep 02, 2019 1:13 pm

I can send in a privat message ok ?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2:DM] Auto DJ

Postby L'In20Cible » Mon Sep 02, 2019 1:29 pm

I've loaded your code and found the issue. The following line:

Syntax: Select all

music_repeat.start(cfg.music_interval.get_int(), 0)

Should be:

Syntax: Select all

music_repeat.start(cfg.music_interval.get_int())

The second arguments defines how many time the loop should repeat so by having it set to 0, it only gets executed once and is never repeated. This was changed in #156. I didn't test it in-game, but the function was executed after that change.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] Auto DJ

Postby Painkiller » Mon Sep 02, 2019 1:42 pm

It seems to work again many thanks to this place.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 36 guests