// ---------------------------------------------------------
// -- 22.09.06 -- by SaferFrags -- is-low.de -- 319528205 --
// ---------------------------------------------------------
// ************************
// ** DO NOT EDIT BELOW! **
// ************************
block load
{
  es_xlog Loading RoundEndSounds
  es_xsetinfo res_ver "1.4.1 beta"
  es_xmakepublic res_ver
  es_xdoblock res/init_sound
  es_xsetinfo res_game 0
  es_xgetgame res_game
  if (server_var(res_game) == "Counter-Strike: Source") then es_xsetinfo res_event winner
  if ("Day of Defeat" in server_var(res_game)) then es_xsetinfo res_event team
}
block unload
{
  es_xlog Unloading RoundEndSounds
}
event round_end
{
  es_xdoblock res/play_sound
}
event dod_round_win
{
  es_xdoblock res/play_sound
}
event es_map_start
{
  es_xdoblock res/init_sound
}
block init_sound
{
  es_xkeygroupload res_sound "|res"
  es_xsetinfo res_ct_sounds 0
  es_xsetinfo res_t_sounds 0
  es_xforeachval val in res_sound sounds "es_xdoblock res/add_sound"
  es_xlog [RES] Sounds initialized -- Preloading Valve-Sounds in 2 min
  es_xdelayed 120 es_xdoblock res/preload_sound
  es_xkeygroupdelete res_sound
}
block add_sound
{
  es_xsetinfo res_sound 0
  es_keygetvalue res_sound res_sound sounds server_var(val)
  if (ct in server_var(val)) then es_xmath res_ct_sounds + 1
  else do
  {
    es_xmath res_t_sounds + 1
  }
  es_xsetinfo res_format 0
  es_format res_format "sound%1" server_var(res_sound)
  es_stringtable downloadables server_var(res_format)
  es_log [RES] Added Sound: server_var(res_sound) - server_var(res_format)
}
block preload_sound
{
  es_xsetinfo res_userid 0
  es_xgetuserid res_userid
  if ("Day of Defeat" in server_var(res_game)) do
  {
    es_emitsound player server_var(res_userid) "ambient/german_win.mp3" 0.0 0.0
    es_emitsound player server_var(res_userid) "ambient/us_win.mp3" 0.0 0.0
    es_log [RES-Debug] Sounds for server_var(res_game) on server_var(res_userid) preloaded...
  }
}
block play_sound
{
  es_xkeygroupload res_sound "|res"
  if (event_var(server_var(res_event)) == 2) do
  {
    es_xsetinfo res_winner t
    if (server_var(res_game) == "Counter-Strike: Source") then es_xsetinfo res_sound "ambient/t_win.mp3"
    if (server_var(res_game) == "Day of Defeat: Source") then es_xsetinfo res_sound "ambient/us_win.mp3"
  }
  if (event_var(server_var(res_event)) == 3) do
  {
    es_xsetinfo res_winner ct
    if (server_var(res_game) == "Counter-Strike: Source") then es_xsetinfo res_sound "ambient/ct_win.mp3"
    if (server_var(res_game) == "Day of Defeat: Source") then es_xsetinfo res_sound "ambient/german_win.mp3"
  }
  es_xsetinfo res_userid 0
  foreach player res_userid #human "es_stopsound server_var(res_userid) server_var(res_sound)"
  es_xsetinfo res_format 0
  es_format res_format "res_%1_sounds" server_var(res_winner)
  es_xsetinfo res_random 0
  es_rand res_random 1 server_var(server_var(res_format))
  es_xsetinfo res_play_sound 0
  es_format res_play_sound "res_%1win%2" server_var(res_winner) server_var(res_random)
  es_xsetinfo res_get_of_db 0
  es_keygetvalue res_get_of_db res_sound sounds server_var(res_play_sound)
  es_cexec_all play server_var(res_get_of_db)
  es_xkeygroupdelete res_sound
}
