Advertisement
Daemonion

fade in/out reference

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