♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
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:
LSEE BGS 8 100 100 Fire
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

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.
 
Last edited by a moderator:

Rift

Villager
Member
Joined
Apr 30, 2012
Messages
6
Reaction score
1
First Language
English&Tagalog
Primarily Uses
Very cool, thanks Lemony! I've got some hidden items in my game that can only be found via clever exploration, and I might just have to make a 'metal detector' type item that works in conjunction with your script.

"Player is near hidden object + detector item is equipped / in players possession = nearby hidden objects / events emit sound".

Awesome B)

Edit: I might be overlooking something but I'm getting an error: "Line 24: NoMethodError occurred. Undefined method `each' for nil:NilClass"
 
Last edited by a moderator:

paradoxum

Veteran
Veteran
Joined
Apr 18, 2012
Messages
80
Reaction score
9
Primarily Uses
Thanks again for making this Lemony :)

Testing out the new version with an event playing an SE that switches to page 2 (no SE) when touched.

50% of the time it gives this error: http://i.imgur.com/T51jw.png and the other 50% the sound plays one last time but sort of echoes out and sounds strange.
 
Last edited by a moderator:

Todd

Game Developer
Veteran
Joined
Mar 14, 2012
Messages
269
Reaction score
43
First Language
English
Primarily Uses
N/A
This this looks great, I'll definitely use it when more than one BGS is available.
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Hi! I just edited the first post, added a demo and updated the script. Check this version and if you found any bug or problem, please make a demo recreating it!

This this looks great, I'll definitely use it when more than one BGS is available.
You could try using the BGS file in the SE/ME folder and setting the frames between each play by now. I don't think that multiple BGS playing is even allowed in the Audio class..

.
 

Todd

Game Developer
Veteran
Joined
Mar 14, 2012
Messages
269
Reaction score
43
First Language
English
Primarily Uses
N/A
Alright thanks, I think it is possible because I know Modern Algebra has a script like this and I think it allows multiple BGS
 

paradoxum

Veteran
Veteran
Joined
Apr 18, 2012
Messages
80
Reaction score
9
Primarily Uses
Not getting the error I mentioned anymore however now almost every time the sound will 'echo' out when turned off (changed to paged 2). The event I am using to test is simply this:

2 pages

page 1 has the sound emitting comment

after that self switch A=on

trigger - action button

page 2 - A=ON

nothing on the page
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Hi Paradox! I was able to reproduce that error and it is already fixed, check the new updated script.
 

The Infamous Bon Bon

Executive Geek
Veteran
Joined
Mar 13, 2012
Messages
846
Reaction score
412
First Language
English
Primarily Uses
Cool. I will have to try this out. I was using a BGS for fires in my game, but they always sounded a little off because of distance and transfering was a pain (had to remember to shut it off in every possible transfer). I think this will alleviate both problems.
 
Last edited by a moderator:

paradoxum

Veteran
Veteran
Joined
Apr 18, 2012
Messages
80
Reaction score
9
Primarily Uses


Getting this error upon loading a map where I am not using the script at all. I do however have events for Doors which play a normal sound effect on page 1 and then another SE on page 2, so I think it's something to do with that.
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Hi paradox! Thank you for the feedback! First post updated, check it out now.
 

paradoxum

Veteran
Veteran
Joined
Apr 18, 2012
Messages
80
Reaction score
9
Primarily Uses
Hey Lemony,

Could there be an option to adjust the maximum volume of the SE being played?
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Hi there! I just added the volume option, check out the script or download the updated demo! You need to set the volume just after pitch when creating the comment.
 

ashes999

Uber Coder
Veteran
Joined
May 18, 2012
Messages
114
Reaction score
6
First Language
English
Primarily Uses
I'm getting an error that Object::Game_Character is an uninitialized constant. How do you add this script?
 

mobychan

CodeMaster
Veteran
Joined
Mar 23, 2012
Messages
297
Reaction score
45
First Language
German
Primarily Uses
You could try the demo he linked in the first post ;)

The last time I tried it it worked.

You usually just place it below Materials and above Main.

Did you place it above Game_Character? Seems like it since the error says that the program doesn't know Game_Character (yet).
 

ashes999

Uber Coder
Veteran
Joined
May 18, 2012
Messages
114
Reaction score
6
First Language
English
Primarily Uses
Yeah, noob mistake. I got it working, thanks.
 
Last edited by a moderator:

Retoral

Warper
Member
Joined
Jan 22, 2013
Messages
1
Reaction score
0
Primarily Uses
Hey!
Is it possible to make just a specific terrain to play the sound?

Like you want the ocean to play but don't want to maker a dousin of events just to make that happened.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,807
Reaction score
14,021
First Language
English
Primarily Uses
RMMV
Your events would not have to be side by side. You could put them several tiles apart depending on the range and as the player moves away from one and closer to another they'll still hear the sound.
 

Latest Threads

Latest Posts

Latest Profile Posts

The self-righteous indignation of family when you expect them to pay back money you've leant to them never ceases to amaze me.
Gamedev for relaxing? yes or no?
I've been having a rough couple of months and as such let down some friends of mine in the RPG Maker community. I still need time to get back to my normal self, but it's nice to be back, to read articles, and to design again (albeit at a slow pace). Hope to give updates on Kid Crescent soon.
Friendly reminder that you don't have to be able to do absolutely everything. It's okay to scale back features or assets if things are too much - especially if you're the only one working on the game! And you can always add things in later. <3
My new cutscene system makes it so much easier to add parallel stuff happening in the background, I can easily fill the whole screen with action.

Forum statistics

Threads
107,734
Messages
1,031,737
Members
139,869
Latest member
Anzi
Top