Sound Emitting Events
(v.2.1)
Introduction
This little script allows you to set up events that will play BGS/ME/SE (you could try BGM, but..) if the player gets close enough.
The volume is based on the distance between the player and the event, so the closer the player is to the event, the louder it will play, the farthest the player is, the softer it will play (or not play at all).
You can set a max volume for the sound/music.
(v.2.1)
Features
- Easy to use.
- Compatibility friendly.
- Lemonade friendly.
Screenshot
How to Use
To use it, you just need to make a comment inside the event that would be the sound source with the following →
Code:
LSEE TYPE RANGE PITCH VOLUME FILENAME 复制代码
If you want a BGS to play, you need to add BGS after LSEE, like this →
Code:
If you want to play ME/SE, you also need to two additional indicators for delay and variance →
Code:
LSEE SE 8 100 45 Absorb2 60 100 复制代码
Demo
http://www.mediafire...41g2a39vpkuh00d
Script
Spoiler Code:
#============================================================================== # ** Lemony's Sound Emitting Events #------------------------------------------------------------------------------ # * This little script allows to make certain events play music/sounds based # on player proximity. # * It is currently limited by one bgs at a time, resulting in lag if one # sound emitting event's area is overlapping other's sound emitting event area. #------------------------------------------------------------------------------ # To use it, simple make a comment inside the target event with the following # LSEE TYPE RANGE PITCH VOLUME FILENAME => LSEE BGS 8 100 100 Fire # If type is SE or ME, you need two additional variables # LSEE TYPE RANGE PITCH VOLUME FILENAME DELAY RANDOM #============================================================================== class Game_Event < Game_Character #-------------------------------------------------------------------------- # * Refresh Alias #-------------------------------------------------------------------------- alias lemony_see_refresh refresh #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh lemony_see_refresh return if (@page.nil? || @page.list.nil?) @page.list.each {|p| b = p.parameters[0] s, @lsee_out = (b != nil && b.is_a?(String)) ? b.split : '', false if (p.code == 108 || p.code == 408) && b.include?('LSEE') @lsee_data = [s[1], s[2], s[3].to_i, s[4], s[5], s[6].to_i, s[7].to_i] break if @lsee_data != nil else @lsee_out = true end} end #-------------------------------------------------------------------------- # * Update Alias #-------------------------------------------------------------------------- alias lemony_see_update update #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update lemony_see_update if !@lsee_data.nil? xx, yy = (@real_x - $game_player.real_x), (@real_y - $game_player.real_y) close = (Math.sqrt((xx * xx) + (yy * yy)) <= @lsee_data[1].to_i) r, d = @lsee_data[1].to_i, Math.sqrt((xx * xx) + (yy * yy)) v, go, ms = (r - (d - 1 % r)) * @lsee_data[3].to_i / r, true, ['ME', 'SE'] if !@lsee_out if ms.include?(@lsee_data[0]) @lsee_timer ||= @lsee_data[5] + rand(@lsee_data[6]) @lsee_timer = [@lsee_timer - 1, 0].max go = @lsee_timer <= 0 @lsee_timer = nil if go end out = (!@lsee_data[7].nil? && (@lsee_data[7].volume > 0 && !close)) && go f = "#{@lsee_data[0]}.new('#{@lsee_data[4]}', #{v}, #{@lsee_data[2]})" @lsee_data[7] ||= eval("RPG::" + f) if close && go @lsee_data[7].volume = v if !@lsee_data[7].nil? && close @lsee_data[7].play if ((!@lsee_data[7].nil? && close) && go) || out @lsee_data[7].volume -= 1 if !@lsee_data[7].nil? && !close @lsee_data[7] = nil if (!@lsee_data[7].nil? && @lsee_data[7].volume <= 0) elsif @lsee_out @lsee_data[7].volume -= 1 if !@lsee_data[7].nil? @lsee_data[7].play if !@lsee_data[7].nil? && !ms.include?(@lsee_data[0]) if (!@lsee_data[7].nil? && @lsee_data[7].volume <= 0) @lsee_data, @lsee_out = nil, false end end end end end 复制代码
Author's Notes
Free for use in commercial/noncommercial games, no credits needed.
本贴来自国际rpgmaker官方论坛作者:♥SOURCE♥处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/sound-emitting-events.1714/