## Nissan3501 by http://infin1ty.ru/

import es, random, os


tOrdner = "dreist/terwin/"


ctOrdner = "dreist/ctwin/"


sOrdner = "dreist/joing/"


t_soundstmp = os.listdir(es.getString("eventscripts_gamedir") + "/sound/" + tOrdner)
ct_soundstmp = os.listdir(es.getString("eventscripts_gamedir") + "/sound/" + ctOrdner)
s_soundstmp = os.listdir(es.getString("eventscripts_gamedir") + "/sound/" + sOrdner)
t_sounds=[]
ct_sounds=[]
s_sounds=[]
for soundfile in t_soundstmp:
    extension = soundfile[-4:]
    if (extension=='.mp3'):
        t_sounds.append(soundfile)
        print soundfile + " added to Twin sound list"
for soundfile in ct_soundstmp:
    extension = soundfile[-4:]
    if (extension=='.mp3'):
        ct_sounds.append(soundfile)
        print soundfile + " added to CTwin sound list"
for soundfile in s_soundstmp:
    extension = soundfile[-4:]
    if (extension=='.mp3'):
        s_sounds.append(soundfile)
        print soundfile + " added to join sound list"
    
def es_map_start(ev):
    download()
	
def round_end(event_var):
    tSound = tOrdner + random.choice(t_sounds)
    ctSound = ctOrdner + random.choice(ct_sounds)
    for x in es.getUseridList():
        if es.getplayersteamid(x) != "BOT":
            if int(event_var['winner']) == 2:
                es.cexec(x, "play %s" % tSound)
	
            if int(event_var['winner']) == 3:
                es.cexec(x, "play %s" % ctSound)

def player_activate(ev):
    sSound = sOrdner + random.choice(s_sounds)
    for x in es.getUseridList():
        if es.getplayersteamid(x) != "BOT":
              userid = int(ev['userid'])
              es.cexec(userid, "play %s" % sSound)

    
    


def download():
    for x in t_sounds:
        es.stringtable("downloadables", "sound/" + tOrdner + "%s" % x)

    for x in ct_sounds:
        es.stringtable("downloadables", "sound/" + ctOrdner + "%s" % x)

    for x in s_sounds:
        es.stringtable("downloadables", "sound/" + sOrdner + "%s" % x)
