Advertisement
Daemonion

Fade in/out rough

May 23rd, 2012
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. local function fade_in(cur_amb_vol, timer, counter)
  2. if fade_in_check_time ~= nil and time_global() - fade_in_check_time <= timer then return end
  3. fade_in_check_time = time_global()
  4. if cur_amb_vol<ambient_vol then
  5. cur_amb_vol=cur_amb_vol+counter
  6. if cur_amb_vol>ambient_vol then cur_amb_vol=ambient_vol end
  7. --printf("fade_in:SET = "..ambient_vol)
  8. get_console():execute('snd_volume_music '..cur_amb_vol)
  9. end
  10. end
  11.  
  12. local function fade_out(cur_amb_vol, timer, counter)
  13. if fade_out_check_time ~= nil and time_global() - fade_out_check_time <= timer then return end
  14. fade_out_check_time = time_global()
  15. if cur_amb_vol>0 then
  16. cur_amb_vol=cur_amb_vol-counter
  17. if cur_amb_vol<0 then cur_amb_vol=0 end
  18. --printf("fade_out:SET = "..ambient_vol)
  19. get_console():execute('snd_volume_music '..cur_amb_vol)
  20. end
  21. end
  22.  
  23. function fades()
  24. --' Distemper 05.2008 --
  25. local actor = db.actor
  26. if actor:alive() then
  27. local playing_back = IsDynamicMusic()
  28. local actor_pos = actor:position()
  29. for k, object in pairs(npc_table) do
  30. local object_id = object:id()
  31. if not playing_back and play_combat ~= 0 then
  32. stop_combat(object_id)
  33. elseif playing_back then
  34. if object:alive() then
  35. if play_local_combat(actor, object, actor_pos, object_id) then
  36. break
  37. end
  38. play_local_suspence(actor, object, actor_pos, object_id)
  39. end
  40. end
  41. end
  42. end
  43. --' end --
  44.  
  45. local cur_amb_vol = get_console():get_float('snd_volume_music')
  46. if music then
  47. fade_out(cur_amb_vol, 100, 0.1)
  48. else
  49. if db.storage.silence_zone_table and actor:alive() then
  50. local actor_pos = actor:position()
  51. local flag = 0
  52. for k,v in pairs(db.storage.silence_zone_table) do
  53. local zone = db.zone_by_name[v]
  54. if zone:inside(actor_pos) then
  55. flag = 1
  56. break
  57. end
  58. end
  59. if flag == 1 then
  60. fade_out(cur_amb_vol, 1000, 0.1)
  61. else
  62. fade_in(cur_amb_vol, 1000, 0.05)
  63. end
  64. else
  65. fade_in(cur_amb_vol, 100, 0.05)
  66. end
  67. end
  68. end
  69. function restore_ambient_on_end()
  70. if music_obj and music_obj:playing() then music_obj:stop() end
  71. --printf("restore_ambient_on_end:SET = "..ambient_vol)
  72. get_console():execute('snd_volume_music '..ambient_vol)
  73. end
  74. function main_menu_on()
  75. --printf("main_menu_on:SET = "..ambient_vol)
  76. get_console():execute('snd_volume_music '..ambient_vol)
  77. end
  78. function main_menu_off()
  79. local cur_amb = get_console():get_float('snd_volume_music')
  80. if cur_amb~=ambient_vol then
  81. ambient_vol = cur_amb
  82. end
  83. --printf("main_menu_off:SET = "..ambient_vol)
  84. get_console():execute('snd_volume_music '..ambient_vol)
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement