Using Volume Distance Script/Parallel Proces only once every x seconds

Status
Not open for further replies.

FredHuizinga

Villager
Member
Joined
Sep 3, 2018
Messages
5
Reaction score
0
First Language
Dutch
Primarily Uses
RMVXA
So I ran into a problem not too long ago, and I've looked around on the web but didn't see any solution to my problem (I think).

I made a map recently with a waterfall, and I'd like to have the waterfall play a waterfall sound, but I only want it to be hearable when you're close to the waterfall. For that I am using this volume distance script:
# Version 1.01# Date : Nov 15, 2013
#------------------------------------------------------------------------------
# Parameters:
# eventID : ID of the event that produces the SE
# md : maximum distance up to which you can hear the SE
# mv : maximum volume of the SE
# return : actual volume depending on the actual distance
#
# Example:
# RPG::SE.new("Cat", volume(@event_id,20,50), 100).play
#------------------------------------------------------------------------------

def volume(eventID, md, mv)

x1 = $game_player.x

y1 = $game_player.y

x2 = $game_map.events[eventID].x

y2 = $game_map.events[eventID].y

d = Math.sqrt((x2-x1)**2 + (y2-y1)**2).round

v = mv-(mv*d/md).round

if v < 0 then

v = 0

end

return(v)

end

I've tried this script before on another map to play a hammer sound when you get close to the forge, and I already found that when you put the event to a parallel process (because to my knowledge the sound doesn't run otherwise) the sound starts infinitely looping over itself which creates a terrible sound and a certain amount of lag. I fixed that issue by simply putting a wait command after the script line to only play the sound every 2 seconds or so, but now that I'm trying it here again that doesn't seem to be a solution.

The SE I use for the Waterfall is quite lengthy (63 seconds) but it is a nice loop and I'd like to stick with it. Now, when I try to run the script through an event, it again starts to infinitely loop over itself, which I do not want. But when I try to add a wait command the command needs to be long enough to stop the sound from looping until it is finished (so 63 seconds), but I found that the sound somehow doesn't play anymore after a wait time of 600 frames/10 seconds.

What I'd basically like to know is if it is possible to run the event when the player enters the map, only play the SE once, wait until the SE is finished and only then start to play it again whilst still using the script so the sound is only hearable in some parts of the map?
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,114
Reaction score
11,464
First Language
English
Primarily Uses
RMVXA
Although your query is linked to a script, I'm not moving this to Script Support (yet) as it looks like it is an event issue, not a script one.

Have you tried putting in a wait for 63 seconds? To get a wait that long, you will need multiple Wait commands, as the maximum you can have is 999 frames and it's 60 frames per second.
 

FredHuizinga

Villager
Member
Joined
Sep 3, 2018
Messages
5
Reaction score
0
First Language
Dutch
Primarily Uses
RMVXA
I have, yes. I also noticed the maximum frame limit is 999, so with a quick calculation I figured that if I put in 6 wait command for 600 frames and 1 for 180 frames I would have the right amount of frames, but when I test play the map the sound still doesn't play.

I don't have a real clue as to what the problem could be, I think it might have something to do with the parallel process stopping the sound from happening as soon as it executes the next command, but that doesn't really make sense since it doesn't do that with shorter wait commands. I've also tried to end the process loop by enabling a self switch after executing the script line and adding another event page, but that also doesn't seem to work.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,400
Reaction score
7,222
First Language
German
Primarily Uses
RMMV
please show us screenshots of the event - there is a lot of possibilities where you could have gone wrong, and we need to see the complete event with all options to help.

additionally, is the event placed near the waterfall or farther away from it?
 

FredHuizinga

Villager
Member
Joined
Sep 3, 2018
Messages
5
Reaction score
0
First Language
Dutch
Primarily Uses
RMVXA
please show us screenshots of the event - there is a lot of possibilities where you could have gone wrong, and we need to see the complete event with all options to help.

additionally, is the event placed near the waterfall or farther away from it?
Alright, right now all the event is is this:
I left it all empty for now since I had no idea how to progress. This is how I initially tried to run the event and makes it loop infinitely over itself.

I've also tried these following commands, including trying to use the Move Route command, but none of them have worked.

And yes, the event is directly located behind the waterfall sprite. The sprite itself is 96x96 so this SE event fits perfectly inside the 3x3.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,400
Reaction score
7,222
First Language
German
Primarily Uses
RMMV
You won't get what you want with this for several reasons.

your script just calculates a volume number, you need the play command to change the actual volume of the sound.
that means you are required to restart the sound to make it quieter or louder based on the distance.
even if there were no otherproblem, your wait sequence would mean that the sound volume does not change during the wait frames, even if the player goes nearer or farther during that time.

second problem is that to reduce lag, the engine ignores all events outside a certain range - which is only a tiny bit more than the screen width.
most likely you went farther away than that while the SE still played on the old volume, and then it didn't repeat because you were to far away from the event for it to be processed.
 

FredHuizinga

Villager
Member
Joined
Sep 3, 2018
Messages
5
Reaction score
0
First Language
Dutch
Primarily Uses
RMVXA
Alright, so if I understand correctly the script I'm using needs to restart the sound every time to be able to adjust the volume? I don't think the second problem is actually a problem for me though. If the event isn't processed outside of a certain range that means the sound won't play outside of that range which is kind of what I want anyway.

The first part is most likely what I'm having trouble with then, so my question would then be if there is any way in which you can event/script an event to play a continuous SE whilst still being able to adjust the sound based on player position? I'm also guessing it has to be a script since I don't see an obvious way of doing this through events, so maybe this thread should also be moved to Script Support.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,114
Reaction score
11,464
First Language
English
Primarily Uses
RMVXA
No, it doesn't need a script. When I'm on my computer (in a couple of hours) I'll post screen shots of how I did this with an event.

EDIT
You will need 2 events and 2 variables.
The variables will be getting the player's x and y coordinates.

Event one
First check the map x,y for the waterfall event that you have created. In my example, the waterfall was located at 20, 14. You then create a parallel process event which you can tuck up in the top left corner of the map out of the way. It looks like this:

waterfall event.png

You will see where I have used that 20, 14. This event is determining how far away from the waterfall the player is and setting the variable accordingly.

You then need a second event, also parallel process, which you can also tuck up out of the way. This has 12 pages, each with a single command and conditioned by the changing variable. Please note that you must put the 'silent' page as the last, and the full volume page as the first because of the order in which the engine reads event pages.
sfx page 1.png sfx page 2.png sfx page 3.png sfx page 4.png sfx page 5.png sfx page 6.png sfx page 7.png sfx page 8.png sfx page 9.png sfx page 10.png sfx page 11.png sfx page 12.png
And that's all there is to it.
Well, I say "all", but it was only straightforward after I'd worked out the logic of the first event.
 
Last edited:

FredHuizinga

Villager
Member
Joined
Sep 3, 2018
Messages
5
Reaction score
0
First Language
Dutch
Primarily Uses
RMVXA
Well, I did everything you did exactly as you described it, but it didn't work for me. My map is 25x25, and my waterfall is located at X8 Y20 in the map, and my player is located at X5 Y1.

I followed the instructions you gave me for these events, and I'm 100% sure I followed them to the letter.
I did the other event the exact same way as you, but I still encounter 2 problems, 1 old one and 1 new one.

The old problem is that the sound still infinitely loops over itself for some reason. The new problem is that the sound also comes from nowhere near the waterfall itself but originates from the player start point? I even opened a brand new project to check if I maybe had scripts that were somehow interfering with the sound system, but that also isn't the case.

EDIT: NEVERMIND I FIGURED IT OUT.
It literally took me 10 minutes to play with those events you made before I realized the mistakes I made.

Problem 1, the infinite looping, was somehow caused by the fact that I used a SE sound instead of a BGS. I am not a 100% certain why the SE loops infinitely in a parallel process and a BGS doesn't, but that was the problem I had, which is now fixed by simply changing to a BGS.

The 2nd problem was because I misread the X & Y positions on the map. Rookie error, but in my defence, I thought that the X's and Y's would be counted like in a graph, so the bottom left would be 1,1. This is not the case. 1,1 is in the top left instead of the bottom left, so I just simply fixed this problem by inputting the right coordinates.

I ran it again in a test game, and it works perfectly now! I did increase the range of the sounds a little bit to better fit my map, but other than that it's great!

Big thanks to you guys for helping me find a solution ^^!
 
Last edited:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,114
Reaction score
11,464
First Language
English
Primarily Uses
RMVXA
Glad to be of help. I remember when I first started off, I didn't realise that the x,y of an event/tile is given at the bottom right of the map and I once spent ages manually counting across and down to get a series of them.

Can this be closed now? If so, please Report your last post and ask for the thread to be closed.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,007
Reaction score
4,746
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Finally did a test of sorts for the opening of my game... ... including this shot here.
My current status!?
It might be... QUAKE!!! :o
At least that was true several hours ago. :p
Quexp wrote on Shaz's profile.
I absolutely love your profile/pic! :kaoluv:
Stream will be live shortly with some Darkest Dungeon! Feel free to drop by!
I made a battle results screen for my minigame.. any feedback? :)

Forum statistics

Threads
100,686
Messages
978,416
Members
132,310
Latest member
hnhat
Top