じ☆ve冰风 发表于 2026-7-31 13:36:28

SE volume change over distance

Introduction
This little script calculate the distance between an event and the player and the volume for a sound that can be played by that event.

Features
- Friendly little helper
 
How to Use
Simple put a call script command in your event.

In my example I use a cat as an event that randomly plays a "meow" every five seconds with a probability of 25%.
The maximum volume is 50 and the maximum distance the sound is played is 20.

The call script command should be like this:
 
@>Control Variables: = Random No.(0..100)
@>Conditional Branch; Variable<=25
  @>Script: RPG::SE.new("Cat", volume(@event_id,20,50), 100).play
  @>Wait:300 frame(s)
  @>
: Else
  @>Wait:300 frame(s)
  @>
: Branch End
@>
 
Author's Note
Free for use in commercial/noncommercial games.
Credits are welcome. 
 
Script



Spoiler#------------------------------------------------------------------------------
# weilhalt scripts
# peter.guettinger@gmail.com
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
# Title : Sound Volume
# Author : Peter Guettinger



# 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.x

  y2 = $game_map.events.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


本贴来自国际rpgmaker官方论坛作者:neoscully处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/se-volume-change-over-distance.19990/
页: [1]
查看完整版本: SE volume change over distance