The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on April 10, 2010, 07:26:35 PM

Title: Individual Collapse Sounds
Post by: modern algebra on April 10, 2010, 07:26:35 PM
Individual Collapse Sounds
Version: 1.0
Author: modern algebra
Date: April 10, 2010

Version History



Description


This script allows you to set individual collapse sounds for your enemies and actors. Want humans to scream when they die but robots to break down? This is what this script does.

Features


Instructions

Paste the script into the Script Editor (F11) above Main but below the rest of the default scripts.

Script


Code: [Select]
#==============================================================================
#    Individual Collapse Sounds
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: April 10, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to set individual collapse sounds for your enemies
#   and actors. Want humans to scream when they die but robots to break down?
#   This is what this script does.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script into the Script Editor in its own slot above Main and
#   below Materials. To configure an enemy collapse sound, simply type into its
#   notebox this code:
#      \CS[se_name, volume, pitch]
#         se_name : the filename of the SE you want to play upon death
#         volume  : the volume you want it to play at. 100 is default if you
#           exclude it.
#         pitch   : the pitch you want it to play at. 100 is default if you
#           exclude it.
#
#    If you don't put anything at all, then the enemy collapse sound will be
#   the default one you set in the database. Note that you don't need to
#   specify volume or pitch, so \CS[se_name] would be fine, as would be
#   \CS[se_name, volume].
#   EXAMPLE: \CS[Collapse1, 95, 85]
#
#    To set up the actor's collapse sounds. See the EDITABLE REGION at line 47.
#==============================================================================
# ** Game_Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - perform_collapse
#    new method - maic_collapse_sound
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Collapse Sound
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maic_collapse_sound
    name, volume, pitch = $data_system.sounds[13].name, 100, 100
    case @actor_id
    #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    #  EDITABLE REGION
    #````````````````````````````````````````````````````````````````````````
    #    To set up an actor, use this format:
    #      when actor_id
    #        name = "filename" (defaults to database collapse file)
    #        volume = integer  (defaults to 100)
    #        pitch = integer   (dfaults to 100)
    #
    #    If you do not set one up for an actor at all, then it will play the
    #   database actor collapse sound when that actor dies. If you set one up
    #   for an actor but exclude any of the values, it will default the value
    #   specified above.
    #
    #  EXAMPLE:
    #    when 1 # Ralph
    #      name = "Collapse1"
    #      volume = 80
    #      pitch = 65
    #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    when 1 # Ralph
      name = "Collapse1"
      volume = 80
    when 2 # Ulrika
      name = "Collapse2"
      pitch = 150
    #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    #  END EDITABLE REGION
    #////////////////////////////////////////////////////////////////////////
    else
      return $data_system.sounds[13]
    end
    return RPG::SE.new (name, volume, pitch)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Perform Collapse
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mornal_indcol_perform_9tv1 perform_collapse
  def perform_collapse (*args)
    system_sound = $data_system.sounds[13]
    $data_system.sounds[13] = maic_collapse_sound
    mornal_indcol_perform_9tv1 (*args) # Run Original Method
    $data_system.sounds[13] = system_sound
  end
end

#==============================================================================
# ** RPG::Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - maiec_collapse_sound
#==============================================================================

class RPG::Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Collapse Sound
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maiec_collapse_sound
    if self.note[/\\CS\[(.+?),?\s*?(\d*?),?\s*?(\d*?)\]/i] != nil
      pitch = $3 ? $3.to_i : 100
      volume = $2 ? $2.to_i : 100
      return RPG::SE.new ($1.to_s, volume, pitch)
    else
      return $data_system.sounds[11]
    end
  end
end

#==============================================================================
# ** Game_Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - perform_collapse
#==============================================================================

class Game_Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Perform Collapse
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malgbr_indenmyclapse_8ik1 perform_collapse
  def perform_collapse (*args)
    system_sound = $data_system.sounds[11]
    $data_system.sounds[11] = self.enemy.maiec_collapse_sound
    malgbr_indenmyclapse_8ik1 (*args) # Run Original Method
    $data_system.sounds[11] = system_sound
  end
end

Credit



Thanks


Support


Please post in this topic for support, no matter how old the topic is. Do not PM me.

Known Compatibility Issues

No known compatibility issues. If you find one, please post and I will do my best to resolve it.
Title: Re: Individual Collapse Sounds
Post by: Grafikal on April 10, 2010, 08:05:42 PM
a.w.e.s.o.m.e.
Title: Re: Individual Collapse Sounds
Post by: Deity on April 10, 2010, 08:28:34 PM
Wow nice work!
I should learn more about "*args" you use it it often. :P

Deity
Title: Re: Individual Collapse Sounds
Post by: modern algebra on April 11, 2010, 12:25:36 AM
I use it for compatibility purposes the args part is just the name of the variable; what matters is the * operator. You can think of it as collapsing an array, so if you have an array like:

coords = [x, y, z]
a, b, c = *coords # a = x; b = y; c = z

It also works in reverse, so *coords = x, y, z # coords = [x, y, z]

I use it in both ways where I am aliasing. It first takes all of the arguments passed to a method and puts them in an array (called args, but again you could name it anything). I then collapse that array and pass those arguments through the original method call.

So:

Code: [Select]
alias new_method old_method
def old_method (*args)
  new_method (*args)
end

I think it helps for compatibility, because you don't need to know what arguments that method is expecting if you don't need to use them. Because consider this situation:

Original method:

Code: [Select]
def old_method (x, y)
  # Stuff
end

And then another scripter comes along and decides he wants to add another argument he/she can pass to this method for his/her own purposes, so he/she writes this:

Code: [Select]
alias new_method old_method
def old_method (x, y, z = 0)
  new_method (x, y)
  # Stuff
end

So far everything is dandy. It will work everywhere. But then another scripter comes along and writes this:

Code: [Select]
alias new_method2 old_method
def old_method (x, y)
  new_method2 (x, y)
  # Stuff
end

Now, wherever in the first scripter's code that he passes the extra argument to old_method there will be an argument error because he's passing three arguments to old_method when it only takes two. Now that would be a very easy error to correct since all anyone would need to do is put the second script above the first script in the Editor, but it's not hard to imagine more serious incarnations of this and in any case, most RM users aren't overly adept at solving errors in their scripts. So, as long as you're not using the arguments passed to the method you alias, then you might as well use *args in order to avoid potential argument errors.
Title: Re: Individual Collapse Sounds
Post by: Foghart on February 08, 2011, 08:35:20 PM
Could be great if somebody send some Dying SE to use.
By the way, great script!
Title: Re: Individual Collapse Sounds
Post by: pacdiggity on February 09, 2011, 10:08:10 AM
Or you could check the last post date and create your own topic for it. There is a warning on when you post over topics 60 days old, yeah?
Title: Re: Individual Collapse Sounds
Post by: modern algebra on February 09, 2011, 01:34:57 PM
For scripts and resources, it is perfectly OK to post on them even when they're old, as it avoids clutter and other problems.

Necroposting is only prohibited where it makes sense to prohibit it: for instance when it's responding to a conversation when none of the participants are still here or still care. For scripts, resources, forum games, it's almost always OK.
Title: Re: Individual Collapse Sounds
Post by: Omiekins on February 09, 2011, 07:06:24 PM
I was actually making some SFX for my game, and had looking for a script like this on my to-do list.  Necroposting saved the effort :3  In return for a fabulous script, I can submit some unused sfx sometime in the future.  x3  I'd love to contribute to this site, but I'm more on the creative side, not so much the scripting or technical. 

THAT SAID.

Thanks so much for the script. <3
Title: Re: Individual Collapse Sounds
Post by: pacdiggity on February 10, 2011, 08:00:46 AM
Sorry MA.
I'll try to do better next time.
I thought it was prohibited everywhere. Sorry ;9