import es, os.path, random

def addSounds():
    es.server.queuecmd('downloadable sound/deathrun/stop.mp3')    
    if os.path.isfile(es.getAddonPath('deathrun') + '/soundlist.cfg'):
        a = open(es.getAddonPath('deathrun') + '/soundlist.cfg', 'r')
        b = a.readlines()
        for line in b:
            es.server.queuecmd('downloadable sound/%s'%line)

def load():
    addSounds()

def es_map_start(event_var): 
    addSounds()

def round_start(event_var):
    addSounds()

def player_activate(event_var):
    userid = int(event_var['userid'])
    if os.path.isfile(es.getAddonPath('deathrun') + '/soundlist.cfg'):
        a = open(es.getAddonPath('deathrun') + '/soundlist.cfg', 'r')
        b = a.readlines()
        for line in b:
            sound = '%s'%line
            es.cexec(userid,'play %s'%sound)

def player_say(event_var):
    text = event_var['text']
    userid = int(event_var['userid'])
    if text.lower() == '!stop':
        es.cexec(userid,'play deathrun/stop.mp3')

